Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aahung committed Mar 22, 2021
1 parent 6db2af7 commit da68d27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 71 deletions.
70 changes: 11 additions & 59 deletions tests/unit/commands/local/lib/test_sam_function_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,29 +245,7 @@ def setUp(self):
stack_path="",
),
),
(
"SamFunc2",
Function(
name="SamFunc2",
functionname="SamFunc2",
runtime="nodejs4.3",
handler="index.handler",
codeuri=".",
memory=None,
timeout=None,
environment=None,
rolearn=None,
layers=[],
events=None,
metadata=None,
inlinecode=None,
imageuri=None,
imageconfig=None,
packagetype=ZIP,
codesign_config_arn=None,
stack_path="",
),
),
("SamFunc2", None), # codeuri is a s3 location, ignored
(
"SamFunc3",
Function(
Expand Down Expand Up @@ -337,29 +315,7 @@ def setUp(self):
stack_path="",
),
),
(
"LambdaFunc1",
Function(
name="LambdaFunc1",
functionname="LambdaFunc1",
runtime="nodejs4.3",
handler="index.handler",
codeuri=".",
memory=None,
timeout=None,
environment=None,
rolearn=None,
layers=[],
events=None,
metadata=None,
inlinecode=None,
imageuri=None,
imageconfig=None,
packagetype=ZIP,
codesign_config_arn=None,
stack_path="",
),
),
("LambdaFunc1", None), # codeuri is a s3 location, ignored
(
"LambdaFuncWithInlineCode",
Function(
Expand Down Expand Up @@ -561,11 +517,9 @@ def test_get_all_must_return_all_functions(self):
expected = {
"SamFunctions",
"SamFuncWithInlineCode",
"SamFunc2",
"SamFunc3",
"SamFunc4",
"SamFuncWithFunctionNameOverride",
"LambdaFunc1",
"LambdaFuncWithInlineCode",
"LambdaFunc2",
"LambdaFuncWithLocalPath",
Expand All @@ -576,7 +530,7 @@ def test_get_all_must_return_all_functions(self):
posixpath.join("ChildStack", "SamImageFunctionsInChild"),
}

self.assertEqual(result, expected)
self.assertEqual(expected, result)


class TestSamFunctionProvider_init(TestCase):
Expand Down Expand Up @@ -627,7 +581,7 @@ def test_must_work_for_sam_function(self, convert_mock, resources_mock):
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)
convert_mock.assert_called_with(stack, "Func1", {"a": "b"}, [], False)

@patch("samcli.lib.providers.sam_function_provider.Stack.resources", new_callable=PropertyMock)
@patch.object(SamFunctionProvider, "_convert_sam_function_resource")
Expand All @@ -648,7 +602,13 @@ def test_must_work_with_no_properties(self, convert_mock, resources_mock):
stack = make_root_stack(None)
result = SamFunctionProvider._extract_functions([stack])
self.assertEqual(expected, result)
convert_mock.assert_called_with(stack, "Func1", {}, [], False, ignore_code_extraction_warnings=False)
convert_mock.assert_called_with(
stack,
"Func1",
{},
[],
False,
)

@patch("samcli.lib.providers.sam_function_provider.Stack.resources", new_callable=PropertyMock)
@patch.object(SamFunctionProvider, "_convert_lambda_function_resource")
Expand Down Expand Up @@ -915,14 +875,6 @@ def test_must_handle_code_dict(self):
result = SamFunctionProvider._convert_sam_function_resource(STACK, name, properties, [])
self.assertEqual(result.codeuri, ".") # Default value

def test_must_handle_code_s3_uri(self):

name = "myname"
properties = {"CodeUri": "s3://bucket/key"}

result = SamFunctionProvider._convert_sam_function_resource(STACK, name, properties, [])
self.assertEqual(result.codeuri, ".") # Default value


class TestSamFunctionProvider_convert_lambda_function_resource(TestCase):
def test_must_convert(self):
Expand Down
16 changes: 4 additions & 12 deletions tests/unit/commands/local/lib/test_sam_layer_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,8 @@ def setUp(self):
"LambdaLayerNoBuild",
LayerVersion("LambdaLayerNoBuild", "PyLayer", ["python3.8", "python3.6"], None, stack_path=""),
),
(
"ServerlessLayerS3Content",
LayerVersion("ServerlessLayerS3Content", ".", ["python3.8", "python3.6"], None, stack_path=""),
),
(
"LambdaLayerS3Content",
LayerVersion("LambdaLayerS3Content", ".", ["python3.8", "python3.6"], None, stack_path=""),
),
("ServerlessLayerS3Content", None), # codeuri is a s3 location, ignored
("LambdaLayerS3Content", None), # codeuri is a s3 location, ignored
(
posixpath.join("ChildStack", "SamLayerInChild"),
LayerVersion(
Expand All @@ -157,7 +151,7 @@ def setUp(self):
)
def test_get_must_return_each_layer(self, name, expected_output):
actual = self.provider.get(name)
self.assertEqual(actual, expected_output)
self.assertEqual(expected_output, actual)

def test_get_all_must_return_all_layers(self):
result = [posixpath.join(f.stack_path, f.arn) for f in self.provider.get_all()]
Expand All @@ -166,12 +160,10 @@ def test_get_all_must_return_all_layers(self):
"LambdaLayer",
"ServerlessLayerNoBuild",
"LambdaLayerNoBuild",
"ServerlessLayerS3Content",
"LambdaLayerS3Content",
posixpath.join("ChildStack", "SamLayerInChild"),
]

self.assertEqual(result, expected)
self.assertEqual(expected, result)

def test_provider_ignores_non_layer_resource(self):
self.assertIsNone(self.provider.get("SamFunc"))
Expand Down

0 comments on commit da68d27

Please sign in to comment.