def test_must_skip_unknown_resource(self): resources = {"Func1": {"Type": "AWS::SomeOther::Function", "Properties": {"a": "b"}}} expected = {} result = SamFunctionProvider._extract_functions(resources) self.assertEqual(expected, result)
def test_must_work_for_multiple_functions_with_name_but_in_different_stacks( self, convert_mock, ): function_root = Mock() function_root.name = "Func1" function_root.full_path = "Func1" function_child = Mock() function_child.name = "Func1" function_child.full_path = "C/Func1" stack_root = Mock() stack_root.resources = { "Func1": {"Type": "AWS::Lambda::Function", "Properties": {"a": "b"}}, "C": {"Type": "AWS::Serverless::Application", "Properties": {"Location": "./child.yaml"}}, } stack_child = Mock() stack_child.resources = { "Func1": {"Type": "AWS::Lambda::Function", "Properties": {"a": "b"}}, } convert_mock.side_effect = [function_root, function_child] expected = {"Func1": function_root, "C/Func1": function_child} result = SamFunctionProvider._extract_functions([stack_root, stack_child]) self.assertEqual(expected, result) convert_mock.assert_has_calls( [ call(stack_root, "Func1", {"a": "b"}, [], False), call(stack_child, "Func1", {"a": "b"}, [], False), ] )
def test_must_skip_unknown_resource(self, resources_mock): resources_mock.return_value = {"Func1": {"Type": "AWS::SomeOther::Function", "Properties": {"a": "b"}}} expected = {} result = SamFunctionProvider._extract_functions([make_root_stack(None)]) self.assertEqual(expected, result)
def test_must_work_for_lambda_function(self, convert_mock): convertion_result = "some result" convert_mock.return_value = convertion_result resources = {"Func1": {"Type": "AWS::Lambda::Function", "Properties": {"a": "b"}}} expected = {"Func1": "some result"} result = SamFunctionProvider._extract_functions(resources) self.assertEqual(expected, result) convert_mock.assert_called_with("Func1", {"a": "b"}, [])
def test_must_work_for_sam_function(self, convert_mock): convertion_result = "some result" convert_mock.return_value = convertion_result resources = {"Func1": {"Type": "AWS::Serverless::Function", "Properties": {"a": "b"}}} expected = {"Func1": "some result"} result = SamFunctionProvider._extract_functions(resources) self.assertEqual(expected, result) convert_mock.assert_called_with("Func1", {"a": "b"}, [], ignore_code_extraction_warnings=False)
def test_must_work_for_sam_function(self, convert_mock, resources_mock): convertion_result = Mock() convertion_result.full_path = "A/B/C/Func1" convert_mock.return_value = convertion_result resources_mock.return_value = {"Func1": {"Type": "AWS::Serverless::Function", "Properties": {"a": "b"}}} expected = {"A/B/C/Func1": convertion_result} stack = make_root_stack(None) result = SamFunctionProvider._extract_functions([stack]) self.assertEqual(expected, result) convert_mock.assert_called_with(stack, "Func1", {"a": "b"}, [], False, ignore_code_extraction_warnings=False)
def test_must_work_with_no_properties(self, convert_mock): convertion_result = "some result" convert_mock.return_value = convertion_result resources = { "Func1": { "Type": "AWS::Serverless::Function" # No Properties } } expected = {"Func1": "some result"} result = SamFunctionProvider._extract_functions(resources) self.assertEqual(expected, result) convert_mock.assert_called_with("Func1", {}, [])
def test_must_work_with_no_properties(self, convert_mock, resources_mock): convertion_result = "some result" convert_mock.return_value = convertion_result resources_mock.return_value = { "Func1": { "Type": "AWS::Serverless::Function" # No Properties } } expected = {"Func1": "some result"} result = SamFunctionProvider._extract_functions( [make_root_stack(None)]) self.assertEqual(expected, result) convert_mock.assert_called_with("", "Func1", {}, [], ignore_code_extraction_warnings=False)
def test_must_work_for_lambda_function(self, convert_mock, resources_mock): convertion_result = Mock() convertion_result.full_path = "A/B/C/Func1" convert_mock.return_value = convertion_result resources_mock.return_value = { "Func1": { "Type": "AWS::Lambda::Function", "Properties": { "a": "b" } } } expected = {"A/B/C/Func1": convertion_result} result = SamFunctionProvider._extract_functions( [make_root_stack(None)]) self.assertEqual(expected, result) convert_mock.assert_called_with("", "Func1", {"a": "b"}, [])
def test_must_work_with_no_properties(self, convert_mock, resources_mock): convertion_result = Mock() convertion_result.full_path = "A/B/C/Func1" convert_mock.return_value = convertion_result resources_mock.return_value = { "Func1": { "Type": "AWS::Serverless::Function" # No Properties } } expected = {"A/B/C/Func1": convertion_result} stack = make_root_stack(None) result = SamFunctionProvider._extract_functions([stack]) self.assertEqual(expected, result) convert_mock.assert_called_with( stack, "Func1", {}, [], False, )