From 484a1753b7e45d4c2ed551035091102fea3296cc Mon Sep 17 00:00:00 2001 From: Sylvie Dyer Date: Tue, 8 Oct 2024 22:55:34 +0000 Subject: [PATCH] Adding mpr validations to rpdk with testing --- src/rpdk/core/project.py | 18 ++++++++++-------- tests/test_project.py | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/rpdk/core/project.py b/src/rpdk/core/project.py index 81a85b68..10c48a40 100644 --- a/src/rpdk/core/project.py +++ b/src/rpdk/core/project.py @@ -304,7 +304,7 @@ def load_settings(self): "Please consider upgrading to CFN-CLI 2.0 following the guide: " "https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/what-is-cloudformation-cli.html" ) - + # backward compatible if "artifact_type" not in raw_settings: raw_settings["artifact_type"] = ARTIFACT_TYPE_RESOURCE @@ -867,13 +867,15 @@ def generate_docs(self): target_names = ( self.target_info.keys() if self.target_info - else { - target_name - for handler in self.schema.get("handlers", {}).values() - for target_name in handler.get("targetNames", []) - } - if self.artifact_type == ARTIFACT_TYPE_HOOK - else [] + else ( + { + target_name + for handler in self.schema.get("handlers", {}).values() + for target_name in handler.get("targetNames", []) + } + if self.artifact_type == ARTIFACT_TYPE_HOOK + else [] + ) ) LOG.debug("Removing generated docs: %s", docs_path) diff --git a/tests/test_project.py b/tests/test_project.py index 68bfe681..80d87510 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -174,7 +174,9 @@ def test_load_settings_invalid_hooks_settings(project): def test_load_settings_invalid_protocol_version(project): - with patch_settings(project, '{"settings": {"protocolVersion": "3.0.0"}}') as mock_open: + with patch_settings( + project, '{"settings": {"protocolVersion": "3.0.0"}}' + ) as mock_open: with pytest.raises(InvalidProjectError): project.load_settings() mock_open.assert_called_once_with("r", encoding="utf-8") @@ -183,11 +185,7 @@ def test_load_settings_invalid_protocol_version(project): def test_load_settings_missing_protocol_version(project): plugin = object() data = json.dumps( - { - "artifact_type": "MODULE", - "typeName": MODULE_TYPE_NAME, - "settings": {} - } + {"artifact_type": "MODULE", "typeName": MODULE_TYPE_NAME, "settings": {}} ) patch_load = patch( "rpdk.core.project.load_plugin", autospec=True, return_value=plugin @@ -195,7 +193,13 @@ def test_load_settings_missing_protocol_version(project): with patch_settings(project, data) as mock_open, patch_load as mock_load: project.load_settings() - + mock_open.assert_called_once_with("r", encoding="utf-8") + mock_load.assert_not_called() + assert project.type_info == ("AWS", "Color", "Red", "MODULE") + assert project.type_name == MODULE_TYPE_NAME + assert project.language is None + assert project.artifact_type == ARTIFACT_TYPE_MODULE + assert project._plugin is None assert project.settings == {} @@ -324,9 +328,7 @@ def test_load_settings_valid_protocol_version(project): { "artifact_type": "MODULE", "typeName": MODULE_TYPE_NAME, - "settings": { - "protocolVersion": "2.0.0" - } + "settings": {"protocolVersion": "2.0.0"}, } ) patch_load = patch(