1
# Copyright (C) 2005, 2006 Canonical
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.
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.
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
3
17
# FIXME: This test should be repeated for each available http client
4
18
# implementation; at the moment we have urllib and pycurl.
6
21
from bzrlib.tests import TestCase
7
22
from bzrlib.transport.http import extract_auth
8
23
from bzrlib.transport.http._urllib import HttpTransport
24
from bzrlib.transport.http._pycurl import PyCurlTransport
25
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
10
27
class FakeManager (object):
11
28
def __init__(self):
14
31
def add_password(self, realm, host, username, password):
15
32
self.credentials.append([realm, host, username, password])
18
35
class TestHttpUrls(TestCase):
19
36
def test_url_parsing(self):
55
72
eq = self.assertEqualDiff
56
73
eq(t.abspath('.bzr/tree-version'),
57
74
'http://bzr.ozlabs.org/.bzr/tree-version')
77
class TestHttpConnections(TestCaseWithWebserver):
79
_transport = HttpTransport
82
super(TestHttpConnections, self).setUp()
83
self.build_tree(['xxx', 'foo/', 'foo/bar'], line_endings='binary')
85
def test_http_has(self):
86
server = self.get_readonly_server()
87
t = self._transport(server.get_url())
88
self.assertEqual(t.has('foo/bar'), True)
89
self.assertEqual(len(server.logs), 1)
90
self.assertContainsRe(server.logs[0],
91
r'"HEAD /foo/bar HTTP/1.." (200|302) - "-" "bzr/')
93
def test_http_has_not_found(self):
94
server = self.get_readonly_server()
95
t = self._transport(server.get_url())
96
self.assertEqual(t.has('not-found'), False)
97
self.assertContainsRe(server.logs[1],
98
r'"HEAD /not-found HTTP/1.." 404 - "-" "bzr/')
100
def test_http_get(self):
101
server = self.get_readonly_server()
102
t = self._transport(server.get_url())
103
fp = t.get('foo/bar')
104
self.assertEqualDiff(
106
'contents of foo/bar\n')
107
self.assertEqual(len(server.logs), 1)
108
self.assertTrue(server.logs[0].find(
109
'"GET /foo/bar HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__) > -1)
112
class TestHttpConnections_pycurl(TestHttpConnections):
113
_transport = PyCurlTransport
116
super(TestHttpConnections_pycurl, self).setUp()