~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-13 08:53:34 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061013085334-e216654a3e842ff9
Fix bug #57644 by issuing an explicit error message.

* bzrlib/tests/test_http.py:
Fix some doc strings.
(TestForbiddenServer, TestForbiddenServer_urllib,
TestForbiddenServer_pycurl): Tests for correct handling of 403
error code.

* bzrlib/transport/http/_urllib2_wrappers.py:
Cleanup errors import and uses.
(HTTPDefaultErrorHandler.http_error_default): Handles 403 error code.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._raise_curl_http_error): Handles 403 error code.

* bzrlib/tests/HTTPTestUtil.py:
(ForbiddenRequestHandler): New class. An http server where
everything is forbidden.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import socket
23
23
 
24
24
import bzrlib
25
 
from bzrlib.errors import (
26
 
    DependencyNotPresent,
27
 
    ConnectionError,
28
 
    InvalidHttpResponse,
29
 
    )
 
25
from bzrlib import errors
30
26
from bzrlib.tests import (
31
27
    TestCase,
32
28
    TestSkipped,
39
35
from bzrlib.tests.HTTPTestUtil import (
40
36
    BadProtocolRequestHandler,
41
37
    BadStatusRequestHandler,
 
38
    ForbiddenRequestHandler,
42
39
    InvalidStatusRequestHandler,
43
40
    TestCaseWithWebserver,
44
41
    WallRequestHandler,
167
164
            s = socket.socket()
168
165
            s.bind(('localhost', 0))
169
166
            t = self._transport('http://%s:%s/' % s.getsockname())
170
 
            self.assertRaises(ConnectionError, t.has, 'foo/bar')
 
167
            self.assertRaises(errors.ConnectionError, t.has, 'foo/bar')
171
168
        finally:
172
169
            socket.setdefaulttimeout(default_timeout)
173
170
 
178
175
        try:
179
176
            from bzrlib.transport.http._pycurl import PyCurlTransport
180
177
            return PyCurlTransport
181
 
        except DependencyNotPresent:
 
178
        except errors.DependencyNotPresent:
182
179
            raise TestSkipped('pycurl not present')
183
180
 
184
181
    _transport = property(_get_pycurl_maybe)
265
262
    def test_http_has(self):
266
263
        server = self.get_readonly_server()
267
264
        t = self._transport(server.get_url())
268
 
        self.assertRaises(ConnectionError, t.has, 'foo/bar')
 
265
        self.assertRaises(errors.ConnectionError, t.has, 'foo/bar')
269
266
 
270
267
    def test_http_get(self):
271
268
        server = self.get_readonly_server()
272
269
        t = self._transport(server.get_url())
273
 
        self.assertRaises(ConnectionError, t.get, 'foo/bar')
 
270
        self.assertRaises(errors.ConnectionError, t.get, 'foo/bar')
274
271
 
275
272
 
276
273
class TestWallServer_urllib(TestWallServer, TestCaseWithWebserver):
277
 
    """Tests WallServer for urllib implementation"""
 
274
    """Tests "wall" server for urllib implementation"""
278
275
 
279
276
    _transport = HttpTransport_urllib
280
277
 
282
279
class TestWallServer_pycurl(TestWithTransport_pycurl,
283
280
                            TestWallServer,
284
281
                            TestCaseWithWebserver):
285
 
    """Tests WallServer for pycurl implementation"""
 
282
    """Tests "wall" server for pycurl implementation"""
286
283
 
287
284
 
288
285
class TestBadStatusServer(object):
294
291
    def test_http_has(self):
295
292
        server = self.get_readonly_server()
296
293
        t = self._transport(server.get_url())
297
 
        self.assertRaises(InvalidHttpResponse, t.has, 'foo/bar')
 
294
        self.assertRaises(errors.InvalidHttpResponse, t.has, 'foo/bar')
298
295
 
299
296
    def test_http_get(self):
300
297
        server = self.get_readonly_server()
301
298
        t = self._transport(server.get_url())
302
 
        self.assertRaises(InvalidHttpResponse, t.get, 'foo/bar')
 
299
        self.assertRaises(errors.InvalidHttpResponse, t.get, 'foo/bar')
303
300
 
304
301
 
305
302
class TestBadStatusServer_urllib(TestBadStatusServer, TestCaseWithWebserver):
306
 
    """Tests BadStatusServer for urllib implementation"""
 
303
    """Tests bad status server for urllib implementation"""
307
304
 
308
305
    _transport = HttpTransport_urllib
309
306
 
311
308
class TestBadStatusServer_pycurl(TestWithTransport_pycurl,
312
309
                                 TestBadStatusServer,
313
310
                                 TestCaseWithWebserver):
314
 
    """Tests BadStatusServer for pycurl implementation"""
 
311
    """Tests bad status server for pycurl implementation"""
315
312
 
316
313
 
317
314
class TestInvalidStatusServer(TestBadStatusServer):
326
323
 
327
324
class TestInvalidStatusServer_urllib(TestInvalidStatusServer,
328
325
                                     TestCaseWithWebserver):
329
 
    """Tests InvalidStatusServer for urllib implementation"""
 
326
    """Tests invalid status server for urllib implementation"""
330
327
 
331
328
    _transport = HttpTransport_urllib
332
329
 
334
331
class TestInvalidStatusServer_pycurl(TestWithTransport_pycurl,
335
332
                                     TestInvalidStatusServer,
336
333
                                     TestCaseWithWebserver):
337
 
    """Tests InvalidStatusServer for pycurl implementation"""
 
334
    """Tests invalid status server for pycurl implementation"""
338
335
 
339
336
 
340
337
class TestBadProtocolServer(object):
341
 
    """Tests bad status from server."""
 
338
    """Tests bad protocol from server."""
342
339
 
343
340
    def create_transport_readonly_server(self):
344
341
        return HttpServer(BadProtocolRequestHandler)
346
343
    def test_http_has(self):
347
344
        server = self.get_readonly_server()
348
345
        t = self._transport(server.get_url())
349
 
        self.assertRaises(InvalidHttpResponse, t.has, 'foo/bar')
 
346
        self.assertRaises(errors.InvalidHttpResponse, t.has, 'foo/bar')
350
347
 
351
348
    def test_http_get(self):
352
349
        server = self.get_readonly_server()
353
350
        t = self._transport(server.get_url())
354
 
        self.assertRaises(InvalidHttpResponse, t.get, 'foo/bar')
 
351
        self.assertRaises(errors.InvalidHttpResponse, t.get, 'foo/bar')
355
352
 
356
353
 
357
354
class TestBadProtocolServer_urllib(TestBadProtocolServer,
358
355
                                   TestCaseWithWebserver):
359
 
    """Tests BadProtocolServer for urllib implementation"""
 
356
    """Tests bad protocol server for urllib implementation"""
360
357
 
361
358
    _transport = HttpTransport_urllib
362
359
 
364
361
#class TestBadProtocolServer_pycurl(TestWithTransport_pycurl,
365
362
#                                   TestBadProtocolServer,
366
363
#                                   TestCaseWithWebserver):
367
 
#    """Tests BadProtocolServer for pycurl implementation"""
 
364
#    """Tests bad protocol server for pycurl implementation"""
 
365
 
 
366
 
 
367
class TestForbiddenServer(object):
 
368
    """Tests forbidden server"""
 
369
 
 
370
    def create_transport_readonly_server(self):
 
371
        return HttpServer(ForbiddenRequestHandler)
 
372
 
 
373
    def test_http_has(self):
 
374
        server = self.get_readonly_server()
 
375
        t = self._transport(server.get_url())
 
376
        self.assertRaises(errors.TransportError, t.has, 'foo/bar')
 
377
 
 
378
    def test_http_get(self):
 
379
        server = self.get_readonly_server()
 
380
        t = self._transport(server.get_url())
 
381
        self.assertRaises(errors.TransportError, t.get, 'foo/bar')
 
382
 
 
383
 
 
384
class TestForbiddenServer_urllib(TestForbiddenServer, TestCaseWithWebserver):
 
385
    """Tests forbidden server for urllib implementation"""
 
386
 
 
387
    _transport = HttpTransport_urllib
 
388
 
 
389
 
 
390
class TestForbiddenServer_pycurl(TestWithTransport_pycurl,
 
391
                                 TestForbiddenServer,
 
392
                                 TestCaseWithWebserver):
 
393
    """Tests forbidden server for pycurl implementation"""
 
394