Skip to content

Commit 803d820

Browse files
add testing for uncachable marking
1 parent 08479d4 commit 803d820

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/pip/_internal/index/collector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ def collect_links(self, project_name):
639639
# We want to filter out anything that does not have a secure origin.
640640
url_locations = [
641641
link for link in itertools.chain(
642+
# Mark PyPI indices as "uncacheable" -- this will avoid caching
643+
# the result of parsing the page for links.
642644
(Link(url, uncacheable=True) for url in index_url_loc),
643645
(Link(url) for url in fl_url_loc),
644646
)

tests/unit/test_collector.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,14 @@ def test_fetch_page(self, mock_get_html_response):
576576
fake_response = make_fake_html_response(url)
577577
mock_get_html_response.return_value = fake_response
578578

579-
location = Link(url)
579+
location = Link(url, uncacheable=True)
580580
link_collector = make_test_link_collector()
581581
actual = link_collector.fetch_page(location)
582582

583583
assert actual.content == fake_response.content
584584
assert actual.encoding is None
585585
assert actual.url == url
586+
assert actual.uncacheable_links == location.uncacheable
586587

587588
# Also check that the right session object was passed to
588589
# _get_html_response().
@@ -607,8 +608,12 @@ def test_collect_links(self, caplog, data):
607608

608609
assert len(actual.find_links) == 1
609610
check_links_include(actual.find_links, names=['packages'])
611+
# Check that find-links URLs are not marked as cacheable.
612+
assert not actual.find_links[0].uncacheable
610613

611614
assert actual.project_urls == [Link('https://pypi.org/simple/twine/')]
615+
# Check that index URLs are always marked as uncacheable.
616+
assert actual.project_urls[0].uncacheable
612617

613618
expected_message = dedent("""\
614619
1 location(s) to search for versions of twine:

0 commit comments

Comments
 (0)