/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Robert Collins
  • Date: 2006-03-03 02:09:49 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060303020949-0ddc6f33d0a43943
Smoke test for RevisionStore factories creating revision stores.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
# FIXME: This test should be repeated for each available http client
18
 
# implementation; at the moment we have urllib and pycurl.
19
 
 
20
 
# TODO: Should be renamed to bzrlib.transport.http.tests?
 
1
# (C) 2005 Canonical
21
2
 
22
3
import bzrlib
23
 
from bzrlib.errors import DependencyNotPresent
24
 
from bzrlib.tests import TestCase, TestSkipped
25
 
from bzrlib.transport import Transport
26
 
from bzrlib.transport.http import extract_auth
27
 
from bzrlib.transport.http._urllib import HttpTransport_urllib
 
4
from bzrlib.tests import TestCase
28
5
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
 
6
from bzrlib.transport.http import HttpTransport, extract_auth
29
7
 
30
8
class FakeManager (object):
31
9
    def __init__(self):
48
26
        
49
27
    def test_abs_url(self):
50
28
        """Construction of absolute http URLs"""
51
 
        t = HttpTransport_urllib('http://bazaar-ng.org/bzr/bzr.dev/')
 
29
        t = HttpTransport('http://bazaar-ng.org/bzr/bzr.dev/')
52
30
        eq = self.assertEqualDiff
53
31
        eq(t.abspath('.'),
54
32
           'http://bazaar-ng.org/bzr/bzr.dev')
61
39
 
62
40
    def test_invalid_http_urls(self):
63
41
        """Trap invalid construction of urls"""
64
 
        t = HttpTransport_urllib('http://bazaar-ng.org/bzr/bzr.dev/')
 
42
        t = HttpTransport('http://bazaar-ng.org/bzr/bzr.dev/')
65
43
        self.assertRaises(ValueError,
66
44
            t.abspath,
67
45
            '.bzr/')
71
49
 
72
50
    def test_http_root_urls(self):
73
51
        """Construction of URLs from server root"""
74
 
        t = HttpTransport_urllib('http://bzr.ozlabs.org/')
 
52
        t = HttpTransport('http://bzr.ozlabs.org/')
75
53
        eq = self.assertEqualDiff
76
54
        eq(t.abspath('.bzr/tree-version'),
77
55
           'http://bzr.ozlabs.org/.bzr/tree-version')
78
56
 
79
 
    def test_http_impl_urls(self):
80
 
        """There are servers which ask for particular clients to connect"""
81
 
        try:
82
 
            from bzrlib.transport.http._pycurl import HttpServer_PyCurl
83
 
            server = HttpServer_PyCurl()
84
 
            try:
85
 
                server.setUp()
86
 
                url = server.get_url()
87
 
                self.assertTrue(url.startswith('http+pycurl://'))
88
 
            finally:
89
 
                server.tearDown()
90
 
        except DependencyNotPresent:
91
 
            raise TestSkipped('pycurl not present')
92
 
 
93
 
class TestHttpMixins(object):
94
 
 
95
 
    def _prep_tree(self):
96
 
        self.build_tree(['xxx', 'foo/', 'foo/bar'], line_endings='binary',
97
 
                        transport=self.get_transport())
 
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')
98
63
 
99
64
    def test_http_has(self):
100
65
        server = self.get_readonly_server()
101
 
        t = self._transport(server.get_url())
 
66
        t = HttpTransport(server.get_url())
102
67
        self.assertEqual(t.has('foo/bar'), True)
103
68
        self.assertEqual(len(server.logs), 1)
104
 
        self.assertContainsRe(server.logs[0], 
105
 
            r'"HEAD /foo/bar HTTP/1.." (200|302) - "-" "bzr/')
 
69
        self.assertTrue(server.logs[0].endswith(
 
70
            '"HEAD /foo/bar HTTP/1.1" 200 - "-" "bzr/%s"'
 
71
            % bzrlib.__version__))
106
72
 
107
 
    def test_http_has_not_found(self):
108
 
        server = self.get_readonly_server()
109
 
        t = self._transport(server.get_url())
110
73
        self.assertEqual(t.has('not-found'), False)
111
 
        self.assertContainsRe(server.logs[1], 
112
 
            r'"HEAD /not-found HTTP/1.." 404 - "-" "bzr/')
 
74
        self.assertTrue(server.logs[-1].endswith(
 
75
            '"HEAD /not-found HTTP/1.1" 404 - "-" "bzr/%s"'
 
76
            % bzrlib.__version__))
113
77
 
114
78
    def test_http_get(self):
115
79
        server = self.get_readonly_server()
116
 
        t = self._transport(server.get_url())
 
80
        t = HttpTransport(server.get_url())
117
81
        fp = t.get('foo/bar')
118
82
        self.assertEqualDiff(
119
83
            fp.read(),
120
84
            'contents of foo/bar\n')
121
85
        self.assertEqual(len(server.logs), 1)
122
 
        self.assertTrue(server.logs[0].find(
123
 
            '"GET /foo/bar HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__) > -1)
124
 
 
125
 
 
126
 
class TestHttpConnections_urllib(TestCaseWithWebserver, TestHttpMixins):
127
 
    _transport = HttpTransport_urllib
128
 
 
129
 
    def setUp(self):
130
 
        TestCaseWithWebserver.setUp(self)
131
 
        self._prep_tree()
132
 
 
133
 
 
134
 
 
135
 
class TestHttpConnections_pycurl(TestCaseWithWebserver, TestHttpMixins):
136
 
 
137
 
    def _get_pycurl_maybe(self):
138
 
        try:
139
 
            from bzrlib.transport.http._pycurl import PyCurlTransport
140
 
            return PyCurlTransport
141
 
        except DependencyNotPresent:
142
 
            raise TestSkipped('pycurl not present')
143
 
 
144
 
    _transport = property(_get_pycurl_maybe)
145
 
 
146
 
    def setUp(self):
147
 
        TestCaseWithWebserver.setUp(self)
148
 
        self._prep_tree()
149
 
 
150
 
 
151
 
 
152
 
class TestHttpTransportRegistration(TestCase):
153
 
    """Test registrations of various http implementations"""
154
 
 
155
 
    def test_http_registered(self):
156
 
        import bzrlib.transport.http._urllib
157
 
        from bzrlib.transport import get_transport
158
 
        # urlllib should always be present
159
 
        t = get_transport('http+urllib://bzr.google.com/')
160
 
        self.assertIsInstance(t, Transport)
161
 
        self.assertIsInstance(t, bzrlib.transport.http._urllib.HttpTransport_urllib)
 
86
        self.assertTrue(server.logs[0].endswith(
 
87
            '"GET /foo/bar HTTP/1.1" 200 - "-" "bzr/%s"' % bzrlib.__version__))