summaryrefslogtreecommitdiff
path: root/tests/test_index.py
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2012-09-01 16:19:19 +0200
committerJannis Leidel <jannis@leidel.info>2012-09-01 16:19:19 +0200
commit235e1dea02abd3a89ab53ea8035fd4ee8a37887b (patch)
tree5e7b2c5a853aefed870863bed9da6722100e2420 /tests/test_index.py
parent6083597ebebd05d28b57d53c6077bfa7c3b168f8 (diff)
parentb183a327412e83ac24a9c9d28a6bedd94bb69d7b (diff)
downloadpip-threaded-page-getting.tar.gz
Merge branch 'develop' into threaded-page-gettingthreaded-page-getting
Diffstat (limited to 'tests/test_index.py')
-rw-r--r--tests/test_index.py29
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
+