Skip to content

Commit

Permalink
Adding mpr validations to rpdk with testing
Browse files Browse the repository at this point in the history
  • Loading branch information
syldyer committed Oct 8, 2024
1 parent 83f6962 commit 484a175
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
18 changes: 10 additions & 8 deletions src/rpdk/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 12 additions & 10 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -183,19 +185,21 @@ 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
)

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 == {}


Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 484a175

Please sign in to comment.