~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Martin Pool
  • Date: 2006-01-13 09:57:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060113095713-1fa5912229a3898e
Review updates of pycurl transport

Split them out into 

  bzrlib.transport.http             common base
  bzrlib.transport.http._urllib     pure python
  bzrlib.transport.http._pycurl     calls pycurl

Update to work with robert's nice transport test multiplexer.

Add PyCurlTransport.has() which does just a HEAD request; should be faster.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# (C) 2005 Canonical
 
2
 
 
3
# FIXME: This test should be repeated for each available http client
 
4
# implementation; at the moment we have urllib and pycurl.
 
5
 
 
6
from bzrlib.tests import TestCase
 
7
from bzrlib.transport.http import extract_auth
 
8
from bzrlib.transport.http._urllib import HttpTransport
 
9
 
 
10
class FakeManager (object):
 
11
    def __init__(self):
 
12
        self.credentials = []
 
13
        
 
14
    def add_password(self, realm, host, username, password):
 
15
        self.credentials.append([realm, host, username, password])
 
16
 
 
17
        
 
18
class TestHttpUrls(TestCase):
 
19
    def test_url_parsing(self):
 
20
        f = FakeManager()
 
21
        url = extract_auth('http://example.com', f)
 
22
        self.assertEquals('http://example.com', url)
 
23
        self.assertEquals(0, len(f.credentials))
 
24
        url = extract_auth('http://user:pass@www.bazaar-ng.org/bzr/bzr.dev', f)
 
25
        self.assertEquals('http://www.bazaar-ng.org/bzr/bzr.dev', url)
 
26
        self.assertEquals(1, len(f.credentials))
 
27
        self.assertEquals([None, 'www.bazaar-ng.org', 'user', 'pass'], f.credentials[0])
 
28
        
 
29
    def test_abs_url(self):
 
30
        """Construction of absolute http URLs"""
 
31
        t = HttpTransport('http://bazaar-ng.org/bzr/bzr.dev/')
 
32
        eq = self.assertEqualDiff
 
33
        eq(t.abspath('.'),
 
34
           'http://bazaar-ng.org/bzr/bzr.dev')
 
35
        eq(t.abspath('foo/bar'), 
 
36
           'http://bazaar-ng.org/bzr/bzr.dev/foo/bar')
 
37
        eq(t.abspath('.bzr'),
 
38
           'http://bazaar-ng.org/bzr/bzr.dev/.bzr')
 
39
        eq(t.abspath('.bzr/1//2/./3'),
 
40
           'http://bazaar-ng.org/bzr/bzr.dev/.bzr/1/2/3')
 
41
 
 
42
    def test_invalid_http_urls(self):
 
43
        """Trap invalid construction of urls"""
 
44
        t = HttpTransport('http://bazaar-ng.org/bzr/bzr.dev/')
 
45
        self.assertRaises(ValueError,
 
46
            t.abspath,
 
47
            '.bzr/')
 
48
        self.assertRaises(ValueError,
 
49
            t.abspath,
 
50
            '/.bzr')
 
51
 
 
52
    def test_http_root_urls(self):
 
53
        """Construction of URLs from server root"""
 
54
        t = HttpTransport('http://bzr.ozlabs.org/')
 
55
        eq = self.assertEqualDiff
 
56
        eq(t.abspath('.bzr/tree-version'),
 
57
           'http://bzr.ozlabs.org/.bzr/tree-version')