summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests/test_upload.py
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2010-07-22 12:50:05 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2010-07-22 12:50:05 (GMT)
commit3679727939a9d25ccfe057e71e8a4b8be73d47ce (patch)
tree88326b8ec80cf57f51d2e093143e233ec4ce1be5 /Lib/distutils/tests/test_upload.py
parent5db0c94072abad10c9d2df99eefd1f51eb84f2bc (diff)
downloadcpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.zip
cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.tar.gz
cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.tar.bz2
reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
Diffstat (limited to 'Lib/distutils/tests/test_upload.py')
-rw-r--r--Lib/distutils/tests/test_upload.py61
1 files changed, 35 insertions, 26 deletions
diff --git a/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py
index 979ab22..35e9700 100644
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/tests/test_upload.py
@@ -2,8 +2,8 @@
import sys
import os
import unittest
+import http.client as httpclient
-from distutils.command import upload as upload_mod
from distutils.command.upload import upload
from distutils.core import Distribution
@@ -38,37 +38,48 @@ index-servers =
[server1]
username:me
"""
+class Response(object):
+ def __init__(self, status=200, reason='OK'):
+ self.status = status
+ self.reason = reason
-class FakeOpen(object):
+class FakeConnection(object):
- def __init__(self, url):
- self.url = url
- if not isinstance(url, str):
- self.req = url
- else:
- self.req = None
- self.msg = 'OK'
+ def __init__(self):
+ self.requests = []
+ self.headers = []
+ self.body = ''
- def getcode(self):
- return 200
+ def __call__(self, netloc):
+ return self
+ def connect(self):
+ pass
+ endheaders = connect
+
+ def putrequest(self, method, url):
+ self.requests.append((method, url))
+
+ def putheader(self, name, value):
+ self.headers.append((name, value))
+
+ def send(self, body):
+ self.body = body
+
+ def getresponse(self):
+ return Response()
class uploadTestCase(PyPIRCCommandTestCase):
def setUp(self):
super(uploadTestCase, self).setUp()
- self.old_open = upload_mod.urlopen
- upload_mod.urlopen = self._urlopen
- self.last_open = None
+ self.old_class = httpclient.HTTPConnection
+ self.conn = httpclient.HTTPConnection = FakeConnection()
def tearDown(self):
- upload_mod.urlopen = self.old_open
+ httpclient.HTTPConnection = self.old_class
super(uploadTestCase, self).tearDown()
- def _urlopen(self, url):
- self.last_open = FakeOpen(url)
- return self.last_open
-
def test_finalize_options(self):
# new format
@@ -113,15 +124,13 @@ class uploadTestCase(PyPIRCCommandTestCase):
cmd.run()
# what did we send ?
- headers = dict(self.last_open.req.headers)
+ headers = dict(self.conn.headers)
self.assertEquals(headers['Content-length'], '2087')
self.assertTrue(headers['Content-type'].startswith('multipart/form-data'))
- self.assertEquals(self.last_open.req.get_method(), 'POST')
- self.assertEquals(self.last_open.req.get_full_url(),
- 'http://pypi.python.org/pypi')
- self.assertTrue(b'xxx' in self.last_open.req.data)
- auth = self.last_open.req.headers['Authorization']
- self.assertFalse('\n' in auth)
+ self.assertFalse('\n' in headers['Authorization'])
+
+ self.assertEquals(self.conn.requests, [('POST', '/pypi')])
+ self.assert_((b'xxx') in self.conn.body)
def test_suite():
return unittest.makeSuite(uploadTestCase)