diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2013-11-10 18:50:10 -0500 | 
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-11-10 18:50:10 -0500 | 
| commit | a2ebfd02566d6ec929e75bfadaadd250314d9a20 (patch) | |
| tree | b712c12b97298bddeb3c0960f9f12e2fd4b77d6b /Lib/distutils/tests/test_upload.py | |
| parent | 3492e39b447a8e76df9da1cc05bd1cdf504e74f1 (diff) | |
| download | cpython-git-a2ebfd02566d6ec929e75bfadaadd250314d9a20.tar.gz | |
Issue #19544 and Issue #6286: Restore use of urllib over http allowing use of http_proxy for Distutils upload command, a feature accidentally lost in the rollback of distutils2.
Diffstat (limited to 'Lib/distutils/tests/test_upload.py')
| -rw-r--r-- | Lib/distutils/tests/test_upload.py | 63 | 
1 files changed, 26 insertions, 37 deletions
diff --git a/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py index 4c6464a32e..a474596e33 100644 --- a/Lib/distutils/tests/test_upload.py +++ b/Lib/distutils/tests/test_upload.py @@ -1,9 +1,9 @@  """Tests for distutils.command.upload."""  import os  import unittest -import http.client as httpclient  from test.support import run_unittest +from distutils.command import upload as upload_mod  from distutils.command.upload import upload  from distutils.core import Distribution @@ -37,48 +37,37 @@ index-servers =  [server1]  username:me  """ -class Response(object): -    def __init__(self, status=200, reason='OK'): -        self.status = status -        self.reason = reason -class FakeConnection(object): +class FakeOpen(object): -    def __init__(self): -        self.requests = [] -        self.headers = [] -        self.body = '' +    def __init__(self, url): +        self.url = url +        if not isinstance(url, str): +            self.req = url +        else: +            self.req = None +        self.msg = 'OK' -    def __call__(self, netloc): -        return self +    def getcode(self): +        return 200 -    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_class = httpclient.HTTPConnection -        self.conn = httpclient.HTTPConnection = FakeConnection() +        self.old_open = upload_mod.urlopen +        upload_mod.urlopen = self._urlopen +        self.last_open = None      def tearDown(self): -        httpclient.HTTPConnection = self.old_class +        upload_mod.urlopen = self.old_open          super(uploadTestCase, self).tearDown() +    def _urlopen(self, url): +        self.last_open = FakeOpen(url) +        return self.last_open +      def test_finalize_options(self):          # new format @@ -122,14 +111,14 @@ class uploadTestCase(PyPIRCCommandTestCase):          cmd.ensure_finalized()          cmd.run() -        # what did we send ? -        headers = dict(self.conn.headers) +         # what did we send ? +        headers = dict(self.last_open.req.headers)          self.assertEqual(headers['Content-length'], '2087') -        self.assertTrue(headers['Content-type'].startswith('multipart/form-data')) -        self.assertFalse('\n' in headers['Authorization']) - -        self.assertEqual(self.conn.requests, [('POST', '/pypi')]) -        self.assertTrue((b'xxx') in self.conn.body) +        self.assert_(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.assert_(b'xxx' in self.last_open.req.data)  def test_suite():      return unittest.makeSuite(uploadTestCase)  | 
