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
12
12
from tenacity .stop import stop_after_attempt
13
13
14
14
from cloudpub .common import BaseService
15
- from cloudpub .error import InvalidStateError , NotFoundError
15
+ from cloudpub .error import ConflictError , InvalidStateError , NotFoundError , RunningSubmissionError
16
16
from cloudpub .models .ms_azure import (
17
17
ConfigureStatus ,
18
18
CustomerLeads ,
@@ -213,6 +213,14 @@ def test_wait_for_job_completion_successful_completion(
213
213
assert f"Job { job_id } failed" not in caplog .text
214
214
assert f"Job { job_id } succeeded" in caplog .text
215
215
216
+ @pytest .mark .parametrize (
217
+ "error_name" ,
218
+ [
219
+ "job_details_completed_failure_obj" ,
220
+ "job_details_completed_conflict_obj" ,
221
+ "job_details_completed_running_submission_obj" ,
222
+ ],
223
+ )
216
224
@mock .patch ("cloudpub.ms_azure.utils.is_azure_job_not_complete" )
217
225
@mock .patch ("cloudpub.ms_azure.AzureService._query_job_details" )
218
226
def test_get_job_details_after_failed_completion (
@@ -223,20 +231,26 @@ def test_get_job_details_after_failed_completion(
223
231
caplog : LogCaptureFixture ,
224
232
job_details_running_obj : ConfigureStatus ,
225
233
job_details_completed_failure_obj : ConfigureStatus ,
226
- errors : List [Dict [str , Any ]],
234
+ job_details_completed_conflict_obj : ConfigureStatus ,
235
+ job_details_completed_running_submission_obj : ConfigureStatus ,
236
+ error_name : str ,
237
+ request : pytest .FixtureRequest ,
227
238
) -> None :
239
+
228
240
mock_job_details .side_effect = [
229
241
job_details_running_obj ,
230
242
job_details_running_obj ,
231
243
job_details_running_obj ,
232
- job_details_completed_failure_obj ,
244
+ request . getfixturevalue ( error_name ) ,
233
245
job_details_running_obj ,
234
246
]
235
247
236
248
azure_service ._wait_for_job_completion .retry .sleep = mock .Mock () # type: ignore
237
249
job_id = "job_id_111"
238
250
with caplog .at_level (logging .ERROR ):
239
- with pytest .raises (InvalidStateError ) as e_info :
251
+ with pytest .raises (
252
+ (InvalidStateError , RunningSubmissionError , ConflictError )
253
+ ) as e_info :
240
254
azure_service ._wait_for_job_completion (job_id = job_id )
241
255
assert f"Job { job_id } failed: \n " in str (e_info .value )
242
256
assert mock_job_details .call_count == 4
@@ -858,7 +872,7 @@ def test_publish_preview_success_on_retry(
858
872
None ,
859
873
mock .MagicMock (), # Success on 3rd call
860
874
]
861
- # Remove the retry sleep
875
+ # Remove the retry sleeptest_publish_preview_fail_on_retry
862
876
azure_service ._publish_preview .retry .sleep = mock .Mock () # type: ignore
863
877
864
878
# Test
@@ -888,7 +902,18 @@ def test_publish_preview_fail_on_retry(
888
902
"jobId" : "1" ,
889
903
"jobStatus" : "completed" ,
890
904
"jobResult" : "failed" ,
891
- "errors" : ["failure1" , "failure2" ],
905
+ "errors" : [
906
+ {
907
+ "resourceId" : "resource-id" ,
908
+ "code" : "internalServerError" ,
909
+ "message" : "failure1" ,
910
+ },
911
+ {
912
+ "resourceId" : "resource-id" ,
913
+ "code" : "internalServerError" ,
914
+ "message" : "failure2" ,
915
+ },
916
+ ],
892
917
}
893
918
)
894
919
mock_is_sbpreview .return_value = False
@@ -898,7 +923,7 @@ def test_publish_preview_fail_on_retry(
898
923
azure_service ._publish_preview .retry .sleep = mock .Mock () # type: ignore
899
924
expected_err = (
900
925
f"Failed to submit the product { product_obj .id } to preview. "
901
- "Status: failed Errors: failure1\n failure2 "
926
+ "Status: failed Errors: internalServerError: failure1\n internalServerError: failure2 "
902
927
)
903
928
904
929
# Test
@@ -949,7 +974,18 @@ def test_publish_live_fail_on_retry(
949
974
"jobId" : "1" ,
950
975
"jobStatus" : "completed" ,
951
976
"jobResult" : "failed" ,
952
- "errors" : ["failure1" , "failure2" ],
977
+ "errors" : [
978
+ {
979
+ "resourceId" : "resource-id" ,
980
+ "code" : "internalServerError" ,
981
+ "message" : "failure1" ,
982
+ },
983
+ {
984
+ "resourceId" : "resource-id" ,
985
+ "code" : "internalServerError" ,
986
+ "message" : "failure2" ,
987
+ },
988
+ ],
953
989
}
954
990
)
955
991
mock_subst .side_effect = [err_resp for _ in range (3 )]
@@ -958,7 +994,7 @@ def test_publish_live_fail_on_retry(
958
994
azure_service ._publish_live .retry .sleep = mock .Mock () # type: ignore
959
995
expected_err = (
960
996
f"Failed to submit the product { product_obj .id } to live. "
961
- "Status: failed Errors: failure1\n failure2 "
997
+ "Status: failed Errors: internalServerError: failure1\n internalServerError: failure2 "
962
998
)
963
999
964
1000
# Test
0 commit comments