diff options
Diffstat (limited to 'tests/test_index.py')
-rw-r--r-- | tests/test_index.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/test_index.py b/tests/test_index.py index 6f9d216dc..c537172aa 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -1,4 +1,6 @@ -from pip.index import package_to_requirement, HTMLPage +from pip.index import package_to_requirement, HTMLPage, get_mirrors, DEFAULT_MIRROR_HOSTNAME +from string import ascii_lowercase +from mock import patch def test_package_name_should_be_converted_to_requirement(): @@ -26,3 +28,28 @@ def test_html_page_should_be_able_to_scrap_rel_links(): assert len(links) == 1 assert links[0].url == 'http://supervisord.org/' +@patch('socket.gethostbyname_ex') +def test_get_mirrors(mock_gethostbyname_ex): + # Test when the expected result comes back + # from socket.gethostbyname_ex + mock_gethostbyname_ex.return_value = ('g.pypi.python.org', [DEFAULT_MIRROR_HOSTNAME], ['129.21.171.98']) + mirrors = get_mirrors() + # Expect [a-g].pypi.python.org, since last mirror + # is returned as g.pypi.python.org + assert len(mirrors) == 7 + for c in "abcdefg": + assert c + ".pypi.python.org" in mirrors + +@patch('socket.gethostbyname_ex') +def test_get_mirrors_no_cname(mock_gethostbyname_ex): + # Test when the UNexpected result comes back + # from socket.gethostbyname_ex + # (seeing this in Japan and was resulting in 216k + # invalid mirrors and a hot CPU) + mock_gethostbyname_ex.return_value = (DEFAULT_MIRROR_HOSTNAME, [DEFAULT_MIRROR_HOSTNAME], ['129.21.171.98']) + mirrors = get_mirrors() + # Falls back to [a-z].pypi.python.org + assert len(mirrors) == 26 + for c in ascii_lowercase: + assert c + ".pypi.python.org" in mirrors + |