/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-07-13 19:02:12 UTC
  • mfrom: (4986.2.8 deprecation)
  • Revision ID: pqm@pqm.ubuntu.com-20100713190212-bnayd5moplwtxhhb
(mbp) change some test tearDowns to addCleanup or overrideAttr (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
                            _qualified_prefix='http+pycurl',)))
90
90
    tests.multiply_tests(t_tests, transport_scenarios, result)
91
91
 
 
92
    protocol_scenarios = [
 
93
            ('HTTP/1.0',  dict(_protocol_version='HTTP/1.0')),
 
94
            ('HTTP/1.1',  dict(_protocol_version='HTTP/1.1')),
 
95
            ]
 
96
 
 
97
    # some tests are parametrized by the protocol version only
 
98
    p_tests, remaining_tests = tests.split_suite_by_condition(
 
99
        remaining_tests, tests.condition_isinstance((
 
100
                TestAuthOnRedirected,
 
101
                )))
 
102
    tests.multiply_tests(p_tests, protocol_scenarios, result)
 
103
 
92
104
    # each implementation tested with each HTTP version
93
105
    tp_tests, remaining_tests = tests.split_suite_by_condition(
94
106
        remaining_tests, tests.condition_isinstance((
103
115
                TestRanges,
104
116
                TestSpecificRequestHandler,
105
117
                )))
106
 
    protocol_scenarios = [
107
 
            ('HTTP/1.0',  dict(_protocol_version='HTTP/1.0')),
108
 
            ('HTTP/1.1',  dict(_protocol_version='HTTP/1.1')),
109
 
            ]
110
118
    tp_scenarios = tests.multiply_scenarios(transport_scenarios,
111
119
                                            protocol_scenarios)
112
120
    tests.multiply_tests(tp_tests, tp_scenarios, result)
1117
1125
    def setUp(self):
1118
1126
        tests.TestCase.setUp(self)
1119
1127
        self._old_env = {}
1120
 
 
1121
 
    def tearDown(self):
1122
 
        self._restore_env()
1123
 
        tests.TestCase.tearDown(self)
 
1128
        self.addCleanup(self._restore_env)
1124
1129
 
1125
1130
    def _install_env(self, env):
1126
1131
        for name, value in env.iteritems():
1966
1971
        # We override at class level because constructors may propagate the
1967
1972
        # bound method and render instance overriding ineffective (an
1968
1973
        # alternative would be to define a specific ui factory instead...)
1969
 
        self.orig_report_activity = self._transport._report_activity
1970
 
        self._transport._report_activity = report_activity
1971
 
 
1972
 
    def tearDown(self):
1973
 
        self._transport._report_activity = self.orig_report_activity
1974
 
        self.server.stop_server()
1975
 
        tests.TestCase.tearDown(self)
 
1974
        self.overrideAttr(self._transport, '_report_activity', report_activity)
 
1975
        self.addCleanup(self.server.stop_server)
1976
1976
 
1977
1977
    def get_transport(self):
1978
1978
        return self._transport(self.server.get_url())
2095
2095
class TestActivity(tests.TestCase, TestActivityMixin):
2096
2096
 
2097
2097
    def setUp(self):
2098
 
        tests.TestCase.setUp(self)
2099
 
        self.server = self._activity_server(self._protocol_version)
2100
 
        self.server.start_server()
2101
 
        self.activities = {}
2102
 
        def report_activity(t, bytes, direction):
2103
 
            count = self.activities.get(direction, 0)
2104
 
            count += bytes
2105
 
            self.activities[direction] = count
2106
 
 
2107
 
        # We override at class level because constructors may propagate the
2108
 
        # bound method and render instance overriding ineffective (an
2109
 
        # alternative would be to define a specific ui factory instead...)
2110
 
        self.orig_report_activity = self._transport._report_activity
2111
 
        self._transport._report_activity = report_activity
2112
 
 
2113
 
    def tearDown(self):
2114
 
        self._transport._report_activity = self.orig_report_activity
2115
 
        self.server.stop_server()
2116
 
        tests.TestCase.tearDown(self)
 
2098
        TestActivityMixin.setUp(self)
2117
2099
 
2118
2100
 
2119
2101
class TestNoReportActivity(tests.TestCase, TestActivityMixin):
2120
2102
 
 
2103
    # Unlike TestActivity, we are really testing ReportingFileSocket and
 
2104
    # ReportingSocket, so we don't need all the parametrization. Since
 
2105
    # ReportingFileSocket and ReportingSocket are wrappers, it's easier to
 
2106
    # test them through their use by the transport than directly (that's a
 
2107
    # bit less clean but far more simpler and effective).
 
2108
    _activity_server = ActivityHTTPServer
 
2109
    _protocol_version = 'HTTP/1.1'
 
2110
 
2121
2111
    def setUp(self):
2122
 
        tests.TestCase.setUp(self)
2123
 
        # Unlike TestActivity, we are really testing ReportingFileSocket and
2124
 
        # ReportingSocket, so we don't need all the parametrization. Since
2125
 
        # ReportingFileSocket and ReportingSocket are wrappers, it's easier to
2126
 
        # test them through their use by the transport than directly (that's a
2127
 
        # bit less clean but far more simpler and effective).
2128
 
        self.server = ActivityHTTPServer('HTTP/1.1')
2129
 
        self._transport=_urllib.HttpTransport_urllib
2130
 
 
2131
 
        self.server.start_server()
2132
 
 
2133
 
        # We override at class level because constructors may propagate the
2134
 
        # bound method and render instance overriding ineffective (an
2135
 
        # alternative would be to define a specific ui factory instead...)
2136
 
        self.orig_report_activity = self._transport._report_activity
2137
 
        self._transport._report_activity = None
2138
 
 
2139
 
    def tearDown(self):
2140
 
        self._transport._report_activity = self.orig_report_activity
2141
 
        self.server.stop_server()
2142
 
        tests.TestCase.tearDown(self)
 
2112
        self._transport =_urllib.HttpTransport_urllib
 
2113
        TestActivityMixin.setUp(self)
2143
2114
 
2144
2115
    def assertActivitiesMatch(self):
2145
2116
        # Nothing to check here
2156
2127
    _transport = _urllib.HttpTransport_urllib
2157
2128
 
2158
2129
    def create_transport_readonly_server(self):
2159
 
        return self._auth_server()
 
2130
        return self._auth_server(protocol_version=self._protocol_version)
2160
2131
 
2161
2132
    def create_transport_secondary_server(self):
2162
2133
        """Create the secondary server redirecting to the primary server"""
2163
2134
        new = self.get_readonly_server()
2164
2135
 
2165
 
        redirecting = http_utils.HTTPServerRedirecting()
 
2136
        redirecting = http_utils.HTTPServerRedirecting(
 
2137
            protocol_version=self._protocol_version)
2166
2138
        redirecting.redirect_to(new.host, new.port)
2167
2139
        return redirecting
2168
2140