Add unit test to warn on invalid content-type

This commit is contained in:
Devesh Kumar Singh 2020-04-19 15:38:37 +05:30
parent 1bc7f535ca
commit fa67244d45
1 changed files with 30 additions and 0 deletions

View File

@ -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.