File: test_advanced_http_options.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (47 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from globus_sdk.testing import RegisteredResponse, load_response


def test_allow_redirects_false(client):
    # based on a real response from 'GET https://auth.globus.org/'
    load_response(
        RegisteredResponse(
            path="https://foo.api.globus.org/bar",
            status=302,
            headers={
                "Date": "Fri, 15 Apr 2022 15:35:44 GMT",
                "Content-Type": "text/html",
                "Connection": "keep-alive",
                "Server": "nginx",
                "Location": "https://www.globus.org/",
            },
            body="""\
<html>
<head><title>302 Found</title></head>
<body>
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
""",
        )
    )
    # NOTE: this test isn't very "real" because of where `responses` intercepts the
    # request/response action
    # even without `allow_redirects=False`, this test would pass
    # if we find a better way of testing redirect behavior, consider removing this test
    res = client.request("GET", "/bar", allow_redirects=False)
    assert res.http_status == 302


def test_stream_true(client):
    load_response(
        RegisteredResponse(
            path="https://foo.api.globus.org/bar",
            json={"foo": "bar"},
        )
    )
    res = client.request("GET", "/bar", stream=True)
    assert res.http_status == 200
    # forcing JSON evaluation still works as expected (this must force the download /
    # evaluation of content)
    assert res["foo"] == "bar"