test_cookies.py
This file
Path
tests/client/test_cookies.py
164 lines · 4.8 KiB · Python
Last changed by
Dispatcher -> AsyncDispatcher (#725)Tom Christiebefore adoptione19bd9b
History of this fileTake it
The walk stopped after 200 commits: lines older than b574230 point at it.
Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 1–3why, one step back1import json2from http.cookiejar import Cookie, CookieJar3Drop sync (#544)Tom Christiebefore adoption206c537
lines 4–5why, one step back4import pytest5Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 6why, one step back6from httpx import AsyncClient, Cookies, Request, ResponseTighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 7why, one step back7from httpx.config import CertTypes, TimeoutTypes, VerifyTypesDispatcher -> AsyncDispatcher (#725)Tom Christiebefore adoptione19bd9b
line 8why, one step back8from httpx.dispatch.base import AsyncDispatcherRemove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 9–10why, one step back910Dispatcher -> AsyncDispatcher (#725)Tom Christiebefore adoptione19bd9b
line 11why, one step back11class MockDispatch(AsyncDispatcher):Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 12–13why, one step back12 async def send(13 self,Drop sync (#544)Tom Christiebefore adoption206c537
line 14why, one step back14 request: Request,Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 15–17why, one step back15 verify: VerifyTypes = None,16 cert: CertTypes = None,17 timeout: TimeoutTypes = None,Drop sync (#544)Tom Christiebefore adoption206c537
line 18why, one step back18 ) -> Response:Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 19–20why, one step back19 if request.url.path.startswith("/echo_cookies"):20 body = json.dumps({"cookies": request.headers.get("Cookie")}).encode()Drop sync (#544)Tom Christiebefore adoption206c537
line 21why, one step back21 return Response(200, content=body, request=request)Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 22–23why, one step back22 elif request.url.path.startswith("/set_cookie"):23 headers = {"set-cookie": "example-name=example-value"}Drop sync (#544)Tom Christiebefore adoption206c537
line 24why, one step back24 return Response(200, headers=headers, request=request)Type-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
lines 25–26why, one step back25 else:26 raise NotImplementedError # pragma: no coverRemove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 27–28why, one step back2728Drop sync (#544)Tom Christiebefore adoption206c537
line 29why, one step back29@pytest.mark.asyncioType-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 30why, one step back30async def test_set_cookie() -> None:Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 31–36why, one step back31 """32 Send a request including a cookie.33 """34 url = "http://example.org/echo_cookies"35 cookies = {"example-name": "example-value"}36Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 37why, one step back37 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 38why, one step back38 response = await client.get(url, cookies=cookies)Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 39–43why, one step back3940 assert response.status_code == 20041 assert response.json() == {"cookies": "example-name=example-value"}4243Drop sync (#544)Tom Christiebefore adoption206c537
line 44why, one step back44@pytest.mark.asyncioType-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 45why, one step back45async def test_set_cookie_with_cookiejar() -> None:Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 46–67why, one step back46 """47 Send a request including a cookie, using a `CookieJar` instance.48 """4950 url = "http://example.org/echo_cookies"51 cookies = CookieJar()52 cookie = Cookie(53 version=0,54 name="example-name",55 value="example-value",56 port=None,57 port_specified=False,58 domain="",59 domain_specified=False,60 domain_initial_dot=False,61 path="/",62 path_specified=True,63 secure=False,64 expires=None,65 discard=True,66 comment=None,67 comment_url=None,Type-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 68why, one step back68 rest={"HttpOnly": ""},Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 69–72why, one step back69 rfc2109=False,70 )71 cookies.set_cookie(cookie)72Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 73why, one step back73 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 74why, one step back74 response = await client.get(url, cookies=cookies)Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 75–79why, one step back7576 assert response.status_code == 20077 assert response.json() == {"cookies": "example-name=example-value"}7879Drop sync (#544)Tom Christiebefore adoption206c537
line 80why, one step back80@pytest.mark.asyncioType-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 81why, one step back81async def test_setting_client_cookies_to_cookiejar() -> None:Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 82–103why, one step back82 """83 Send a request including a cookie, using a `CookieJar` instance.84 """8586 url = "http://example.org/echo_cookies"87 cookies = CookieJar()88 cookie = Cookie(89 version=0,90 name="example-name",91 value="example-value",92 port=None,93 port_specified=False,94 domain="",95 domain_specified=False,96 domain_initial_dot=False,97 path="/",98 path_specified=True,99 secure=False,100 expires=None,101 discard=True,102 comment=None,103 comment_url=None,Type-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 104why, one step back104 rest={"HttpOnly": ""},Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 105–108why, one step back105 rfc2109=False,106 )107 cookies.set_cookie(cookie)108Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 109why, one step back109 client = AsyncClient(dispatch=MockDispatch())Type-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 110why, one step back110 client.cookies = cookies # type: ignoreDrop sync (#544)Tom Christiebefore adoption206c537
line 111why, one step back111 response = await client.get(url)Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 112–116why, one step back112113 assert response.status_code == 200114 assert response.json() == {"cookies": "example-name=example-value"}115116Drop sync (#544)Tom Christiebefore adoption206c537
line 117why, one step back117@pytest.mark.asyncioType-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 118why, one step back118async def test_set_cookie_with_cookies_model() -> None:Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 119–126why, one step back119 """120 Send a request including a cookie, using a `Cookies` instance.121 """122123 url = "http://example.org/echo_cookies"124 cookies = Cookies()125 cookies["example-name"] = "example-value"126Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 127why, one step back127 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 128why, one step back128 response = await client.get(url, cookies=cookies)Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 129–133why, one step back129130 assert response.status_code == 200131 assert response.json() == {"cookies": "example-name=example-value"}132133Drop sync (#544)Tom Christiebefore adoption206c537
line 134why, one step back134@pytest.mark.asyncioType-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 135why, one step back135async def test_get_cookie() -> None:Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 136–137why, one step back136 url = "http://example.org/set_cookie"137Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 138why, one step back138 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 139why, one step back139 response = await client.get(url)Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 140–145why, one step back140141 assert response.status_code == 200142 assert response.cookies["example-name"] == "example-value"143 assert client.cookies["example-name"] == "example-value"144145Drop sync (#544)Tom Christiebefore adoption206c537
line 146why, one step back146@pytest.mark.asyncioType-check test_cookies.py (#677)Florimond Mancabefore adoption0ee0005
line 147why, one step back147async def test_cookie_persistence() -> None:Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
lines 148–150why, one step back148 """149 Ensure that Client instances persist cookies between requests.150 """Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 151why, one step back151 client = AsyncClient(dispatch=MockDispatch())Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
line 152why, one step back152Drop sync (#544)Tom Christiebefore adoption206c537
lines 153–155why, one step back153 response = await client.get("http://example.org/echo_cookies")154 assert response.status_code == 200155 assert response.json() == {"cookies": None}Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)Seth Michael Larsonbefore adoptionb574230
line 156why, one step back156Drop sync (#544)Tom Christiebefore adoption206c537
lines 157–164why, one step back157 response = await client.get("http://example.org/set_cookie")158 assert response.status_code == 200159 assert response.cookies["example-name"] == "example-value"160 assert client.cookies["example-name"] == "example-value"161162 response = await client.get("http://example.org/echo_cookies")163 assert response.status_code == 200164 assert response.json() == {"cookies": "example-name=example-value"}