~bzr-pqm/bzr/bzr.dev

1185.16.68 by Martin Pool
- http url fixes suggested by Robey Pointer, and tests
1
# (C) 2005 Canonical
2
1540.3.3 by Martin Pool
Review updates of pycurl transport
3
# FIXME: This test should be repeated for each available http client
4
# implementation; at the moment we have urllib and pycurl.
5
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
6
from bzrlib.tests import TestCase
1540.3.3 by Martin Pool
Review updates of pycurl transport
7
from bzrlib.transport.http import extract_auth
8
from bzrlib.transport.http._urllib import HttpTransport
1185.40.20 by Robey Pointer
allow user:pass@ info in http urls to be used for auth; this should be easily expandable later to use auth config files
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
        
1185.16.68 by Martin Pool
- http url fixes suggested by Robey Pointer, and tests
18
class TestHttpUrls(TestCase):
1185.40.20 by Robey Pointer
allow user:pass@ info in http urls to be used for auth; this should be easily expandable later to use auth config files
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
        
1185.16.68 by Martin Pool
- http url fixes suggested by Robey Pointer, and tests
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')