/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: Andrew Bennetts
  • Date: 2009-11-19 06:28:13 UTC
  • mfrom: (4811 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4812.
  • Revision ID: andrew.bennetts@canonical.com-20091119062813-t6sd6gwbot8nfyze
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1178
1178
        if self._testing_pycurl():
1179
1179
            # Oh my ! pycurl does not check for the port as part of
1180
1180
            # no_proxy :-( So we just test the host part
1181
 
            self.no_proxy_host = 'localhost'
 
1181
            self.no_proxy_host = self.server.host
1182
1182
        else:
1183
1183
            self.no_proxy_host = self.proxy_address
1184
1184
        # The secondary server is the proxy
1956
1956
        pass
1957
1957
 
1958
1958
 
1959
 
class TestActivity(tests.TestCase):
 
1959
class TestActivityMixin(object):
1960
1960
    """Test socket activity reporting.
1961
1961
 
1962
1962
    We use a special purpose server to control the bytes sent and received and
2100
2100
        code, f = t._post('abc def end-of-body\n')
2101
2101
        self.assertEqual('lalala whatever as long as itsssss\n', f.read())
2102
2102
        self.assertActivitiesMatch()
 
2103
 
 
2104
 
 
2105
class TestActivity(tests.TestCase, TestActivityMixin):
 
2106
 
 
2107
    def setUp(self):
 
2108
        tests.TestCase.setUp(self)
 
2109
        self.server = self._activity_server(self._protocol_version)
 
2110
        self.server.setUp()
 
2111
        self.activities = {}
 
2112
        def report_activity(t, bytes, direction):
 
2113
            count = self.activities.get(direction, 0)
 
2114
            count += bytes
 
2115
            self.activities[direction] = count
 
2116
 
 
2117
        # We override at class level because constructors may propagate the
 
2118
        # bound method and render instance overriding ineffective (an
 
2119
        # alternative would be to define a specific ui factory instead...)
 
2120
        self.orig_report_activity = self._transport._report_activity
 
2121
        self._transport._report_activity = report_activity
 
2122
 
 
2123
    def tearDown(self):
 
2124
        self._transport._report_activity = self.orig_report_activity
 
2125
        self.server.tearDown()
 
2126
        tests.TestCase.tearDown(self)
 
2127
 
 
2128
 
 
2129
class TestNoReportActivity(tests.TestCase, TestActivityMixin):
 
2130
 
 
2131
    def setUp(self):
 
2132
        tests.TestCase.setUp(self)
 
2133
        # Unlike TestActivity, we are really testing ReportingFileSocket and
 
2134
        # ReportingSocket, so we don't need all the parametrization. Since
 
2135
        # ReportingFileSocket and ReportingSocket are wrappers, it's easier to
 
2136
        # test them through their use by the transport than directly (that's a
 
2137
        # bit less clean but far more simpler and effective).
 
2138
        self.server = ActivityHTTPServer('HTTP/1.1')
 
2139
        self._transport=_urllib.HttpTransport_urllib
 
2140
 
 
2141
        self.server.setUp()
 
2142
 
 
2143
        # We override at class level because constructors may propagate the
 
2144
        # bound method and render instance overriding ineffective (an
 
2145
        # alternative would be to define a specific ui factory instead...)
 
2146
        self.orig_report_activity = self._transport._report_activity
 
2147
        self._transport._report_activity = None
 
2148
 
 
2149
    def tearDown(self):
 
2150
        self._transport._report_activity = self.orig_report_activity
 
2151
        self.server.tearDown()
 
2152
        tests.TestCase.tearDown(self)
 
2153
 
 
2154
    def assertActivitiesMatch(self):
 
2155
        # Nothing to check here
 
2156
        pass