~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-02-22 04:29:54 UTC
  • mfrom: (1566 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1569.
  • Revision ID: mbp@sourcefrog.net-20060222042954-60333f08dd56a646
[merge] from bzr.dev before integration
Fix undefined ordering in sign_my_revisions breaking tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# (C) 2005 Canonical
2
2
 
 
3
import bzrlib
3
4
from bzrlib.tests import TestCase
 
5
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
4
6
from bzrlib.transport.http import HttpTransport, extract_auth
5
7
 
6
8
class FakeManager (object):
10
12
    def add_password(self, realm, host, username, password):
11
13
        self.credentials.append([realm, host, username, password])
12
14
 
13
 
        
 
15
 
14
16
class TestHttpUrls(TestCase):
15
17
    def test_url_parsing(self):
16
18
        f = FakeManager()
51
53
        eq = self.assertEqualDiff
52
54
        eq(t.abspath('.bzr/tree-version'),
53
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__))