~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Martin Pool
  • Date: 2009-12-22 04:07:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4917.
  • Revision ID: mbp@sourcefrog.net-20091222040736-079e2r91hea7a40l
Rename to -Dno_activity; incidentally fixes ReST syntax error

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,
52
51
    http_server,
53
52
    http_utils,
54
53
    )
62
61
    )
63
62
 
64
63
 
65
 
if features.pycurl.available():
 
64
try:
66
65
    from bzrlib.transport.http._pycurl import PyCurlTransport
 
66
    pycurl_present = True
 
67
except errors.DependencyNotPresent:
 
68
    pycurl_present = False
67
69
 
68
70
 
69
71
def load_tests(standard_tests, module, loader):
82
84
                        _server=http_server.HttpServer_urllib,
83
85
                        _qualified_prefix='http+urllib',)),
84
86
        ]
85
 
    if features.pycurl.available():
 
87
    if pycurl_present:
86
88
        transport_scenarios.append(
87
89
            ('pycurl', dict(_transport=PyCurlTransport,
88
90
                            _server=http_server.HttpServer_PyCurl,
154
156
        activity_scenarios.append(
155
157
            ('urllib,https', dict(_activity_server=ActivityHTTPSServer,
156
158
                                  _transport=_urllib.HttpTransport_urllib,)),)
157
 
    if features.pycurl.available():
 
159
    if pycurl_present:
158
160
        activity_scenarios.append(
159
161
            ('pycurl,http', dict(_activity_server=ActivityHTTPServer,
160
162
                                 _transport=PyCurlTransport,)),)
374
376
    """Test case to inherit from if pycurl is present"""
375
377
 
376
378
    def _get_pycurl_maybe(self):
377
 
        self.requireFeature(features.pycurl)
378
 
        return PyCurlTransport
 
379
        try:
 
380
            from bzrlib.transport.http._pycurl import PyCurlTransport
 
381
            return PyCurlTransport
 
382
        except errors.DependencyNotPresent:
 
383
            raise tests.TestSkipped('pycurl not present')
379
384
 
380
385
    _transport = property(_get_pycurl_maybe)
381
386
 
448
453
        https by supplying a fake version_info that do not
449
454
        support it.
450
455
        """
451
 
        self.requireFeature(features.pycurl)
452
 
        # Import the module locally now that we now it's available.
453
 
        pycurl = features.pycurl.module
 
456
        try:
 
457
            import pycurl
 
458
        except ImportError:
 
459
            raise tests.TestSkipped('pycurl not present')
454
460
 
455
461
        version_info_orig = pycurl.version_info
456
 
        def restore():
 
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
457
483
            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')
477
484
 
478
485
 
479
486
class TestHTTPConnections(http_utils.TestCaseWithWebserver):
596
603
                                      protocol_version=self._protocol_version)
597
604
 
598
605
    def _testing_pycurl(self):
599
 
        # TODO: This is duplicated for lots of the classes in this file
600
 
        return (features.pycurl.available()
601
 
                and self._transport == PyCurlTransport)
 
606
        return pycurl_present and self._transport == PyCurlTransport
602
607
 
603
608
 
604
609
class WallRequestHandler(http_server.TestingHTTPRequestHandler):
713
718
    _req_handler_class = BadProtocolRequestHandler
714
719
 
715
720
    def setUp(self):
716
 
        if self._testing_pycurl():
 
721
        if pycurl_present and self._transport == PyCurlTransport:
717
722
            raise tests.TestNotApplicable(
718
723
                "pycurl doesn't check the protocol version")
719
724
        super(TestBadProtocolServer, self).setUp()
1182
1187
        self._old_env = {}
1183
1188
 
1184
1189
    def _testing_pycurl(self):
1185
 
        # TODO: This is duplicated for lots of the classes in this file
1186
 
        return (features.pycurl.available()
1187
 
                and self._transport == PyCurlTransport)
 
1190
        return pycurl_present and self._transport == PyCurlTransport
1188
1191
 
1189
1192
    def create_transport_secondary_server(self):
1190
1193
        """Creates an http server that will serve files with
1386
1389
    """
1387
1390
 
1388
1391
    def setUp(self):
1389
 
        if (features.pycurl.available()
1390
 
            and self._transport == PyCurlTransport):
 
1392
        if pycurl_present and self._transport == PyCurlTransport:
1391
1393
            raise tests.TestNotApplicable(
1392
1394
                "pycurl doesn't redirect silently annymore")
1393
1395
        super(TestHTTPSilentRedirections, self).setUp()
1505
1507
        return self._auth_server(protocol_version=self._protocol_version)
1506
1508
 
1507
1509
    def _testing_pycurl(self):
1508
 
        # TODO: This is duplicated for lots of the classes in this file
1509
 
        return (features.pycurl.available()
1510
 
                and self._transport == PyCurlTransport)
 
1510
        return pycurl_present and self._transport == PyCurlTransport
1511
1511
 
1512
1512
    def get_user_url(self, user, password):
1513
1513
        """Build an url embedding user and password"""