def test_get_cookies_for_url_ignores_secure_cookies_for_http(): jar = CookieJar() jar.add(URL(b"https://foo.org"), Cookie(b"hello", b"world", secure=True)) cookies = list(jar.get_cookies_for_url(URL(b"http://foo.org/hello-world"))) assert len(cookies) == 0
def test_get_cookies_for_url(): jar = CookieJar() jar.add(URL(b"https://foo.org"), Cookie("hello", "world")) cookies = list(jar.get_cookies_for_url(URL(b"https://foo.org/hello-world"))) assert len(cookies) == 1 assert cookies[0].name == "hello" assert cookies[0].value == "world"
def test_get_cookies_for_url(): jar = CookieJar() jar.add(URL(b'https://foo.org'), Cookie(b'hello', b'world')) cookies = list(jar.get_cookies_for_url( URL(b'https://foo.org/hello-world'))) assert len(cookies) == 1 assert cookies[0].name == b'hello' assert cookies[0].value == b'world'
def test_cookie_jar_does_not_override_http_only_cookie_with_non_http_only_cookie( ): jar = CookieJar() jar.add( URL(b"https://foo.org"), Cookie( b"hello", b"world", expires=datetime_to_cookie_format(datetime.utcnow() + timedelta(days=2)), http_only=True, ), ) jar.add( URL(b"https://foo.org"), Cookie( b"hello", b"world2", expires=datetime_to_cookie_format(datetime.utcnow() + timedelta(days=2)), http_only=True, ), ) cookie = jar.get(b"foo.org", b"/", b"hello") assert cookie is not None assert cookie.cookie.value == b"world2" jar.add( URL(b"https://foo.org"), Cookie( b"hello", b"world modified", expires=datetime_to_cookie_format(datetime.utcnow() + timedelta(days=2)), http_only=False, ), ) cookie = jar.get(b"foo.org", b"/", b"hello") assert cookie is not None assert cookie.cookie.value == b"world2"
def test_cookiejar_invalid_domain(request_url, cookie_domain): jar = CookieJar() cookie = Cookie(b'Name', b'Value', domain=cookie_domain) with pytest.raises(InvalidCookieDomain): jar.add(request_url, cookie)