1
1
import json
2
2
import logging
3
3
from copy import deepcopy
4
- from typing import Any , Dict , List
4
+ from typing import Any , Dict
5
5
from unittest import mock
6
6
7
7
import pytest
13
13
from tenacity .stop import stop_after_attempt
14
14
15
15
from cloudpub .common import BaseService
16
- from cloudpub .error import InvalidStateError , NotFoundError
16
+ from cloudpub .error import ConflictError , InvalidStateError , NotFoundError , RunningSubmissionError
17
17
from cloudpub .models .ms_azure import (
18
18
ConfigureStatus ,
19
19
CustomerLeads ,
@@ -214,6 +214,14 @@ def test_wait_for_job_completion_successful_completion(
214
214
assert f"Job { job_id } failed" not in caplog .text
215
215
assert f"Job { job_id } succeeded" in caplog .text
216
216
217
+ @pytest .mark .parametrize (
218
+ "error_name" ,
219
+ [
220
+ "job_details_completed_failure_obj" ,
221
+ "job_details_completed_conflict_obj" ,
222
+ "job_details_completed_running_submission_obj" ,
223
+ ],
224
+ )
217
225
@mock .patch ("cloudpub.ms_azure.utils.is_azure_job_not_complete" )
218
226
@mock .patch ("cloudpub.ms_azure.AzureService._query_job_details" )
219
227
def test_get_job_details_after_failed_completion (
@@ -224,20 +232,26 @@ def test_get_job_details_after_failed_completion(
224
232
caplog : LogCaptureFixture ,
225
233
job_details_running_obj : ConfigureStatus ,
226
234
job_details_completed_failure_obj : ConfigureStatus ,
227
- errors : List [Dict [str , Any ]],
235
+ job_details_completed_conflict_obj : ConfigureStatus ,
236
+ job_details_completed_running_submission_obj : ConfigureStatus ,
237
+ error_name : str ,
238
+ request : pytest .FixtureRequest ,
228
239
) -> None :
240
+
229
241
mock_job_details .side_effect = [
230
242
job_details_running_obj ,
231
243
job_details_running_obj ,
232
244
job_details_running_obj ,
233
- job_details_completed_failure_obj ,
245
+ request . getfixturevalue ( error_name ) ,
234
246
job_details_running_obj ,
235
247
]
236
248
237
249
azure_service ._wait_for_job_completion .retry .sleep = mock .Mock () # type: ignore
238
250
job_id = "job_id_111"
239
251
with caplog .at_level (logging .ERROR ):
240
- with pytest .raises (InvalidStateError ) as e_info :
252
+ with pytest .raises (
253
+ (InvalidStateError , RunningSubmissionError , ConflictError )
254
+ ) as e_info :
241
255
azure_service ._wait_for_job_completion (job_id = job_id )
242
256
assert f"Job { job_id } failed: \n " in str (e_info .value )
243
257
assert mock_job_details .call_count == 4
@@ -861,7 +875,7 @@ def test_publish_preview_success_on_retry(
861
875
None ,
862
876
mock .MagicMock (), # Success on 3rd call
863
877
]
864
- # Remove the retry sleep
878
+ # Remove the retry sleeptest_publish_preview_fail_on_retry
865
879
azure_service ._publish_preview .retry .sleep = mock .Mock () # type: ignore
866
880
867
881
# Test
@@ -891,7 +905,18 @@ def test_publish_preview_fail_on_retry(
891
905
"jobId" : "1" ,
892
906
"jobStatus" : "completed" ,
893
907
"jobResult" : "failed" ,
894
- "errors" : ["failure1" , "failure2" ],
908
+ "errors" : [
909
+ {
910
+ "resourceId" : "resource-id" ,
911
+ "code" : "internalServerError" ,
912
+ "message" : "failure1" ,
913
+ },
914
+ {
915
+ "resourceId" : "resource-id" ,
916
+ "code" : "internalServerError" ,
917
+ "message" : "failure2" ,
918
+ },
919
+ ],
895
920
}
896
921
)
897
922
mock_is_sbpreview .return_value = False
@@ -901,7 +926,7 @@ def test_publish_preview_fail_on_retry(
901
926
azure_service ._publish_preview .retry .sleep = mock .Mock () # type: ignore
902
927
expected_err = (
903
928
f"Failed to submit the product { product_obj .id } to preview. "
904
- "Status: failed Errors: failure1\n failure2 "
929
+ "Status: failed Errors: internalServerError: failure1\n internalServerError: failure2 "
905
930
)
906
931
907
932
# Test
@@ -952,7 +977,18 @@ def test_publish_live_fail_on_retry(
952
977
"jobId" : "1" ,
953
978
"jobStatus" : "completed" ,
954
979
"jobResult" : "failed" ,
955
- "errors" : ["failure1" , "failure2" ],
980
+ "errors" : [
981
+ {
982
+ "resourceId" : "resource-id" ,
983
+ "code" : "internalServerError" ,
984
+ "message" : "failure1" ,
985
+ },
986
+ {
987
+ "resourceId" : "resource-id" ,
988
+ "code" : "internalServerError" ,
989
+ "message" : "failure2" ,
990
+ },
991
+ ],
956
992
}
957
993
)
958
994
mock_subst .side_effect = [err_resp for _ in range (3 )]
@@ -961,7 +997,7 @@ def test_publish_live_fail_on_retry(
961
997
azure_service ._publish_live .retry .sleep = mock .Mock () # type: ignore
962
998
expected_err = (
963
999
f"Failed to submit the product { product_obj .id } to live. "
964
- "Status: failed Errors: failure1\n failure2 "
1000
+ "Status: failed Errors: internalServerError: failure1\n internalServerError: failure2 "
965
1001
)
966
1002
967
1003
# Test
0 commit comments