~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-05 04:30:07 UTC
  • mfrom: (4932 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4934.
  • Revision ID: john@arbash-meinel.com-20100105043007-ehgbldqd3q0gtyws
Merge bzr.dev, resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    deprecated_in,
49
49
    )
50
50
from bzrlib.tests import (
 
51
    features,
51
52
    http_server,
52
53
    http_utils,
53
54
    )
61
62
    )
62
63
 
63
64
 
64
 
try:
 
65
if features.pycurl.available():
65
66
    from bzrlib.transport.http._pycurl import PyCurlTransport
66
 
    pycurl_present = True
67
 
except errors.DependencyNotPresent:
68
 
    pycurl_present = False
69
67
 
70
68
 
71
69
def load_tests(standard_tests, module, loader):
84
82
                        _server=http_server.HttpServer_urllib,
85
83
                        _qualified_prefix='http+urllib',)),
86
84
        ]
87
 
    if pycurl_present:
 
85
    if features.pycurl.available():
88
86
        transport_scenarios.append(
89
87
            ('pycurl', dict(_transport=PyCurlTransport,
90
88
                            _server=http_server.HttpServer_PyCurl,
156
154
        activity_scenarios.append(
157
155
            ('urllib,https', dict(_activity_server=ActivityHTTPSServer,
158
156
                                  _transport=_urllib.HttpTransport_urllib,)),)
159
 
    if pycurl_present:
 
157
    if features.pycurl.available():
160
158
        activity_scenarios.append(
161
159
            ('pycurl,http', dict(_activity_server=ActivityHTTPServer,
162
160
                                 _transport=PyCurlTransport,)),)
376
374
    """Test case to inherit from if pycurl is present"""
377
375
 
378
376
    def _get_pycurl_maybe(self):
379
 
        try:
380
 
            from bzrlib.transport.http._pycurl import PyCurlTransport
381
 
            return PyCurlTransport
382
 
        except errors.DependencyNotPresent:
383
 
            raise tests.TestSkipped('pycurl not present')
 
377
        self.requireFeature(features.pycurl)
 
378
        return PyCurlTransport
384
379
 
385
380
    _transport = property(_get_pycurl_maybe)
386
381
 
453
448
        https by supplying a fake version_info that do not
454
449
        support it.
455
450
        """
456
 
        try:
457
 
            import pycurl
458
 
        except ImportError:
459
 
            raise tests.TestSkipped('pycurl not present')
 
451
        self.requireFeature(features.pycurl)
 
452
        # Import the module locally now that we now it's available.
 
453
        pycurl = features.pycurl.module
460
454
 
461
455
        version_info_orig = pycurl.version_info
462
 
        try:
463
 
            # Now that we have pycurl imported, we can fake its version_info
464
 
            # This was taken from a windows pycurl without SSL
465
 
            # (thanks to bialix)
466
 
            pycurl.version_info = lambda : (2,
467
 
                                            '7.13.2',
468
 
                                            462082,
469
 
                                            'i386-pc-win32',
470
 
                                            2576,
471
 
                                            None,
472
 
                                            0,
473
 
                                            None,
474
 
                                            ('ftp', 'gopher', 'telnet',
475
 
                                             'dict', 'ldap', 'http', 'file'),
476
 
                                            None,
477
 
                                            0,
478
 
                                            None)
479
 
            self.assertRaises(errors.DependencyNotPresent, self._transport,
480
 
                              'https://launchpad.net')
481
 
        finally:
482
 
            # Restore the right function
 
456
        def restore():
483
457
            pycurl.version_info = version_info_orig
 
458
        self.addCleanup(restore)
 
459
 
 
460
        # Fake the pycurl version_info This was taken from a windows pycurl
 
461
        # without SSL (thanks to bialix)
 
462
        pycurl.version_info = lambda : (2,
 
463
                                        '7.13.2',
 
464
                                        462082,
 
465
                                        'i386-pc-win32',
 
466
                                        2576,
 
467
                                        None,
 
468
                                        0,
 
469
                                        None,
 
470
                                        ('ftp', 'gopher', 'telnet',
 
471
                                         'dict', 'ldap', 'http', 'file'),
 
472
                                        None,
 
473
                                        0,
 
474
                                        None)
 
475
        self.assertRaises(errors.DependencyNotPresent, self._transport,
 
476
                          'https://launchpad.net')
484
477
 
485
478
 
486
479
class TestHTTPConnections(http_utils.TestCaseWithWebserver):
603
596
                                      protocol_version=self._protocol_version)
604
597
 
605
598
    def _testing_pycurl(self):
606
 
        return pycurl_present and self._transport == PyCurlTransport
 
599
        # TODO: This is duplicated for lots of the classes in this file
 
600
        return (features.pycurl.available()
 
601
                and self._transport == PyCurlTransport)
607
602
 
608
603
 
609
604
class WallRequestHandler(http_server.TestingHTTPRequestHandler):
718
713
    _req_handler_class = BadProtocolRequestHandler
719
714
 
720
715
    def setUp(self):
721
 
        if pycurl_present and self._transport == PyCurlTransport:
 
716
        if self._testing_pycurl():
722
717
            raise tests.TestNotApplicable(
723
718
                "pycurl doesn't check the protocol version")
724
719
        super(TestBadProtocolServer, self).setUp()
1187
1182
        self._old_env = {}
1188
1183
 
1189
1184
    def _testing_pycurl(self):
1190
 
        return pycurl_present and self._transport == PyCurlTransport
 
1185
        # TODO: This is duplicated for lots of the classes in this file
 
1186
        return (features.pycurl.available()
 
1187
                and self._transport == PyCurlTransport)
1191
1188
 
1192
1189
    def create_transport_secondary_server(self):
1193
1190
        """Creates an http server that will serve files with
1389
1386
    """
1390
1387
 
1391
1388
    def setUp(self):
1392
 
        if pycurl_present and self._transport == PyCurlTransport:
 
1389
        if (features.pycurl.available()
 
1390
            and self._transport == PyCurlTransport):
1393
1391
            raise tests.TestNotApplicable(
1394
1392
                "pycurl doesn't redirect silently annymore")
1395
1393
        super(TestHTTPSilentRedirections, self).setUp()
1507
1505
        return self._auth_server(protocol_version=self._protocol_version)
1508
1506
 
1509
1507
    def _testing_pycurl(self):
1510
 
        return pycurl_present and self._transport == PyCurlTransport
 
1508
        # TODO: This is duplicated for lots of the classes in this file
 
1509
        return (features.pycurl.available()
 
1510
                and self._transport == PyCurlTransport)
1511
1511
 
1512
1512
    def get_user_url(self, user, password):
1513
1513
        """Build an url embedding user and password"""