Added explicit exception raise when no stack found. (#3559)

* Added explicit exception raise when no stack found.

Currently, any operation that uses 'get_stack' method from 'CloudFormationBackend' class
will fail with AttributeError or jinja2 exception if ran against non-existing stack(created/deleted)
To fix the issue I explicitly raised a 'ValidationError' exception.
Added tests for boto and boto3 responses.

* Moved non-existing stack tests to 'test_stack_events'

When using 'update_stack' to test raising an exception when the stack doesn't exist
test coverage dropped by 0.5%. I am using stack_events instead.

* Removed some unreachable paths

After adding the exception couple of paths in the code are unreachable as 'get_stack' doesn't return 'None' anymore.
This is the reason why coverall was reporting decreased coverage.

* Removed an unreachable path I missed

* Added couple of tests in cloudformation/models

* Added more assertions around raised exception

* Formatted document using black to fix issue with travis.
This commit is contained in:
Modhaffer Rahmani 2021-01-16 15:42:51 +01:00 committed by GitHub
commit 8fe5a680a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 7 deletions

View file

@ -707,6 +707,7 @@ class CloudFormationBackend(BaseBackend):
for stack in self.stacks.values():
if stack.name == name_or_stack_id:
return stack
raise ValidationError(name_or_stack_id)
def update_stack(self, name, template, role_arn=None, parameters=None, tags=None):
stack = self.get_stack(name)
@ -715,8 +716,6 @@ class CloudFormationBackend(BaseBackend):
def list_stack_resources(self, stack_name_or_id):
stack = self.get_stack(stack_name_or_id)
if stack is None:
return None
return stack.stack_resources
def delete_stack(self, name_or_stack_id):