forked from brainsik/virtualenv-burrito
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_download.py
49 lines (39 loc) · 1.39 KB
/
test_download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# encoding: utf-8
import os
import urllib2
import csv
import hashlib
from nose.tools import eq_
PYPI_MD5_URL = 'http://pypi.python.org/pypi?:action=show_md5&digest='
PYPI_DOWNLOADS = {
# filename: md5sum
'distribute-0.6.49.tar.gz': '89e68df89faf1966bcbd99a0033fbf8e',
'pip-1.4.1.tar.gz': '6afbb46aeb48abac658d4df742bff714',
'virtualenv-1.10.1.tar.gz': '3a04aa2b32c76c83725ed4d9918e362e',
'virtualenvwrapper-4.1.1.tar.gz': 'f18f2c612b936583a8ec0f7114b6637e',
}
def test_tarball_names():
tarballs = set()
with open('versions.csv', 'r') as fo:
reader = csv.reader(fo)
for name, version, url, digest in reader:
if name.startswith('_'):
continue
tarballs.add(os.path.basename(url))
eq_(tarballs, set(PYPI_DOWNLOADS.keys()))
def test_shasum():
with open('versions.csv', 'r') as fo:
reader = csv.reader(fo)
for name, version, url, digest in reader:
if name.startswith('_'):
continue
sha1 = hashlib.sha1()
sha1.update(urllib2.urlopen(url).read())
eq_(digest, sha1.hexdigest())
def test_md5_url_exists():
for ball, md5sum in PYPI_DOWNLOADS.iteritems():
url = PYPI_MD5_URL + md5sum
try:
urllib2.urlopen(url)
except urllib2.HTTPError as e:
assert False, "Failed to open %s: %s %s" % (url, type(e), e)