Skip to content
Myr

test `parse_header_links` via public api (#3061)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* test `parse_header_links` via public api * add no-link test * Update tests/test_utils.py ---------

authored by T-256 · committed by GitHub · parent c7cd6aa · Browse files · 2 files+14 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

2 files+14 added−9 removed

  • tests:+7 added−2 removed
  • other:+7 added−7 removed

2 files+14 added−9 removed

modified:httpx/_models.py+7 added-7 removed
772 unmodified lines
773 """774 Returns the parsed header links of the response, if any775 """776 header = self.headers.get("link")777 ldict = {}778 if header:779 links = parse_header_links(header)780 for link in links:781 key = link.get("rel") or link.get("url")782 ldict[key] = link783 return ldict777 if header is None:778 return {}779780 return {781 (link.get("rel") or link.get("url")): link782 for link in parse_header_links(header)783 }784785 @property786 def num_bytes_downloaded(self) -> int:787 return self._num_bytes_downloaded788
427 unmodified lines
modified:tests/test_utils.py+7 added-2 removed
10 unmodified lines
11 URLPattern,12 get_ca_bundle_from_env,13 get_environment_proxies,14 is_https_redirect,15 parse_header_links,15 same_origin,16)1718from .common import TESTS_DIR
59 unmodified lines
78 ("", []),79 ),80)81def test_parse_header_links(value, expected):83 assert parse_header_links(value) == expected82 all_links = httpx.Response(200, headers={"link": value}).links.values()83 assert all(link in all_links for link in expected)848586def test_parse_header_links_no_link():87 all_links = httpx.Response(200).links88 assert all_links == {}899091def test_logging_request(server, caplog):92 caplog.set_level(logging.INFO)93 with httpx.Client() as client:94 response = client.get(server.url)
198 unmodified lines