~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-12 14:29:32 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-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    TestCase,
32
32
    TestSkipped,
33
33
    )
 
34
from bzrlib.tests.HttpServer import (
 
35
    HttpServer,
 
36
    HttpServer_PyCurl,
 
37
    HttpServer_urllib,
 
38
    )
 
39
from bzrlib.tests.HTTPTestUtil import (
 
40
    BadProtocolRequestHandler,
 
41
    BadStatusRequestHandler,
 
42
    InvalidStatusRequestHandler,
 
43
    TestCaseWithWebserver,
 
44
    WallRequestHandler,
 
45
    )
34
46
from bzrlib.transport import (
35
47
    get_transport,
36
48
    Transport,
37
49
    )
38
50
from bzrlib.transport.http import (
39
51
    extract_auth,
40
 
    BadProtocolRequestHandler,
41
 
    BadStatusRequestHandler,
42
52
    HttpTransportBase,
43
 
    InvalidStatusRequestHandler,
44
 
    WallRequestHandler,
45
53
    )
46
54
from bzrlib.transport.http._urllib import HttpTransport_urllib
47
 
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
48
55
 
49
56
 
50
57
class FakeManager (object):
98
105
 
99
106
    def test_http_impl_urls(self):
100
107
        """There are servers which ask for particular clients to connect"""
 
108
        server = HttpServer_PyCurl()
101
109
        try:
102
 
            from bzrlib.transport.http._pycurl import HttpServer_PyCurl
103
 
            server = HttpServer_PyCurl()
104
 
            try:
105
 
                server.setUp()
106
 
                url = server.get_url()
107
 
                self.assertTrue(url.startswith('http+pycurl://'))
108
 
            finally:
109
 
                server.tearDown()
110
 
        except DependencyNotPresent:
111
 
            raise TestSkipped('pycurl not present')
 
110
            server.setUp()
 
111
            url = server.get_url()
 
112
            self.assertTrue(url.startswith('http+pycurl://'))
 
113
        finally:
 
114
            server.tearDown()
112
115
 
113
116
 
114
117
class TestHttpConnections(object):
257
260
    """Tests exceptions during the connection phase"""
258
261
 
259
262
    def create_transport_readonly_server(self):
260
 
        return bzrlib.transport.http.HttpServer(WallRequestHandler)
 
263
        return HttpServer(WallRequestHandler)
261
264
 
262
265
    def test_http_has(self):
263
266
        server = self.get_readonly_server()
286
289
    """Tests bad status from server."""
287
290
 
288
291
    def create_transport_readonly_server(self):
289
 
        return bzrlib.transport.http.HttpServer(BadStatusRequestHandler)
 
292
        return HttpServer(BadStatusRequestHandler)
290
293
 
291
294
    def test_http_has(self):
292
295
        server = self.get_readonly_server()
318
321
    """
319
322
 
320
323
    def create_transport_readonly_server(self):
321
 
        return bzrlib.transport.http.HttpServer(InvalidStatusRequestHandler)
 
324
        return HttpServer(InvalidStatusRequestHandler)
322
325
 
323
326
 
324
327
class TestInvalidStatusServer_urllib(TestInvalidStatusServer,
338
341
    """Tests bad status from server."""
339
342
 
340
343
    def create_transport_readonly_server(self):
341
 
        return bzrlib.transport.http.HttpServer(BadProtocolRequestHandler)
 
344
        return HttpServer(BadProtocolRequestHandler)
342
345
 
343
346
    def test_http_has(self):
344
347
        server = self.get_readonly_server()
364
367
#    """Tests BadProtocolServer for pycurl implementation"""
365
368
 
366
369
 
 
370
class TestRangesServer(object):
 
371
    """Tests range requests against a server.
 
372
 
 
373
    This MUST be used by daughter classes that also inherit from
 
374
    TestCaseWithWebserver.
 
375
 
 
376
    We can't inherit directly from TestCaseWithWebserver or the
 
377
    test framework will try to create an instance which cannot
 
378
    run, its implementation being incomplete.
 
379
    """
 
380
 
 
381
    def setUp(self):
 
382
        TestCaseWithWebserver.setUp(self)
 
383
        transport = self.get_transport()
 
384
        if transport.is_readonly():
 
385
            file('a', 'w').write('0123456789')
 
386
        else:
 
387
            transport.put_bytes('a', '0123456789')
 
388
 
 
389
    def test_single_range(self):
 
390
        server = self.get_readonly_server()
 
391
        t = self._transport(server.get_url())
 
392
        content = t.readv(_file_10, )
 
393
 
 
394
        self.assertRaises(errors.InvalidRange, out.read, 20)
 
395
 
 
396
        out.seek(100)
 
397
        self.assertEqual(_single_range_response[2], out.read(100))
 
398
 
 
399
    def test_single_range_no_content(self):
 
400
        out = self.get_response(_single_range_no_content_type)
 
401
        self.assertIsInstance(out, response.HttpRangeResponse)
 
402
 
 
403
        self.assertRaises(errors.InvalidRange, out.read, 20)
 
404
 
 
405
        out.seek(100)
 
406
        self.assertEqual(_single_range_no_content_type[2], out.read(100))
 
407
 
 
408
    def test_multi_range(self):
 
409
        out = self.get_response(_multipart_range_response)
 
410
        self.assertIsInstance(out, response.HttpMultipartRangeResponse)
 
411
 
 
412
        # Just make sure we can read the right contents
 
413
        out.seek(0)
 
414
        out.read(255)
 
415
 
 
416
        out.seek(1000)
 
417
        out.read(1050)
 
418
 
 
419
    def test_multi_squid_range(self):
 
420
        out = self.get_response(_multipart_squid_range_response)
 
421
        self.assertIsInstance(out, response.HttpMultipartRangeResponse)
 
422
 
 
423
        # Just make sure we can read the right contents
 
424
        out.seek(0)
 
425
        out.read(100)
 
426
 
 
427
        out.seek(300)
 
428
        out.read(200)
 
429
 
 
430
    def test_full_text_no_content_type(self):
 
431
        # We should not require Content-Type for a full response
 
432
        a_response = _full_text_response
 
433
        headers = http._extract_headers(a_response[1], 'http://foo')
 
434
        del headers['Content-Type']
 
435
        out = response.handle_response('http://foo', a_response[0], headers,
 
436
                                        StringIO(a_response[2]))
 
437
        self.assertEqual(_full_text_response[2], out.read())
 
438
 
 
439
    def test_missing_content_range(self):
 
440
        a_response = _single_range_response
 
441
        headers = http._extract_headers(a_response[1], 'http://nocontent')
 
442
        del headers['Content-Range']
 
443
        self.assertRaises(errors.InvalidHttpResponse,
 
444
            response.handle_response, 'http://nocontent', a_response[0],
 
445
                                      headers, StringIO(a_response[2]))