Skip to content

Commit

Permalink
refactor: add a fixture to function value
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis-Henrique committed Nov 30, 2023
1 parent ed93175 commit 9dd60be
Showing 1 changed file with 21 additions and 38 deletions.
59 changes: 21 additions & 38 deletions tests/test_cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)

Expand All @@ -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)

0 comments on commit 9dd60be

Please sign in to comment.