From ff6602f7685d0ecdb91d4f8d84fedd9319112c5d Mon Sep 17 00:00:00 2001 From: Chauncy McCaughey Date: Thu, 11 May 2023 10:34:35 -0600 Subject: [PATCH 1/2] fix: stackId not setable during 'cfn invoke' testing of RESOURCE --- src/rpdk/core/invoke.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpdk/core/invoke.py b/src/rpdk/core/invoke.py index c1620713..3ce13550 100644 --- a/src/rpdk/core/invoke.py +++ b/src/rpdk/core/invoke.py @@ -110,6 +110,7 @@ def invoke(args): request["desiredResourceState"], request["previousResourceState"], request.get("typeConfiguration"), + stackId=request.get("stackId") ) # pylint: disable=too-many-function-args current_invocation = 0 From 5b181d6cd0a9ed52e40545abbd0eade5869a7e7f Mon Sep 17 00:00:00 2001 From: Chauncy McCaughey Date: Thu, 11 May 2023 11:46:20 -0600 Subject: [PATCH 2/2] fix: add missing stackId unit test --- tests/contract/test_resource_client.py | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/contract/test_resource_client.py b/tests/contract/test_resource_client.py index 8bb7958d..ee451ea8 100644 --- a/tests/contract/test_resource_client.py +++ b/tests/contract/test_resource_client.py @@ -1088,6 +1088,37 @@ def test_make_payload(resource_client): } +def test_make_payload_with_stack_id(resource_client): + patch_creds = patch( + "rpdk.core.contract.resource_client.get_temporary_credentials", + autospec=True, + return_value={}, + ) + + token = "ecba020e-b2e6-4742-a7d0-8a06ae7c4b2f" + with patch.object( + resource_client, "generate_token", return_value=token + ), patch_creds: + payload = resource_client._make_payload("CREATE", {"foo": "bar"}, stackId="test-stack") + + assert payload == { + "requestData": { + "callerCredentials": {}, + "resourceProperties": {"foo": "bar"}, + "previousResourceProperties": None, + "logicalResourceId": token, + "typeConfiguration": None, + }, + "region": DEFAULT_REGION, + "awsAccountId": ACCOUNT, + "action": "CREATE", + "bearerToken": token, + "callbackContext": None, + "resourceType": None, + "stackId": "test-stack", + } + + @pytest.mark.parametrize("action", [Action.READ, Action.LIST]) def test_call_sync(resource_client, action): patch_creds = patch(