test parse_header_links via public api (#3061)

* test `parse_header_links` via public api

* add no-link test

* Update tests/test_utils.py

---------

Co-authored-by: Tom Christie <tom@tomchristie.com>
This commit is contained in:
T-256 2024-01-16 13:55:02 +03:30 committed by GitHub
parent c7cd6aa5bd
commit 4f6edf36e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -774,13 +774,13 @@ class Response:
Returns the parsed header links of the response, if any
"""
header = self.headers.get("link")
ldict = {}
if header:
links = parse_header_links(header)
for link in links:
key = link.get("rel") or link.get("url")
ldict[key] = link
return ldict
if header is None:
return {}
return {
(link.get("rel") or link.get("url")): link
for link in parse_header_links(header)
}
@property
def num_bytes_downloaded(self) -> int:

View File

@ -12,7 +12,6 @@ from httpx._utils import (
get_ca_bundle_from_env,
get_environment_proxies,
is_https_redirect,
parse_header_links,
same_origin,
)
@ -80,7 +79,13 @@ def test_guess_by_bom(encoding, expected):
),
)
def test_parse_header_links(value, expected):
assert parse_header_links(value) == expected
all_links = httpx.Response(200, headers={"link": value}).links.values()
assert all(link in all_links for link in expected)
def test_parse_header_links_no_link():
all_links = httpx.Response(200).links
assert all_links == {}
def test_logging_request(server, caplog):