def test_schedule_reinvocation_cloudwatch_callback(): progress = ProgressEvent(status=OperationStatus.IN_PROGRESS, callbackDelaySeconds=60) mock_request = Mock( "cloudformation_cli_python_lib.interface.HandlerRequest", autospec=True)() mock_request.requestContext = {} mock_context = Mock( "cloudformation_cli_python_lib.interface.LambdaContext", autospec=True)() mock_context.get_remaining_time_in_millis.return_value = 6000 mock_context.invoked_function_arn = "arn:aaa:bbb:ccc" with patch( "cloudformation_cli_python_lib.resource.reschedule_after_minutes", autospec=True) as mock_reschedule, patch( "cloudformation_cli_python_lib.resource.sleep", autospec=True) as mock_sleep: reinvoke = Resource.schedule_reinvocation(mock_request, progress, mock_context, Mock()) assert reinvoke is False mock_reschedule.assert_called_once_with( ANY, function_arn="arn:aaa:bbb:ccc", minutes_from_now=1, handler_request=mock_request, ) mock_sleep.assert_not_called() assert mock_request.requestContext.get("invocation") == 1
def test_schedule_reinvocation_not_in_progress(): progress = ProgressEvent(status=OperationStatus.SUCCESS) with patch( "cloudformation_cli_python_lib.resource._get_boto_session", autospec=True ) as mock_session, patch( "cloudformation_cli_python_lib.resource.reschedule_after_minutes", autospec=True) as mock_reschedule: reinvoke = Resource.schedule_reinvocation(sentinel.request, progress, sentinel.context, sentinel.session) assert reinvoke is False mock_session.assert_not_called() mock_reschedule.assert_not_called()
def test_schedule_reinvocation_local_callback(): progress = ProgressEvent(status=OperationStatus.IN_PROGRESS, callbackDelaySeconds=5) mock_request = Mock( "cloudformation_cli_python_lib.interface.HandlerRequest", autospec=True)() mock_request.requestContext = {} mock_context = Mock( "cloudformation_cli_python_lib.interface.LambdaContext", autospec=True)() mock_context.get_remaining_time_in_millis.return_value = 600000 with patch("cloudformation_cli_python_lib.resource.sleep", autospec=True) as mock_sleep: reinvoke = Resource.schedule_reinvocation(mock_request, progress, mock_context, sentinel.session) assert reinvoke is True mock_sleep.assert_called_once_with(5) assert mock_request.requestContext.get("invocation") == 1