4
from bzrlib.tests import TestCase
5
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
6
from bzrlib.transport.http import HttpTransport, extract_auth
8
class FakeManager (object):
12
def add_password(self, realm, host, username, password):
13
self.credentials.append([realm, host, username, password])
16
class TestHttpUrls(TestCase):
17
def test_url_parsing(self):
19
url = extract_auth('http://example.com', f)
20
self.assertEquals('http://example.com', url)
21
self.assertEquals(0, len(f.credentials))
22
url = extract_auth('http://user:pass@www.bazaar-ng.org/bzr/bzr.dev', f)
23
self.assertEquals('http://www.bazaar-ng.org/bzr/bzr.dev', url)
24
self.assertEquals(1, len(f.credentials))
25
self.assertEquals([None, 'www.bazaar-ng.org', 'user', 'pass'], f.credentials[0])
27
def test_abs_url(self):
28
"""Construction of absolute http URLs"""
29
t = HttpTransport('http://bazaar-ng.org/bzr/bzr.dev/')
30
eq = self.assertEqualDiff
32
'http://bazaar-ng.org/bzr/bzr.dev')
33
eq(t.abspath('foo/bar'),
34
'http://bazaar-ng.org/bzr/bzr.dev/foo/bar')
36
'http://bazaar-ng.org/bzr/bzr.dev/.bzr')
37
eq(t.abspath('.bzr/1//2/./3'),
38
'http://bazaar-ng.org/bzr/bzr.dev/.bzr/1/2/3')
40
def test_invalid_http_urls(self):
41
"""Trap invalid construction of urls"""
42
t = HttpTransport('http://bazaar-ng.org/bzr/bzr.dev/')
43
self.assertRaises(ValueError,
46
self.assertRaises(ValueError,
50
def test_http_root_urls(self):
51
"""Construction of URLs from server root"""
52
t = HttpTransport('http://bzr.ozlabs.org/')
53
eq = self.assertEqualDiff
54
eq(t.abspath('.bzr/tree-version'),
55
'http://bzr.ozlabs.org/.bzr/tree-version')
58
class TestHttpConnections(TestCaseWithWebserver):
61
super(TestHttpConnections, self).setUp()
62
self.build_tree(['xxx', 'foo/', 'foo/bar'], line_endings='binary')
64
def test_http_has(self):
65
server = self.get_readonly_server()
66
t = HttpTransport(server.get_url())
67
self.assertEqual(t.has('foo/bar'), True)
68
self.assertEqual(len(server.logs), 1)
69
self.assertTrue(server.logs[0].endswith(
70
'"HEAD /foo/bar HTTP/1.1" 200 - "-" "bzr/%s"'
71
% bzrlib.__version__))
73
self.assertEqual(t.has('not-found'), False)
74
self.assertTrue(server.logs[-1].endswith(
75
'"HEAD /not-found HTTP/1.1" 404 - "-" "bzr/%s"'
76
% bzrlib.__version__))
78
def test_http_get(self):
79
server = self.get_readonly_server()
80
t = HttpTransport(server.get_url())
84
'contents of foo/bar\n')
85
self.assertEqual(len(server.logs), 1)
86
self.assertTrue(server.logs[0].endswith(
87
'"GET /foo/bar HTTP/1.1" 200 - "-" "bzr/%s"' % bzrlib.__version__))