Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/tests/test_upload.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | cb0969071f2a |
| children | 4373f0e4eb21 |
| rev | line source |
|---|---|
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1 """Tests for distutils.command.upload.""" |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
2 import sys |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
3 import os |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
4 import unittest |
|
52585
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
5 import httplib |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
6 |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
7 from distutils.command.upload import upload |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
8 from distutils.core import Distribution |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
9 |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
10 from distutils.tests import support |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
11 from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
12 |
|
50639
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
13 PYPIRC_NOPASSWORD = """\ |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
14 [distutils] |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
15 |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
16 index-servers = |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
17 server1 |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
18 |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
19 [server1] |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
20 username:me |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
21 """ |
|
52585
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
22 class Response(object): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
23 def __init__(self, status=200, reason='OK'): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
24 self.status = status |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
25 self.reason = reason |
|
50639
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
26 |
|
52585
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
27 class FakeConnection(object): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
28 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
29 def __init__(self): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
30 self.requests = [] |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
31 self.headers = [] |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
32 self.body = '' |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
33 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
34 def __call__(self, netloc): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
35 return self |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
36 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
37 def connect(self): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
38 pass |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
39 endheaders = connect |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
40 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
41 def putrequest(self, method, url): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
42 self.requests.append((method, url)) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
43 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
44 def putheader(self, name, value): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
45 self.headers.append((name, value)) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
46 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
47 def send(self, body): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
48 self.body = body |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
49 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
50 def getresponse(self): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
51 return Response() |
|
50639
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
52 |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
53 class uploadTestCase(PyPIRCCommandTestCase): |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
54 |
|
52585
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
55 def setUp(self): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
56 super(uploadTestCase, self).setUp() |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
57 self.old_class = httplib.HTTPConnection |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
58 self.conn = httplib.HTTPConnection = FakeConnection() |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
59 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
60 def tearDown(self): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
61 httplib.HTTPConnection = self.old_class |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
62 super(uploadTestCase, self).tearDown() |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
63 |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
64 def test_finalize_options(self): |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
65 |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
66 # new format |
|
52585
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
67 self.write_file(self.rc, PYPIRC) |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
68 dist = Distribution() |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
69 cmd = upload(dist) |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
70 cmd.finalize_options() |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
71 for attr, waited in (('username', 'me'), ('password', 'secret'), |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
72 ('realm', 'pypi'), |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
73 ('repository', 'http://pypi.python.org/pypi')): |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
74 self.assertEquals(getattr(cmd, attr), waited) |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
75 |
|
50639
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
76 def test_saved_password(self): |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
77 # file with no password |
|
52585
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
78 self.write_file(self.rc, PYPIRC_NOPASSWORD) |
|
50639
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
79 |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
80 # make sure it passes |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
81 dist = Distribution() |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
82 cmd = upload(dist) |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
83 cmd.finalize_options() |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
84 self.assertEquals(cmd.password, None) |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
85 |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
86 # make sure we get it as well, if another command |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
87 # initialized it at the dist level |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
88 dist.password = 'xxx' |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
89 cmd = upload(dist) |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
90 cmd.finalize_options() |
|
589f6844d8e0
Merged revisions 68415 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
91 self.assertEquals(cmd.password, 'xxx') |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
92 |
|
52585
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
93 def test_upload(self): |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
94 tmp = self.mkdtemp() |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
95 path = os.path.join(tmp, 'xxx') |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
96 self.write_file(path) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
97 command, pyversion, filename = 'xxx', '2.6', path |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
98 dist_files = [(command, pyversion, filename)] |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
99 self.write_file(self.rc, PYPIRC) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
100 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
101 # lets run it |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
102 pkg_dir, dist = self.create_dist(dist_files=dist_files) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
103 cmd = upload(dist) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
104 cmd.ensure_finalized() |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
105 cmd.run() |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
106 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
107 # what did we send ? |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
108 headers = dict(self.conn.headers) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
109 self.assertEquals(headers['Content-length'], '2086') |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
110 self.assert_(headers['Content-type'].startswith('multipart/form-data')) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
111 |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
112 self.assertEquals(self.conn.requests, [('POST', '/pypi')]) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
113 self.assert_('xxx' in self.conn.body) |
|
cb0969071f2a
more tests for the upload command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
50639
diff
changeset
|
114 |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
115 def test_suite(): |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
116 return unittest.makeSuite(uploadTestCase) |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
117 |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
118 if __name__ == "__main__": |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
119 unittest.main(defaultTest="test_suite") |
