Skip to content

Commit

Permalink
add testing for uncachable marking
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Mar 20, 2020
1 parent 08479d4 commit 803d820
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/pip/_internal/index/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,8 @@ def collect_links(self, project_name):
# We want to filter out anything that does not have a secure origin.
url_locations = [
link for link in itertools.chain(
# Mark PyPI indices as "uncacheable" -- this will avoid caching
# the result of parsing the page for links.
(Link(url, uncacheable=True) for url in index_url_loc),
(Link(url) for url in fl_url_loc),
)
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,14 @@ def test_fetch_page(self, mock_get_html_response):
fake_response = make_fake_html_response(url)
mock_get_html_response.return_value = fake_response

location = Link(url)
location = Link(url, uncacheable=True)
link_collector = make_test_link_collector()
actual = link_collector.fetch_page(location)

assert actual.content == fake_response.content
assert actual.encoding is None
assert actual.url == url
assert actual.uncacheable_links == location.uncacheable

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

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

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

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

0 comments on commit 803d820

Please sign in to comment.