Skip to content

Commit

Permalink
Add unit test to warn on invalid content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshks committed May 21, 2020
1 parent 1bc7f53 commit fa67244
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,36 @@ def test_get_html_page_invalid_scheme(caplog, url, vcs_scheme):
]


@pytest.mark.parametrize(
"content_type",
[
"application/xhtml+xml",
"application/json",
],
)
def test_get_html_page_invalid_content_type(caplog, content_type):
"""`_get_html_page()` should warn if an invalid content-type is given.
Only text/html is allowed.
"""
caplog.set_level(logging.DEBUG)
url = 'https://pypi.org/simple/pip'
link = Link(url)

session = mock.Mock(PipSession)
session.get.return_value = mock.Mock(**{
"request.method": "GET",
"headers": {"Content-Type": content_type},
})

assert _get_html_page(link, session=session) is None
assert ('pip._internal.index.collector',
logging.WARNING,
'Skipping page {} because the GET request got Content-Type: {}.'
'The supported Content-Type is text/html'.format(
url, content_type)) \
in caplog.record_tuples


def make_fake_html_response(url):
"""
Create a fake requests.Response object.
Expand Down

0 comments on commit fa67244

Please sign in to comment.