1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
1 |
# Copyright (C) 2005, 2006 Canonical
|
1540.3.24
by Martin Pool
Add new protocol 'http+pycurl' that always uses PyCurl. |
2 |
#
|
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
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.
|
|
1540.3.24
by Martin Pool
Add new protocol 'http+pycurl' that always uses PyCurl. |
7 |
#
|
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
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.
|
|
1540.3.24
by Martin Pool
Add new protocol 'http+pycurl' that always uses PyCurl. |
12 |
#
|
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
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
|
|
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
16 |
|
1540.3.3
by Martin Pool
Review updates of pycurl transport |
17 |
# FIXME: This test should be repeated for each available http client
|
18 |
# implementation; at the moment we have urllib and pycurl.
|
|
19 |
||
1540.3.22
by Martin Pool
[patch] Add TestCase.assertIsInstance |
20 |
# TODO: Should be renamed to bzrlib.transport.http.tests?
|
21 |
||
1553.1.2
by James Henstridge
Add a test to make sure the user-agent header is being sent correctly. |
22 |
import bzrlib |
1540.3.30
by Martin Pool
Fix up bogus-url tests for broken dns servers, and error imports |
23 |
from bzrlib.errors import DependencyNotPresent |
24 |
from bzrlib.tests import TestCase, TestSkipped |
|
1540.3.23
by Martin Pool
Allow urls like http+pycurl://host/ to use a particular impl |
25 |
from bzrlib.transport import Transport |
1540.3.3
by Martin Pool
Review updates of pycurl transport |
26 |
from bzrlib.transport.http import extract_auth |
1540.3.26
by Martin Pool
[merge] bzr.dev; pycurl not updated for readv yet |
27 |
from bzrlib.transport.http._urllib import HttpTransport_urllib |
1553.1.3
by James Henstridge
Make bzrlib.transport.http.HttpServer output referer and user agent as in |
28 |
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver |
1185.40.20
by Robey Pointer
allow user:pass@ info in http urls to be used for auth; this should be easily expandable later to use auth config files |
29 |
|
30 |
class FakeManager (object): |
|
31 |
def __init__(self): |
|
32 |
self.credentials = [] |
|
33 |
||
34 |
def add_password(self, realm, host, username, password): |
|
35 |
self.credentials.append([realm, host, username, password]) |
|
36 |
||
1553.1.2
by James Henstridge
Add a test to make sure the user-agent header is being sent correctly. |
37 |
|
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
38 |
class TestHttpUrls(TestCase): |
1185.40.20
by Robey Pointer
allow user:pass@ info in http urls to be used for auth; this should be easily expandable later to use auth config files |
39 |
def test_url_parsing(self): |
40 |
f = FakeManager() |
|
41 |
url = extract_auth('http://example.com', f) |
|
42 |
self.assertEquals('http://example.com', url) |
|
43 |
self.assertEquals(0, len(f.credentials)) |
|
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
44 |
url = extract_auth('http://user:pass@www.bazaar-vcs.org/bzr/bzr.dev', f) |
45 |
self.assertEquals('http://www.bazaar-vcs.org/bzr/bzr.dev', url) |
|
1185.40.20
by Robey Pointer
allow user:pass@ info in http urls to be used for auth; this should be easily expandable later to use auth config files |
46 |
self.assertEquals(1, len(f.credentials)) |
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
47 |
self.assertEquals([None, 'www.bazaar-vcs.org', 'user', 'pass'], f.credentials[0]) |
1185.40.20
by Robey Pointer
allow user:pass@ info in http urls to be used for auth; this should be easily expandable later to use auth config files |
48 |
|
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
49 |
def test_abs_url(self): |
50 |
"""Construction of absolute http URLs"""
|
|
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
51 |
t = HttpTransport_urllib('http://bazaar-vcs.org/bzr/bzr.dev/') |
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
52 |
eq = self.assertEqualDiff |
53 |
eq(t.abspath('.'), |
|
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
54 |
'http://bazaar-vcs.org/bzr/bzr.dev') |
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
55 |
eq(t.abspath('foo/bar'), |
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
56 |
'http://bazaar-vcs.org/bzr/bzr.dev/foo/bar') |
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
57 |
eq(t.abspath('.bzr'), |
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
58 |
'http://bazaar-vcs.org/bzr/bzr.dev/.bzr') |
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
59 |
eq(t.abspath('.bzr/1//2/./3'), |
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
60 |
'http://bazaar-vcs.org/bzr/bzr.dev/.bzr/1/2/3') |
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
61 |
|
62 |
def test_invalid_http_urls(self): |
|
63 |
"""Trap invalid construction of urls"""
|
|
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
64 |
t = HttpTransport_urllib('http://bazaar-vcs.org/bzr/bzr.dev/') |
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
65 |
self.assertRaises(ValueError, |
66 |
t.abspath, |
|
67 |
'.bzr/') |
|
68 |
self.assertRaises(ValueError, |
|
69 |
t.abspath, |
|
70 |
'/.bzr') |
|
71 |
||
72 |
def test_http_root_urls(self): |
|
73 |
"""Construction of URLs from server root"""
|
|
1540.3.26
by Martin Pool
[merge] bzr.dev; pycurl not updated for readv yet |
74 |
t = HttpTransport_urllib('http://bzr.ozlabs.org/') |
1185.16.68
by Martin Pool
- http url fixes suggested by Robey Pointer, and tests |
75 |
eq = self.assertEqualDiff |
76 |
eq(t.abspath('.bzr/tree-version'), |
|
77 |
'http://bzr.ozlabs.org/.bzr/tree-version') |
|
1553.1.2
by James Henstridge
Add a test to make sure the user-agent header is being sent correctly. |
78 |
|
1540.3.24
by Martin Pool
Add new protocol 'http+pycurl' that always uses PyCurl. |
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() |
|
1540.3.30
by Martin Pool
Fix up bogus-url tests for broken dns servers, and error imports |
90 |
except DependencyNotPresent: |
1540.3.24
by Martin Pool
Add new protocol 'http+pycurl' that always uses PyCurl. |
91 |
raise TestSkipped('pycurl not present') |
1553.1.2
by James Henstridge
Add a test to make sure the user-agent header is being sent correctly. |
92 |
|
1540.3.33
by Martin Pool
Fix http tests that were failing to run tearDown when setup got a missing dependency |
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()) |
|
1553.1.2
by James Henstridge
Add a test to make sure the user-agent header is being sent correctly. |
98 |
|
99 |
def test_http_has(self): |
|
1185.50.84
by John Arbash Meinel
[merge] bzr.dev, cleanup conflicts, fixup http tests for new TestCase layout. |
100 |
server = self.get_readonly_server() |
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
101 |
t = self._transport(server.get_url()) |
1553.1.2
by James Henstridge
Add a test to make sure the user-agent header is being sent correctly. |
102 |
self.assertEqual(t.has('foo/bar'), True) |
1185.50.84
by John Arbash Meinel
[merge] bzr.dev, cleanup conflicts, fixup http tests for new TestCase layout. |
103 |
self.assertEqual(len(server.logs), 1) |
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
104 |
self.assertContainsRe(server.logs[0], |
105 |
r'"HEAD /foo/bar HTTP/1.." (200|302) - "-" "bzr/') |
|
1553.1.5
by James Henstridge
Make HTTP transport has() method do HEAD requests, and update test to |
106 |
|
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
107 |
def test_http_has_not_found(self): |
108 |
server = self.get_readonly_server() |
|
109 |
t = self._transport(server.get_url()) |
|
1553.1.5
by James Henstridge
Make HTTP transport has() method do HEAD requests, and update test to |
110 |
self.assertEqual(t.has('not-found'), False) |
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
111 |
self.assertContainsRe(server.logs[1], |
112 |
r'"HEAD /not-found HTTP/1.." 404 - "-" "bzr/') |
|
1553.1.2
by James Henstridge
Add a test to make sure the user-agent header is being sent correctly. |
113 |
|
114 |
def test_http_get(self): |
|
1185.50.84
by John Arbash Meinel
[merge] bzr.dev, cleanup conflicts, fixup http tests for new TestCase layout. |
115 |
server = self.get_readonly_server() |
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
116 |
t = self._transport(server.get_url()) |
1553.1.2
by James Henstridge
Add a test to make sure the user-agent header is being sent correctly. |
117 |
fp = t.get('foo/bar') |
118 |
self.assertEqualDiff( |
|
119 |
fp.read(), |
|
1553.1.3
by James Henstridge
Make bzrlib.transport.http.HttpServer output referer and user agent as in |
120 |
'contents of foo/bar\n') |
1185.50.84
by John Arbash Meinel
[merge] bzr.dev, cleanup conflicts, fixup http tests for new TestCase layout. |
121 |
self.assertEqual(len(server.logs), 1) |
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
122 |
self.assertTrue(server.logs[0].find( |
123 |
'"GET /foo/bar HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__) > -1) |
|
124 |
||
125 |
||
1540.3.33
by Martin Pool
Fix http tests that were failing to run tearDown when setup got a missing dependency |
126 |
class TestHttpConnections_urllib(TestCaseWithWebserver, TestHttpMixins): |
127 |
_transport = HttpTransport_urllib |
|
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
128 |
|
129 |
def setUp(self): |
|
1540.3.33
by Martin Pool
Fix http tests that were failing to run tearDown when setup got a missing dependency |
130 |
TestCaseWithWebserver.setUp(self) |
131 |
self._prep_tree() |
|
132 |
||
133 |
||
134 |
||
135 |
class TestHttpConnections_pycurl(TestCaseWithWebserver, TestHttpMixins): |
|
136 |
||
137 |
def _get_pycurl_maybe(self): |
|
1540.3.29
by Martin Pool
Prevent selftest failure when pycurl is not installed |
138 |
try: |
139 |
from bzrlib.transport.http._pycurl import PyCurlTransport |
|
1612.1.1
by Martin Pool
Raise errors correctly on pycurl connection failure |
140 |
return PyCurlTransport |
1540.3.30
by Martin Pool
Fix up bogus-url tests for broken dns servers, and error imports |
141 |
except DependencyNotPresent: |
1540.3.29
by Martin Pool
Prevent selftest failure when pycurl is not installed |
142 |
raise TestSkipped('pycurl not present') |
1540.3.15
by Martin Pool
[merge] large merge to sync with bzr.dev |
143 |
|
1540.3.33
by Martin Pool
Fix http tests that were failing to run tearDown when setup got a missing dependency |
144 |
_transport = property(_get_pycurl_maybe) |
145 |
||
146 |
def setUp(self): |
|
147 |
TestCaseWithWebserver.setUp(self) |
|
148 |
self._prep_tree() |
|
149 |
||
150 |
||
1540.3.23
by Martin Pool
Allow urls like http+pycurl://host/ to use a particular impl |
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) |
|
1540.3.26
by Martin Pool
[merge] bzr.dev; pycurl not updated for readv yet |
161 |
self.assertIsInstance(t, bzrlib.transport.http._urllib.HttpTransport_urllib) |