test_cookies.py
This file
Path
tests/client/test_cookies.py
146 lines · 4.3 KiB · Python
Last changed by
Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941
History of this fileTake it
The walk stopped after 200 commits: lines older than 225f1e2 point at it.
Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 1–2why, one step back1from http.cookiejar import Cookie, CookieJar2Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 3why, one step back3import httpxRefactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 4why, one step back4from tests.utils import MockTransportUse URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 5–6why, one step back56Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 7–9why, one step back7def get_and_set_cookies(request: httpx.Request) -> httpx.Response:8 if request.url.path == "/echo_cookies":9 data = {"cookies": request.headers.get("cookie")}Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941
line 10why, one step back10 return httpx.Response(200, json=data)Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 11–14why, one step back11 elif request.url.path == "/set_cookie":12 return httpx.Response(200, headers={"set-cookie": "example-name=example-value"})13 else:14 raise NotImplementedError() # pragma: no coverUse URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 15–16why, one step back1516Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 17why, one step back17def test_set_cookie() -> None:Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 18–23why, one step back18 """19 Send a request including a cookie.20 """21 url = "http://example.org/echo_cookies"22 cookies = {"example-name": "example-value"}23Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 24why, one step back24 client = httpx.Client(transport=MockTransport(get_and_set_cookies))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 25why, one step back25 response = client.get(url, cookies=cookies)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 26–30why, one step back2627 assert response.status_code == 20028 assert response.json() == {"cookies": "example-name=example-value"}2930Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 31why, one step back31def test_set_cookie_with_cookiejar() -> None:Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 32–58why, one step back32 """33 Send a request including a cookie, using a `CookieJar` instance.34 """3536 url = "http://example.org/echo_cookies"37 cookies = CookieJar()38 cookie = Cookie(39 version=0,40 name="example-name",41 value="example-value",42 port=None,43 port_specified=False,44 domain="",45 domain_specified=False,46 domain_initial_dot=False,47 path="/",48 path_specified=True,49 secure=False,50 expires=None,51 discard=True,52 comment=None,53 comment_url=None,54 rest={"HttpOnly": ""},55 rfc2109=False,56 )57 cookies.set_cookie(cookie)58Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 59why, one step back59 client = httpx.Client(transport=MockTransport(get_and_set_cookies))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 60why, one step back60 response = client.get(url, cookies=cookies)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 61–65why, one step back6162 assert response.status_code == 20063 assert response.json() == {"cookies": "example-name=example-value"}6465Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 66why, one step back66def test_setting_client_cookies_to_cookiejar() -> None:Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 67–93why, one step back67 """68 Send a request including a cookie, using a `CookieJar` instance.69 """7071 url = "http://example.org/echo_cookies"72 cookies = CookieJar()73 cookie = Cookie(74 version=0,75 name="example-name",76 value="example-value",77 port=None,78 port_specified=False,79 domain="",80 domain_specified=False,81 domain_initial_dot=False,82 path="/",83 path_specified=True,84 secure=False,85 expires=None,86 discard=True,87 comment=None,88 comment_url=None,89 rest={"HttpOnly": ""},90 rfc2109=False,91 )92 cookies.set_cookie(cookie)93Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 94why, one step back94 client = httpx.Client(transport=MockTransport(get_and_set_cookies))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 95why, one step back95 client.cookies = cookies # type: ignoreBetter test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 96why, one step back96 response = client.get(url)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 97–101why, one step back9798 assert response.status_code == 20099 assert response.json() == {"cookies": "example-name=example-value"}100101Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 102why, one step back102def test_set_cookie_with_cookies_model() -> None:Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 103–107why, one step back103 """104 Send a request including a cookie, using a `Cookies` instance.105 """106107 url = "http://example.org/echo_cookies"Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 108why, one step back108 cookies = httpx.Cookies()Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 109–110why, one step back109 cookies["example-name"] = "example-value"110Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 111why, one step back111 client = httpx.Client(transport=MockTransport(get_and_set_cookies))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 112why, one step back112 response = client.get(url, cookies=cookies)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 113–117why, one step back113114 assert response.status_code == 200115 assert response.json() == {"cookies": "example-name=example-value"}116117Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 118why, one step back118def test_get_cookie() -> None:Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 119–120why, one step back119 url = "http://example.org/set_cookie"120Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 121why, one step back121 client = httpx.Client(transport=MockTransport(get_and_set_cookies))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 122why, one step back122 response = client.get(url)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 123–128why, one step back123124 assert response.status_code == 200125 assert response.cookies["example-name"] == "example-value"126 assert client.cookies["example-name"] == "example-value"127128Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 129why, one step back129def test_cookie_persistence() -> None:Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 130–132why, one step back130 """131 Ensure that Client instances persist cookies between requests.132 """Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 133why, one step back133 client = httpx.Client(transport=MockTransport(get_and_set_cookies))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 134why, one step back134Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 135why, one step back135 response = client.get("http://example.org/echo_cookies")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 136–138why, one step back136 assert response.status_code == 200137 assert response.json() == {"cookies": None}138Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 139why, one step back139 response = client.get("http://example.org/set_cookie")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 140–143why, one step back140 assert response.status_code == 200141 assert response.cookies["example-name"] == "example-value"142 assert client.cookies["example-name"] == "example-value"143Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 144why, one step back144 response = client.get("http://example.org/echo_cookies")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 145–146why, one step back145 assert response.status_code == 200146 assert response.json() == {"cookies": "example-name=example-value"}