~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-01 03:31:37 UTC
  • mfrom: (2294.3.3 bzr.ab.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070301033137-9b87fdf211dc2e15
Fix #85305 by issuing an exception instead of a traceback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
        self.port = None
127
127
 
128
128
 
 
129
class TestWithTransport_pycurl(object):
 
130
    """Test case to inherit from if pycurl is present"""
 
131
 
 
132
    def _get_pycurl_maybe(self):
 
133
        try:
 
134
            from bzrlib.transport.http._pycurl import PyCurlTransport
 
135
            return PyCurlTransport
 
136
        except errors.DependencyNotPresent:
 
137
            raise TestSkipped('pycurl not present')
 
138
 
 
139
    _transport = property(_get_pycurl_maybe)
 
140
 
 
141
 
129
142
class TestHttpUrls(TestCase):
130
143
 
131
 
    # FIXME: Some of these tests should be done for both
132
 
    # implementations
 
144
    # TODO: This should be moved to authorization tests once they
 
145
    # are written.
133
146
 
134
147
    def test_url_parsing(self):
135
148
        f = FakeManager()
142
155
        self.assertEquals([None, 'www.bazaar-vcs.org', 'user', 'pass'],
143
156
                          f.credentials[0])
144
157
 
 
158
 
 
159
class TestHttpTransportUrls(object):
 
160
    """Test the http urls.
 
161
 
 
162
    This MUST be used by daughter classes that also inherit from
 
163
    TestCase.
 
164
 
 
165
    We can't inherit directly from TestCase or the
 
166
    test framework will try to create an instance which cannot
 
167
    run, its implementation being incomplete.
 
168
    """
 
169
 
145
170
    def test_abs_url(self):
146
171
        """Construction of absolute http URLs"""
147
 
        t = HttpTransport_urllib('http://bazaar-vcs.org/bzr/bzr.dev/')
 
172
        t = self._transport('http://bazaar-vcs.org/bzr/bzr.dev/')
148
173
        eq = self.assertEqualDiff
149
 
        eq(t.abspath('.'),
150
 
           'http://bazaar-vcs.org/bzr/bzr.dev')
151
 
        eq(t.abspath('foo/bar'),
152
 
           'http://bazaar-vcs.org/bzr/bzr.dev/foo/bar')
153
 
        eq(t.abspath('.bzr'),
154
 
           'http://bazaar-vcs.org/bzr/bzr.dev/.bzr')
 
174
        eq(t.abspath('.'), 'http://bazaar-vcs.org/bzr/bzr.dev')
 
175
        eq(t.abspath('foo/bar'), 'http://bazaar-vcs.org/bzr/bzr.dev/foo/bar')
 
176
        eq(t.abspath('.bzr'), 'http://bazaar-vcs.org/bzr/bzr.dev/.bzr')
155
177
        eq(t.abspath('.bzr/1//2/./3'),
156
178
           'http://bazaar-vcs.org/bzr/bzr.dev/.bzr/1/2/3')
157
179
 
158
180
    def test_invalid_http_urls(self):
159
181
        """Trap invalid construction of urls"""
160
 
        t = HttpTransport_urllib('http://bazaar-vcs.org/bzr/bzr.dev/')
161
 
        self.assertRaises(ValueError,
162
 
            t.abspath,
163
 
            '.bzr/')
164
 
        t = HttpTransport_urllib('http://http://bazaar-vcs.org/bzr/bzr.dev/')
165
 
        self.assertRaises(errors.InvalidURL, t.has, 'foo/bar')
 
182
        t = self._transport('http://bazaar-vcs.org/bzr/bzr.dev/')
 
183
        self.assertRaises(ValueError, t.abspath, '.bzr/')
 
184
        t = self._transport('http://http://bazaar-vcs.org/bzr/bzr.dev/')
 
185
        self.assertRaises((errors.InvalidURL, errors.ConnectionError),
 
186
                          t.has, 'foo/bar')
166
187
 
167
188
    def test_http_root_urls(self):
168
189
        """Construction of URLs from server root"""
169
 
        t = HttpTransport_urllib('http://bzr.ozlabs.org/')
 
190
        t = self._transport('http://bzr.ozlabs.org/')
170
191
        eq = self.assertEqualDiff
171
192
        eq(t.abspath('.bzr/tree-version'),
172
193
           'http://bzr.ozlabs.org/.bzr/tree-version')
173
194
 
174
195
    def test_http_impl_urls(self):
175
196
        """There are servers which ask for particular clients to connect"""
176
 
        server = HttpServer_PyCurl()
 
197
        server = self._server()
177
198
        try:
178
199
            server.setUp()
179
200
            url = server.get_url()
180
 
            self.assertTrue(url.startswith('http+pycurl://'))
 
201
            self.assertTrue(url.startswith('%s://' % self._qualified_prefix))
181
202
        finally:
182
203
            server.tearDown()
183
204
 
184
205
 
 
206
class TestHttpUrls_urllib(TestHttpTransportUrls, TestCase):
 
207
    """Test http urls with urllib"""
 
208
 
 
209
    _transport = HttpTransport_urllib
 
210
    _server = HttpServer_urllib
 
211
    _qualified_prefix = 'http+urllib'
 
212
 
 
213
 
 
214
class TestHttpUrls_pycurl(TestWithTransport_pycurl, TestHttpTransportUrls,
 
215
                          TestCase):
 
216
    """Test http urls with pycurl"""
 
217
 
 
218
    _server = HttpServer_PyCurl
 
219
    _qualified_prefix = 'http+pycurl'
 
220
 
 
221
    # TODO: This should really be moved into another pycurl
 
222
    # specific test. When https tests will be implemented, take
 
223
    # this one into account.
 
224
    def test_pycurl_without_https_support(self):
 
225
        """Test that pycurl without SSL do not fail with a traceback.
 
226
 
 
227
        For the purpose of the test, we force pycurl to ignore
 
228
        https by supplying a fake version_info that do not
 
229
        support it.
 
230
        """
 
231
        try:
 
232
            import pycurl
 
233
        except ImportError:
 
234
            raise TestSkipped('pycurl not present')
 
235
        # Now that we have pycurl imported, we can fake its version_info
 
236
        # This was taken from a windows pycurl without SSL
 
237
        # (thanks to bialix)
 
238
        pycurl.version_info = lambda : (2,
 
239
                                        '7.13.2',
 
240
                                        462082,
 
241
                                        'i386-pc-win32',
 
242
                                        2576,
 
243
                                        None,
 
244
                                        0,
 
245
                                        None,
 
246
                                        ('ftp', 'gopher', 'telnet',
 
247
                                         'dict', 'ldap', 'http', 'file'),
 
248
                                        None,
 
249
                                        0,
 
250
                                        None)
 
251
        self.assertRaises(errors.DependencyNotPresent, self._transport,
 
252
                          'https://launchpad.net')
 
253
 
185
254
class TestHttpConnections(object):
186
255
    """Test the http connections.
187
256
 
247
316
            socket.setdefaulttimeout(default_timeout)
248
317
 
249
318
 
250
 
class TestWithTransport_pycurl(object):
251
 
    """Test case to inherit from if pycurl is present"""
252
 
 
253
 
    def _get_pycurl_maybe(self):
254
 
        try:
255
 
            from bzrlib.transport.http._pycurl import PyCurlTransport
256
 
            return PyCurlTransport
257
 
        except errors.DependencyNotPresent:
258
 
            raise TestSkipped('pycurl not present')
259
 
 
260
 
    _transport = property(_get_pycurl_maybe)
261
 
 
262
 
 
263
319
class TestHttpConnections_urllib(TestHttpConnections, TestCaseWithWebserver):
264
320
    """Test http connections with urllib"""
265
321