* Add repr to Cookies for displaying available cookies
* Add unit test
* Simplify repr
* Remove file
return True
return False
+ def __repr__(self) -> str:
+ cookies_repr = ", ".join(
+ [
+ f"<Cookie {cookie.name}={cookie.value} for {cookie.domain} />"
+ for cookie in self.jar
+ ]
+ )
+
+ return f"<Cookies[{cookies_repr}]>"
+
class _CookieCompatRequest(urllib.request.Request):
"""
Wraps a `Request` instance up in a compatibility interface suitable
assert len(cookies.items()) == 2
for k, v in cookies_val:
assert cookies[k] == v
+
+
+def test_cookies_repr():
+ cookies = httpx.Cookies()
+ cookies.set(name="foo", value="bar", domain="http://blah.com")
+ cookies.set(name="fizz", value="buzz", domain="http://hello.com")
+
+ assert (
+ repr(cookies)
+ == "<Cookies[<Cookie foo=bar for http://blah.com />, <Cookie fizz=buzz for http://hello.com />]>"
+ )