Add repr to Cookies for displaying available cookies (#1411)
* Add repr to Cookies for displaying available cookies * Add unit test * Simplify repr * Remove file
This commit is contained in:
parent
9005bd5df6
commit
28cbe77676
@ -1491,6 +1491,16 @@ class Cookies(MutableMapping):
|
||||
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
|
||||
|
||||
@ -85,3 +85,14 @@ def test_cookies_can_be_a_list_of_tuples():
|
||||
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 />]>"
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user