From c47178996eaeb46fd5565d07ba8fbb4884a4c175 Mon Sep 17 00:00:00 2001 From: Hannes Schmidt Date: Thu, 12 Dec 2024 12:02:13 -0800 Subject: [PATCH] Extract variables for mocked exceptions --- test/service/test_manifest_async.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/service/test_manifest_async.py b/test/service/test_manifest_async.py index 2e4fa8595..bcdcd25b7 100644 --- a/test/service/test_manifest_async.py +++ b/test/service/test_manifest_async.py @@ -250,6 +250,11 @@ def wrapper(*args, **kwargs): machine_arn = service.machine_arn execution_arn = service.execution_arn(execution_name) + not_found = CachedManifestNotFound(manifest_key) + execution_exists = self._mock_sfn_exception(_sfn, + operation_name='StartExecution', + error_code='ExecutionAlreadyExists') + def assert_get_cached_manifest(filters=filters): get_cached_manifest.assert_called_once_with( format=format, @@ -281,7 +286,7 @@ def assert_get_manifest(partition): @reset def put(): nonlocal url, state, token_url - get_cached_manifest.side_effect = CachedManifestNotFound(manifest_key) + get_cached_manifest.side_effect = not_found _sfn.start_execution.return_value = { 'executionArn': execution_arn, 'startDate': 123 @@ -412,11 +417,8 @@ def modified_put(): @reset def modified_put_after_expiration(): nonlocal url - get_cached_manifest.side_effect = CachedManifestNotFound(manifest_key) - exception = self._mock_sfn_exception(_sfn, - operation_name='StartExecution', - error_code='ExecutionAlreadyExists') - _sfn.start_execution.side_effect = exception + get_cached_manifest.side_effect = not_found + _sfn.start_execution.side_effect = execution_exists _sfn.describe_execution.return_value = { 'status': 'SUCCEEDED', 'input': json.dumps(input), @@ -460,7 +462,7 @@ def get_key(): @reset def get_key_after_expiration(): verify_manifest_key.return_value = manifest_key - get_cached_manifest_with_key.side_effect = CachedManifestNotFound(manifest_key) + get_cached_manifest_with_key.side_effect = not_found response = requests.get(str(key_url), allow_redirects=False) self.assertEqual(410, response.status_code) expected_response = {