1+ import http
2+
13import pytest
24
3- from httpx import CookieConflict , Cookies
5+ import httpx
46
57
68def test_cookies ():
7- cookies = Cookies ({"name" : "value" })
9+ cookies = httpx . Cookies ({"name" : "value" })
810 assert cookies ["name" ] == "value"
911 assert "name" in cookies
1012 assert len (cookies ) == 1
@@ -19,8 +21,8 @@ def test_cookies():
1921
2022
2123def test_cookies_update ():
22- cookies = Cookies ()
23- more_cookies = Cookies ()
24+ cookies = httpx . Cookies ()
25+ more_cookies = httpx . Cookies ()
2426 more_cookies .set ("name" , "value" , domain = "example.com" )
2527
2628 cookies .update (more_cookies )
@@ -29,22 +31,47 @@ def test_cookies_update():
2931
3032
3133def test_cookies_with_domain ():
32- cookies = Cookies ()
34+ cookies = httpx . Cookies ()
3335 cookies .set ("name" , "value" , domain = "example.com" )
3436 cookies .set ("name" , "value" , domain = "example.org" )
3537
36- with pytest .raises (CookieConflict ):
38+ with pytest .raises (httpx . CookieConflict ):
3739 cookies ["name" ]
3840
3941 cookies .clear (domain = "example.com" )
4042 assert len (cookies ) == 1
4143
4244
4345def test_cookies_with_domain_and_path ():
44- cookies = Cookies ()
46+ cookies = httpx . Cookies ()
4547 cookies .set ("name" , "value" , domain = "example.com" , path = "/subpath/1" )
4648 cookies .set ("name" , "value" , domain = "example.com" , path = "/subpath/2" )
4749 cookies .clear (domain = "example.com" , path = "/subpath/1" )
4850 assert len (cookies ) == 1
4951 cookies .delete ("name" , domain = "example.com" , path = "/subpath/2" )
5052 assert len (cookies ) == 0
53+
54+
55+ def test_multiple_set_cookie ():
56+ jar = http .cookiejar .CookieJar ()
57+ headers = [
58+ (
59+ b"Set-Cookie" ,
60+ b"1P_JAR=2020-08-09-18; expires=Tue, 08-Sep-2020 18:33:35 GMT; "
61+ b"path=/; domain=.example.org; Secure" ,
62+ ),
63+ (
64+ b"Set-Cookie" ,
65+ b"NID=204=KWdXOuypc86YvRfBSiWoW1dEXfSl_5qI7sxZY4umlk4J35yNTeNEkw15"
66+ b"MRaujK6uYCwkrtjihTTXZPp285z_xDOUzrdHt4dj0Z5C0VOpbvdLwRdHatHAzQs7"
67+ b"7TsaiWY78a3qU9r7KP_RbSLvLl2hlhnWFR2Hp5nWKPsAcOhQgSg; expires=Mon, "
68+ b"08-Feb-2021 18:33:35 GMT; path=/; domain=.example.org; HttpOnly" ,
69+ ),
70+ ]
71+ request = httpx .Request ("GET" , "https://www.example.org" )
72+ response = httpx .Response (200 , request = request , headers = headers )
73+
74+ cookies = httpx .Cookies (jar )
75+ cookies .extract_cookies (response )
76+
77+ assert len (cookies ) == 2
0 commit comments