aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Combelles <ccomb@free.fr>2010-05-19 21:54:20 +0200
committerChristophe Combelles <ccomb@free.fr>2010-05-19 21:54:20 +0200
commit29ffeae7d36c6e6c2a10dd230f8472226f51d955 (patch)
tree9e0497969d1184297fb6c5b6f2bdaa9396b8a98d
parent17502a06524accaf75c09baa817592bd0d38e75b (diff)
downloadexternal_python_setuptools-29ffeae7d36c6e6c2a10dd230f8472226f51d955.tar.gz
external_python_setuptools-29ffeae7d36c6e6c2a10dd230f8472226f51d955.tar.bz2
external_python_setuptools-29ffeae7d36c6e6c2a10dd230f8472226f51d955.zip
set-up infrastructure to write tests with a real http server, and reproduced issue 163.
--HG-- branch : distribute extra : rebase_source : dc3a9fb1663500c66febacbc2ede43eaa96c190e
-rw-r--r--.hgignore1
-rw-r--r--setuptools/tests/indexes/test_links_priority/external.html3
-rw-r--r--setuptools/tests/indexes/test_links_priority/simple/foobar/index.html4
-rw-r--r--setuptools/tests/server.py39
-rw-r--r--setuptools/tests/test_packageindex.py38
5 files changed, 85 insertions, 0 deletions
diff --git a/.hgignore b/.hgignore
index 3ccf2a3a..21ec620a 100644
--- a/.hgignore
+++ b/.hgignore
@@ -10,3 +10,4 @@ lib
bin
include
\.Python
+*.swp
diff --git a/setuptools/tests/indexes/test_links_priority/external.html b/setuptools/tests/indexes/test_links_priority/external.html
new file mode 100644
index 00000000..883e9790
--- /dev/null
+++ b/setuptools/tests/indexes/test_links_priority/external.html
@@ -0,0 +1,3 @@
+<html><body>
+<a href="foobar-0.1.tar.gz#md5=bad_md5">bad old link</a>
+</body></html>
diff --git a/setuptools/tests/indexes/test_links_priority/simple/foobar/index.html b/setuptools/tests/indexes/test_links_priority/simple/foobar/index.html
new file mode 100644
index 00000000..dc6273d1
--- /dev/null
+++ b/setuptools/tests/indexes/test_links_priority/simple/foobar/index.html
@@ -0,0 +1,4 @@
+<html><body>
+<a href="foobar-0.1.tar.gz#md5=correct_md5">foobar-0.1.tar.gz</a><br/>
+<a href="../../external.html" rel="homepage">external homepage</a><br/>
+</body></html>
diff --git a/setuptools/tests/server.py b/setuptools/tests/server.py
new file mode 100644
index 00000000..00f4e07c
--- /dev/null
+++ b/setuptools/tests/server.py
@@ -0,0 +1,39 @@
+"""Basic http server for tests to simulate PyPI or custom indexes
+"""
+import urllib2
+from threading import Thread
+from BaseHTTPServer import HTTPServer
+from SimpleHTTPServer import SimpleHTTPRequestHandler
+
+class IndexServer(HTTPServer):
+ """Basic single-threaded http server simulating a package index
+
+ You can use this server in unittest like this::
+ s = IndexServer()
+ s.start()
+ index_url = s.base_url() + 'mytestindex'
+ # do some test requests to the index
+ s.stop()
+ """
+ def __init__(self):
+ HTTPServer.__init__(self, ('', 0), SimpleHTTPRequestHandler)
+ self._run = True
+
+ def serve(self):
+ while True:
+ self.handle_request()
+ if not self._run: break
+
+ def start(self):
+ self.thread = Thread(target=self.serve)
+ self.thread.start()
+
+ def stop(self):
+ """self.shutdown is not supported on python < 2.6"""
+ self._run = False
+ urllib2.urlopen('http://127.0.0.1:%s/' % self.server_address[1])
+ self.thread.join()
+
+ def base_url(self):
+ port = self.server_address[1]
+ return 'http://127.0.0.1:%s/setuptools/tests/indexes/' % port
diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py
index 8ae7a5b9..5c1c6970 100644
--- a/setuptools/tests/test_packageindex.py
+++ b/setuptools/tests/test_packageindex.py
@@ -5,6 +5,7 @@ import sys
import os, shutil, tempfile, unittest, urllib2
import pkg_resources
import setuptools.package_index
+from server import IndexServer
class TestPackageIndex(unittest.TestCase):
@@ -74,3 +75,40 @@ class TestPackageIndex(unittest.TestCase):
url = 'file:///tmp/test_package_index'
self.assert_(index.url_ok(url, True))
+ def test_links_priority(self):
+ """
+ Download links from the pypi simple index should be used before
+ external download links.
+ http://bitbucket.org/tarek/distribute/issue/163/md5-validation-error
+
+ Usecase :
+ - someone uploads a package on pypi, a md5 is generated
+ - someone manually copies this link (with the md5 in the url) onto an
+ external page accessible from the package page.
+ - someone reuploads the package (with a different md5)
+ - while easy_installing, an MD5 error occurs because the external link
+ is used
+ -> Distribute should use the link from pypi, not the external one.
+ """
+ # start an index server
+ server = IndexServer()
+ server.start()
+ index_url = server.base_url() + 'test_links_priority/simple/'
+
+ # scan a test index
+ pi = setuptools.package_index.PackageIndex(index_url)
+ requirement = pkg_resources.Requirement.parse('foobar')
+ pi.find_packages(requirement)
+ server.stop()
+
+ # the distribution has been found
+ self.assert_('foobar' in pi)
+ # we have two links
+ self.assert_(len(pi['foobar'])==2)
+ # the first link should be from the index
+ self.assert_('correct_md5' in pi['foobar'][0].location)
+ # the second link should be the external one
+ self.assert_('bad_md5' in pi['foobar'][1].location)
+
+
+