def test_entrypoint_success_without_caller_provider_creds(): resource = Resource(TYPE_NAME, Mock()) event = ProgressEvent(status=OperationStatus.SUCCESS, message="") resource.handler(Action.CREATE)(Mock(return_value=event)) payload = ENTRYPOINT_PAYLOAD.copy() payload["requestData"] = payload["requestData"].copy() expected = { "message": "", "status": OperationStatus.SUCCESS, "callbackDelaySeconds": 0, } with patch( "cloudformation_cli_python_lib.resource.ProviderLogHandler.setup"): # Credentials are defined in payload, but null payload["requestData"]["providerCredentials"] = None payload["requestData"]["callerCredentials"] = None event = resource.__call__.__wrapped__( # pylint: disable=no-member resource, payload, None) assert event == expected # Credentials are undefined in payload del payload["requestData"]["providerCredentials"] del payload["requestData"]["callerCredentials"] event = resource.__call__.__wrapped__( # pylint: disable=no-member resource, payload, None) assert event == expected
def test_entrypoint_non_mutating_action(): payload = ENTRYPOINT_PAYLOAD.copy() payload["action"] = "READ" resource = Resource(TYPE_NAME, Mock()) event = ProgressEvent(status=OperationStatus.SUCCESS, message="") resource.handler(Action.CREATE)(Mock(return_value=event)) with patch( "cloudformation_cli_python_lib.resource.ProviderLogHandler.setup" ) as mock_return_progress: resource.__call__.__wrapped__( # pylint: disable=no-member resource, payload, None) assert mock_return_progress.call_count == 1
def test_test_entrypoint_success(): mock_model = Mock(spec_set=["_deserialize"]) mock_model._deserialize.side_effect = [None, None] resource = Resource(TYPE_NAME, mock_model) progress_event = ProgressEvent(status=OperationStatus.SUCCESS) mock_handler = resource.handler(Action.CREATE)( Mock(return_value=progress_event)) payload = { "credentials": { "accessKeyId": "", "secretAccessKey": "", "sessionToken": "" }, "action": "CREATE", "request": { "clientRequestToken": "ecba020e-b2e6-4742-a7d0-8a06ae7c4b2b", "desiredResourceState": None, "previousResourceState": None, "logicalResourceIdentifier": None, }, } event = resource.test_entrypoint.__wrapped__( # pylint: disable=no-member resource, payload, None) assert event is progress_event mock_model._deserialize.assert_has_calls([call(None), call(None)]) mock_handler.assert_called_once()
def test_entrypoint_with_context(): payload = ENTRYPOINT_PAYLOAD.copy() payload["callbackContext"] = {"a": "b"} resource = Resource(TYPE_NAME, Mock()) event = ProgressEvent(status=OperationStatus.SUCCESS, message="", callbackContext={"c": "d"}) mock_handler = resource.handler(Action.CREATE)(Mock(return_value=event)) with patch( "cloudformation_cli_python_lib.resource.ProviderLogHandler.setup"): resource.__call__.__wrapped__( # pylint: disable=no-member resource, payload, None) mock_handler.assert_called_once()
def test_entrypoint_success(): resource = Resource(TYPE_NAME, Mock()) event = ProgressEvent(status=OperationStatus.SUCCESS, message="") mock_handler = resource.handler(Action.CREATE)(Mock(return_value=event)) with patch( "cloudformation_cli_python_lib.resource.ProviderLogHandler.setup" ) as mock_log_delivery: event = resource.__call__.__wrapped__( # pylint: disable=no-member resource, ENTRYPOINT_PAYLOAD, None) mock_log_delivery.assert_called_once() assert event == { "message": "", "status": OperationStatus.SUCCESS.name, # pylint: disable=no-member "callbackDelaySeconds": 0, } mock_handler.assert_called_once()
def test_entrypoint_success(): resource = Resource(TYPE_NAME, Mock()) event = ProgressEvent(status=OperationStatus.SUCCESS, message="") mock_handler = resource.handler(Action.CREATE)(Mock(return_value=event)) with patch( "cloudformation_cli_python_lib.resource.ProviderLogHandler.setup" ) as mock_log_delivery, patch( "cloudformation_cli_python_lib.resource.report_progress", autospec=True) as mock_report_progress: event = resource.__call__.__wrapped__( # pylint: disable=no-member resource, ENTRYPOINT_PAYLOAD, None) assert mock_report_progress.call_count == 2 mock_log_delivery.assert_called_once() assert event == { "message": "", "bearerToken": "123456", "operationStatus": OperationStatus.SUCCESS.name, # pylint: disable=no-member } mock_handler.assert_called_once()