diff --git a/tests/test_cloudformation.py b/tests/test_cloudformation.py index 3626576a..43b27e02 100644 --- a/tests/test_cloudformation.py +++ b/tests/test_cloudformation.py @@ -67,6 +67,25 @@ def test_construct_getatt_raises_exception(self): class TestTemplate(unittest.TestCase): + def setUp(self): + self.function = { + "HelloWorldFunction": { + "Type": "AWS::Serverless::Function", + "Properties": { + "CodeUri": "hello_world/", + "Handler": "app.lambda_handler", + "Runtime": "python3.11", + "Architectures": ["x86_64"], + "Events": { + "HelloWorld": { + "Type": "Api", + "Properties": {"Path": "/hello", "Method": "get"}, + } + }, + }, + } + } + def test_load(self): templates = (f"tests/fixtures/templates/example{i}.yml" for i in range(1, 3)) @@ -92,25 +111,7 @@ def test_load_raises_exception(self): def test_list_functions(self): cloudformation = Template("tests/fixtures/templates/example1.yml") - expected_functions = [ - { - "HelloWorldFunction": { - "Type": "AWS::Serverless::Function", - "Properties": { - "CodeUri": "hello_world/", - "Handler": "app.lambda_handler", - "Runtime": "python3.11", - "Architectures": ["x86_64"], - "Events": { - "HelloWorld": { - "Type": "Api", - "Properties": {"Path": "/hello", "Method": "get"}, - } - }, - }, - } - } - ] + expected_functions = [self.function] self.assertEqual(cloudformation.functions, expected_functions) @@ -136,24 +137,6 @@ def test_find_nodes(self): tree = cloudformation.template nodes = cloudformation.find_nodes(tree["Resources"], cf.NodeType.LAMBDA) - expected_nodes = [ - { - "HelloWorldFunction": { - "Type": "AWS::Serverless::Function", - "Properties": { - "CodeUri": "hello_world/", - "Handler": "app.lambda_handler", - "Runtime": "python3.11", - "Architectures": ["x86_64"], - "Events": { - "HelloWorld": { - "Type": "Api", - "Properties": {"Path": "/hello", "Method": "get"}, - } - }, - }, - } - }, - ] + expected_nodes = [self.function] self.assertEqual(nodes, expected_nodes)