1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
1 |
# (C) 2005 Canonical
|
2 |
||
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
3 |
from bzrlib.tests import 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 |
4 |
from bzrlib.transport.http import HttpTransport, extract_auth |
5 |
||
6 |
class FakeManager (object): |
|
7 |
def __init__(self): |
|
8 |
self.credentials = [] |
|
9 |
||
10 |
def add_password(self, realm, host, username, password): |
|
11 |
self.credentials.append([realm, host, username, password]) |
|
12 |
||
13 |
||
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
14 |
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 |
15 |
def test_url_parsing(self): |
16 |
f = FakeManager() |
|
17 |
url = extract_auth('http://example.com', f) |
|
18 |
self.assertEquals('http://example.com', url) |
|
19 |
self.assertEquals(0, len(f.credentials)) |
|
20 |
url = extract_auth('http://user:pass@www.bazaar-ng.org/bzr/bzr.dev', f) |
|
21 |
self.assertEquals('http://www.bazaar-ng.org/bzr/bzr.dev', url) |
|
22 |
self.assertEquals(1, len(f.credentials)) |
|
23 |
self.assertEquals([None, 'www.bazaar-ng.org', 'user', 'pass'], f.credentials[0]) |
|
24 |
||
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
25 |
def test_abs_url(self): |
26 |
"""Construction of absolute http URLs"""
|
|
27 |
t = HttpTransport('http://bazaar-ng.org/bzr/bzr.dev/') |
|
28 |
eq = self.assertEqualDiff |
|
29 |
eq(t.abspath('.'), |
|
30 |
'http://bazaar-ng.org/bzr/bzr.dev') |
|
31 |
eq(t.abspath('foo/bar'), |
|
32 |
'http://bazaar-ng.org/bzr/bzr.dev/foo/bar') |
|
33 |
eq(t.abspath('.bzr'), |
|
34 |
'http://bazaar-ng.org/bzr/bzr.dev/.bzr') |
|
35 |
eq(t.abspath('.bzr/1//2/./3'), |
|
36 |
'http://bazaar-ng.org/bzr/bzr.dev/.bzr/1/2/3') |
|
37 |
||
38 |
def test_invalid_http_urls(self): |
|
39 |
"""Trap invalid construction of urls"""
|
|
40 |
t = HttpTransport('http://bazaar-ng.org/bzr/bzr.dev/') |
|
41 |
self.assertRaises(ValueError, |
|
42 |
t.abspath, |
|
43 |
'.bzr/') |
|
44 |
self.assertRaises(ValueError, |
|
45 |
t.abspath, |
|
46 |
'/.bzr') |
|
47 |
||
48 |
def test_http_root_urls(self): |
|
49 |
"""Construction of URLs from server root"""
|
|
50 |
t = HttpTransport('http://bzr.ozlabs.org/') |
|
51 |
eq = self.assertEqualDiff |
|
52 |
eq(t.abspath('.bzr/tree-version'), |
|
53 |
'http://bzr.ozlabs.org/.bzr/tree-version') |