@@ -118,11 +118,11 @@ def _check_report_status_response(
118
118
"dataEndTime" : CONFIG_END_DATE ,
119
119
"createdTime" : CONFIG_START_DATE ,
120
120
"dataStartTime" : CONFIG_START_DATE ,
121
+ "reportDocumentId" : report_document_id ,
121
122
}
122
123
if processing_status == ReportProcessingStatus .DONE :
123
124
response_body .update (
124
125
{
125
- "reportDocumentId" : report_document_id ,
126
126
"processingEndTime" : CONFIG_START_DATE ,
127
127
"processingStartTime" : CONFIG_START_DATE ,
128
128
}
@@ -141,18 +141,22 @@ def _get_document_download_url_response(
141
141
return build_response (response_body , status_code = HTTPStatus .OK )
142
142
143
143
144
- def _download_document_response (
145
- stream_name : str , data_format : Optional [str ] = "csv" , compressed : Optional [bool ] = False
146
- ) -> HttpResponse :
144
+ def _download_document_response (stream_name : str , data_format : Optional [str ] = "csv" , compressed : Optional [bool ] = False ) -> HttpResponse :
147
145
response_body = find_template (stream_name , __file__ , data_format )
148
146
if compressed :
149
147
response_body = gzip .compress (response_body .encode ("iso-8859-1" ))
150
148
return HttpResponse (body = response_body , status_code = HTTPStatus .OK )
151
149
152
150
151
+ def _download_document_error_response (compressed : Optional [bool ] = False ) -> HttpResponse :
152
+ response_body = '{"errorDetails":"Error in report request: This report type requires the reportPeriod, distributorView, sellingProgram reportOption to be specified. Please review the document for this report type on GitHub, provide a value for this reportOption in your request, and try again."}'
153
+ if compressed :
154
+ response_body = gzip .compress (response_body .encode ("iso-8859-1" ))
155
+ return HttpResponse (body = response_body , status_code = HTTPStatus .OK )
156
+
157
+
153
158
@freezegun .freeze_time (NOW .isoformat ())
154
159
class TestFullRefresh :
155
-
156
160
@staticmethod
157
161
def _read (stream_name : str , config_ : ConfigBuilder , expecting_exception : bool = False ) -> EntrypointOutput :
158
162
return read_output (
@@ -164,9 +168,7 @@ def _read(stream_name: str, config_: ConfigBuilder, expecting_exception: bool =
164
168
165
169
@pytest .mark .parametrize (("stream_name" , "data_format" ), STREAMS )
166
170
@HttpMocker ()
167
- def test_given_report_when_read_then_return_records (
168
- self , stream_name : str , data_format : str , http_mocker : HttpMocker
169
- ) -> None :
171
+ def test_given_report_when_read_then_return_records (self , stream_name : str , data_format : str , http_mocker : HttpMocker ) -> None :
170
172
mock_auth (http_mocker )
171
173
172
174
http_mocker .post (_create_report_request (stream_name ).build (), _create_report_response (_REPORT_ID ))
@@ -329,9 +331,7 @@ def test_given_report_access_forbidden_when_read_then_no_records_and_error_logge
329
331
) -> None :
330
332
mock_auth (http_mocker )
331
333
332
- http_mocker .post (
333
- _create_report_request (stream_name ).build (), response_with_status (status_code = HTTPStatus .FORBIDDEN )
334
- )
334
+ http_mocker .post (_create_report_request (stream_name ).build (), response_with_status (status_code = HTTPStatus .FORBIDDEN ))
335
335
336
336
output = self ._read (stream_name , config ())
337
337
message_on_access_forbidden = (
@@ -354,9 +354,7 @@ def test_given_report_status_cancelled_when_read_then_stream_completed_successfu
354
354
_check_report_status_response (stream_name , processing_status = ReportProcessingStatus .CANCELLED ),
355
355
)
356
356
357
- message_on_report_cancelled = (
358
- f"The report for stream '{ stream_name } ' was cancelled or there is no data to return."
359
- )
357
+ message_on_report_cancelled = f"The report for stream '{ stream_name } ' was cancelled or there is no data to return."
360
358
361
359
output = self ._read (stream_name , config ())
362
360
assert_message_in_log_output (message_on_report_cancelled , output )
@@ -372,14 +370,27 @@ def test_given_report_status_fatal_when_read_then_exception_raised(
372
370
http_mocker .post (_create_report_request (stream_name ).build (), _create_report_response (_REPORT_ID ))
373
371
http_mocker .get (
374
372
_check_report_status_request (_REPORT_ID ).build (),
375
- _check_report_status_response (stream_name , processing_status = ReportProcessingStatus .FATAL ),
373
+ _check_report_status_response (
374
+ stream_name , processing_status = ReportProcessingStatus .FATAL , report_document_id = _REPORT_DOCUMENT_ID
375
+ ),
376
+ )
377
+
378
+ http_mocker .get (
379
+ _get_document_download_url_request (_REPORT_DOCUMENT_ID ).build (),
380
+ _get_document_download_url_response (_DOCUMENT_DOWNLOAD_URL , _REPORT_DOCUMENT_ID ),
381
+ )
382
+ http_mocker .get (
383
+ _download_document_request (_DOCUMENT_DOWNLOAD_URL ).build (),
384
+ [
385
+ response_with_status (status_code = HTTPStatus .INTERNAL_SERVER_ERROR ),
386
+ _download_document_error_response (),
387
+ ],
376
388
)
377
389
378
390
output = self ._read (stream_name , config (), expecting_exception = True )
379
391
assert output .errors [- 1 ].trace .error .failure_type == FailureType .config_error
380
392
assert (
381
- f"Failed to retrieve the report '{ stream_name } ' for period { CONFIG_START_DATE } -{ CONFIG_END_DATE } "
382
- "due to Amazon Seller Partner platform issues. This will be read during the next sync."
393
+ f"Failed to retrieve the report '{ stream_name } ' for period { CONFIG_START_DATE } -{ CONFIG_END_DATE } . This will be read during the next sync. Error: {{'errorDetails': 'Error in report request: This report type requires the reportPeriod, distributorView, sellingProgram reportOption to be specified. Please review the document for this report type on GitHub, provide a value for this reportOption in your request, and try again.'}}"
383
394
) in output .errors [- 1 ].trace .error .message
384
395
385
396
@pytest .mark .parametrize (
@@ -405,9 +416,7 @@ def test_given_report_with_incorrect_date_format_when_read_then_formatted(
405
416
_get_document_download_url_request (_REPORT_DOCUMENT_ID ).build (),
406
417
_get_document_download_url_response (_DOCUMENT_DOWNLOAD_URL , _REPORT_DOCUMENT_ID ),
407
418
)
408
- http_mocker .get (
409
- _download_document_request (_DOCUMENT_DOWNLOAD_URL ).build (), _download_document_response (stream_name )
410
- )
419
+ http_mocker .get (_download_document_request (_DOCUMENT_DOWNLOAD_URL ).build (), _download_document_response (stream_name ))
411
420
412
421
output = self ._read (stream_name , config ())
413
422
assert len (output .records ) == DEFAULT_EXPECTED_NUMBER_OF_RECORDS
@@ -425,9 +434,7 @@ def test_given_http_error_500_on_create_report_when_read_then_no_records_and_err
425
434
response_with_status (status_code = HTTPStatus .INTERNAL_SERVER_ERROR ),
426
435
)
427
436
428
- message_on_backoff_exception = (
429
- f"The report for stream '{ stream_name } ' was cancelled due to several failed retry attempts."
430
- )
437
+ message_on_backoff_exception = f"The report for stream '{ stream_name } ' was cancelled due to several failed retry attempts."
431
438
432
439
output = self ._read (stream_name , config ())
433
440
assert_message_in_log_output (message_on_backoff_exception , output )
0 commit comments