-
Notifications
You must be signed in to change notification settings - Fork 96
Enable redirect following and avoid treating 302s as errors #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7c22069
fa27daa
a71c951
eb79bd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
TEST_URL = 'http://www.MockNotRealURL.com/api/path' | ||
TEST_BULK_CANCEL_URL = f'{TEST_URL}/bulk/orders/v2/cancel' | ||
TEST_DOWNLOAD_URL = f'{TEST_URL}/download' | ||
TEST_DOWNLOAD_ACTUAL_URL = f'{TEST_URL}/download_actual' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are probably better names and URLs for this. In the actual API, it's |
||
TEST_ORDERS_URL = f'{TEST_URL}/orders/v2' | ||
TEST_STATS_URL = f'{TEST_URL}/stats/orders/v2' | ||
|
||
|
@@ -540,8 +541,16 @@ async def test_download_asset_md(tmpdir, session): | |
'Content-Type': 'application/json', | ||
'Content-Disposition': 'attachment; filename="metadata.json"' | ||
} | ||
|
||
mock_redirect = httpx.Response(HTTPStatus.FOUND, | ||
headers={ | ||
'Location': TEST_DOWNLOAD_ACTUAL_URL, | ||
'Content-Length': '0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreiberkyle there was an exception in the model module if the redirect response didn't have a content-length header. This feels like something we should fix; our API redirect response has an empty body and we should be able to traverse to the header location without checking the body or its length. |
||
}) | ||
mock_resp = httpx.Response(HTTPStatus.OK, json=md_json, headers=md_headers) | ||
respx.get(dl_url).return_value = mock_resp | ||
|
||
respx.get(dl_url).return_value = mock_redirect | ||
respx.get(TEST_DOWNLOAD_ACTUAL_URL).return_value = mock_resp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreiberkyle @mkshah605 @kevinlacaille @cholmes the orders API redirects when downloading. I'm simulating that here. Default behavior of httpx (no redirect following) will cause this test to fail, which is what the bug reporter was seeing. |
||
|
||
cl = OrdersClient(session, base_url=TEST_URL) | ||
filename = await cl.download_asset(dl_url, directory=str(tmpdir)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #685 (comment). This is probably the same thing as
response.status_code >= 400
but syntactically a little neater, maybe?