7
7
import requests
8
8
from source_shopify .shopify_graphql .bulk .exceptions import ShopifyBulkExceptions
9
9
from source_shopify .shopify_graphql .bulk .job import ShopifyBulkStatus
10
- from source_shopify .streams .base_streams import IncrementalShopifyGraphQlBulkStream
11
10
from source_shopify .streams .streams import (
12
11
Collections ,
13
12
CustomerAddress ,
@@ -119,28 +118,21 @@ def test_job_retry_on_concurrency(request, requests_mock, bulk_job_response, con
119
118
120
119
121
120
@pytest .mark .parametrize (
122
- "job_response, error_type, patch_healthcheck, expected" ,
121
+ "job_response, error_type, expected" ,
123
122
[
124
- (
125
- "bulk_job_completed_response" ,
126
- None ,
127
- False ,
128
- "bulk-123456789.jsonl" ,
129
- ),
130
- ("bulk_job_failed_response" , ShopifyBulkExceptions .BulkJobFailed , False , "exited with FAILED" ),
131
- ("bulk_job_timeout_response" , ShopifyBulkExceptions .BulkJobTimout , False , "exited with TIMEOUT" ),
132
- ("bulk_job_access_denied_response" , ShopifyBulkExceptions .BulkJobAccessDenied , False , "exited with ACCESS_DENIED" ),
133
- ("bulk_successful_response_with_errors" , ShopifyBulkExceptions .BulkJobUnknownError , True , "Could not validate the status of the BULK Job" ),
123
+ ("bulk_job_completed_response" , None , "bulk-123456789.jsonl" ),
124
+ ("bulk_job_failed_response" , ShopifyBulkExceptions .BulkJobFailed , "exited with FAILED" ),
125
+ ("bulk_job_timeout_response" , ShopifyBulkExceptions .BulkJobTimout , "exited with TIMEOUT" ),
126
+ ("bulk_job_access_denied_response" , ShopifyBulkExceptions .BulkJobAccessDenied , "exited with ACCESS_DENIED" ),
134
127
],
135
128
ids = [
136
129
"completed" ,
137
130
"failed" ,
138
131
"timeout" ,
139
132
"access_denied" ,
140
- "success with errors (edge)" ,
141
133
],
142
134
)
143
- def test_job_check (mocker , request , requests_mock , job_response , auth_config , error_type , patch_healthcheck , expected ) -> None :
135
+ def test_job_check (mocker , request , requests_mock , job_response , auth_config , error_type , expected ) -> None :
144
136
stream = MetafieldOrders (auth_config )
145
137
# modify the sleep time for the test
146
138
stream .job_manager .concurrent_max_retry = 1
@@ -151,8 +143,6 @@ def test_job_check(mocker, request, requests_mock, job_response, auth_config, er
151
143
# patching the method to get the right ID checks
152
144
if job_id :
153
145
mocker .patch ("source_shopify.shopify_graphql.bulk.job.ShopifyBulkManager.job_get_id" , value = job_id )
154
- if patch_healthcheck :
155
- mocker .patch ("source_shopify.shopify_graphql.bulk.job.ShopifyBulkManager.job_healthcheck" , value = job_response )
156
146
# mocking the response for STATUS CHECKS
157
147
requests_mock .post (stream .job_manager .base_url , json = request .getfixturevalue (job_response ))
158
148
test_job_status_response = requests .post (stream .job_manager .base_url )
@@ -167,6 +157,40 @@ def test_job_check(mocker, request, requests_mock, job_response, auth_config, er
167
157
requests_mock .get (job_result_url , json = request .getfixturevalue (job_response ))
168
158
result = stream .job_manager .job_check (test_job_status_response )
169
159
assert expected == result
160
+
161
+
162
+ @pytest .mark .parametrize (
163
+ "job_response, error_type, expected" ,
164
+ [
165
+ (
166
+ "bulk_successful_response_with_errors" ,
167
+ ShopifyBulkExceptions .BulkJobUnknownError ,
168
+ "Could not validate the status of the BULK Job" ,
169
+ ),
170
+ ],
171
+ ids = [
172
+ "success with errors (edge)" ,
173
+ ],
174
+ )
175
+ def test_one_time_retry_job_check (mocker , request , requests_mock , job_response , auth_config , error_type , expected ) -> None :
176
+ stream = MetafieldOrders (auth_config )
177
+ # modify the sleep time for the test
178
+ stream .job_manager .concurrent_max_retry = 1
179
+ stream .job_manager .concurrent_interval_sec = 1
180
+ stream .job_manager .job_check_interval_sec = 1
181
+ # get job_id from FIXTURE
182
+ job_id = request .getfixturevalue (job_response ).get ("data" , {}).get ("node" , {}).get ("id" )
183
+ # patching the method to get the right ID checks
184
+ if job_id :
185
+ mocker .patch ("source_shopify.shopify_graphql.bulk.job.ShopifyBulkManager.job_get_id" , value = job_id )
186
+ # mocking the response for STATUS CHECKS
187
+ requests_mock .post (stream .job_manager .base_url , json = request .getfixturevalue (job_response ))
188
+ test_job_status_response = requests .post (stream .job_manager .base_url )
189
+ with pytest .raises (error_type ) as error :
190
+ stream .job_manager .job_check (test_job_status_response )
191
+ # The retried request should FAIL here, because we stil want to see the Exception raised
192
+ # We expect the call count to be 4 due to the status checks, the non-retried request would take 2 calls.
193
+ assert expected in repr (error .value ) and requests_mock .call_count == 4
170
194
171
195
172
196
@pytest .mark .parametrize (
0 commit comments