~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Robert Collins
  • Date: 2006-03-01 03:26:23 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060301032623-9d3c073e102f2239
Move WeaveStore down into bzrlib.store.versioned.weave.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# (C) 2005 Canonical
 
2
 
 
3
import bzrlib
 
4
from bzrlib.tests import TestCase
 
5
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
 
6
from bzrlib.transport.http import HttpTransport, extract_auth
 
7
 
 
8
class FakeManager (object):
 
9
    def __init__(self):
 
10
        self.credentials = []
 
11
        
 
12
    def add_password(self, realm, host, username, password):
 
13
        self.credentials.append([realm, host, username, password])
 
14
 
 
15
 
 
16
class TestHttpUrls(TestCase):
 
17
    def test_url_parsing(self):
 
18
        f = FakeManager()
 
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])
 
26
        
 
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
 
31
        eq(t.abspath('.'),
 
32
           'http://bazaar-ng.org/bzr/bzr.dev')
 
33
        eq(t.abspath('foo/bar'), 
 
34
           'http://bazaar-ng.org/bzr/bzr.dev/foo/bar')
 
35
        eq(t.abspath('.bzr'),
 
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')
 
39
 
 
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,
 
44
            t.abspath,
 
45
            '.bzr/')
 
46
        self.assertRaises(ValueError,
 
47
            t.abspath,
 
48
            '/.bzr')
 
49
 
 
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')
 
56
 
 
57
 
 
58
class TestHttpConnections(TestCaseWithWebserver):
 
59
 
 
60
    def setUp(self):
 
61
        super(TestHttpConnections, self).setUp()
 
62
        self.build_tree(['xxx', 'foo/', 'foo/bar'], line_endings='binary')
 
63
 
 
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__))
 
72
 
 
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__))
 
77
 
 
78
    def test_http_get(self):
 
79
        server = self.get_readonly_server()
 
80
        t = HttpTransport(server.get_url())
 
81
        fp = t.get('foo/bar')
 
82
        self.assertEqualDiff(
 
83
            fp.read(),
 
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__))