| 1 |
from globus_sdk.testing import RegisteredResponse, load_response |
| 2 |
|
| 3 |
|
| 4 |
def test_allow_redirects_false(client): |
| 5 |
# based on a real response from 'GET https://auth.globus.org/' |
| 6 |
load_response( |
| 7 |
RegisteredResponse( |
| 8 |
path="https://foo.api.globus.org/bar", |
| 9 |
status=302, |
| 10 |
headers={ |
| 11 |
"Date": "Fri, 15 Apr 2022 15:35:44 GMT", |
| 12 |
"Content-Type": "text/html", |
| 13 |
"Connection": "keep-alive", |
| 14 |
"Server": "nginx", |
| 15 |
"Location": "https://www.globus.org/", |
| 16 |
}, |
| 17 |
body="""\ |
| 18 |
<html> |
| 19 |
<head><title>302 Found</title></head> |
| 20 |
<body> |
| 21 |
<center><h1>302 Found</h1></center> |
| 22 |
<hr><center>nginx</center> |
| 23 |
</body> |
| 24 |
</html> |
| 25 |
""", |
| 26 |
) |
| 27 |
) |
| 28 |
# NOTE: this test isn't very "real" because of where `responses` intercepts the |
| 29 |
# request/response action |
| 30 |
# even without `allow_redirects=False`, this test would pass |
| 31 |
# if we find a better way of testing redirect behavior, consider removing this test |
| 32 |
res = client.request("GET", "/bar", allow_redirects=False) |
| 33 |
assert res.http_status == 302 |
| 34 |
|
| 35 |
|
| 36 |
def test_stream_true(client): |
| 37 |
load_response( |
| 38 |
RegisteredResponse( |
| 39 |
path="https://foo.api.globus.org/bar", |
| 40 |
json={"foo": "bar"}, |
| 41 |
) |
| 42 |
) |
| 43 |
res = client.request("GET", "/bar", stream=True) |
| 44 |
assert res.http_status == 200 |
| 45 |
# forcing JSON evaluation still works as expected (this must force the download / |
| 46 |
# evaluation of content) |
| 47 |
assert res["foo"] == "bar" |