~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

Merge bzr.dev and tree-file-ids-as-tuples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import bzrlib
33
33
from bzrlib import (
34
34
    bzrdir,
35
 
    cethread,
36
35
    config,
37
36
    debug,
38
37
    errors,
128
127
        ('urllib,http', dict(_activity_server=ActivityHTTPServer,
129
128
                            _transport=_urllib.HttpTransport_urllib,)),
130
129
        ]
 
130
    if features.pycurl.available():
 
131
        activity_scenarios.append(
 
132
            ('pycurl,http', dict(_activity_server=ActivityHTTPServer,
 
133
                                _transport=PyCurlTransport,)),)
131
134
    if features.HTTPSServerFeature.available():
 
135
        # FIXME: Until we have a better way to handle self-signed certificates
 
136
        # (like allowing them in a test specific authentication.conf for
 
137
        # example), we need some specialized pycurl/urllib transport for tests.
 
138
        # -- vila 2012-01-20
 
139
        from bzrlib.tests import (
 
140
            ssl_certs,
 
141
            )
 
142
        class HTTPS_urllib_transport(_urllib.HttpTransport_urllib):
 
143
 
 
144
            def __init__(self, base, _from_transport=None):
 
145
                super(HTTPS_urllib_transport, self).__init__(
 
146
                    base, _from_transport=_from_transport,
 
147
                    ca_certs=ssl_certs.build_path('ca.crt'))
 
148
 
132
149
        activity_scenarios.append(
133
150
            ('urllib,https', dict(_activity_server=ActivityHTTPSServer,
134
 
                                _transport=_urllib.HttpTransport_urllib,)),)
135
 
    if features.pycurl.available():
136
 
        activity_scenarios.append(
137
 
            ('pycurl,http', dict(_activity_server=ActivityHTTPServer,
138
 
                                _transport=PyCurlTransport,)),)
139
 
        if features.HTTPSServerFeature.available():
140
 
            from bzrlib.tests import (
141
 
                ssl_certs,
142
 
                )
143
 
            # FIXME: Until we have a better way to handle self-signed
144
 
            # certificates (like allowing them in a test specific
145
 
            # authentication.conf for example), we need some specialized pycurl
146
 
            # transport for tests.
 
151
                                  _transport=HTTPS_urllib_transport,)),)
 
152
        if features.pycurl.available():
147
153
            class HTTPS_pycurl_transport(PyCurlTransport):
148
154
 
149
155
                def __init__(self, base, _from_transport=None):
2120
2126
        tests.TestCase.setUp(self)
2121
2127
        self.server = self._activity_server(self._protocol_version)
2122
2128
        self.server.start_server()
 
2129
        self.addCleanup(self.server.stop_server)
2123
2130
        _activities = {} # Don't close over self and create a cycle
2124
2131
        def report_activity(t, bytes, direction):
2125
2132
            count = _activities.get(direction, 0)
2126
2133
            count += bytes
2127
2134
            _activities[direction] = count
2128
2135
        self.activities = _activities
2129
 
 
2130
2136
        # We override at class level because constructors may propagate the
2131
2137
        # bound method and render instance overriding ineffective (an
2132
2138
        # alternative would be to define a specific ui factory instead...)
2133
2139
        self.overrideAttr(self._transport, '_report_activity', report_activity)
2134
 
        self.addCleanup(self.server.stop_server)
2135
2140
 
2136
2141
    def get_transport(self):
2137
2142
        t = self._transport(self.server.get_url())