bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
4988.10.5
by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS |
1 |
# Copyright (C) 2005-2010 Canonical Ltd
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
|
907.1.48
by John Arbash Meinel
Updated LocalTransport by passing it through the transport_test suite, and got it to pass. |
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.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
|
907.1.48
by John Arbash Meinel
Updated LocalTransport by passing it through the transport_test suite, and got it to pass. |
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.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
|
907.1.48
by John Arbash Meinel
Updated LocalTransport by passing it through the transport_test suite, and got it to pass. |
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
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
907.1.48
by John Arbash Meinel
Updated LocalTransport by passing it through the transport_test suite, and got it to pass. |
16 |
|
17 |
||
|
1185.11.22
by John Arbash Meinel
Major refactoring of testtransport. |
18 |
from cStringIO import StringIO |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
19 |
import os |
20 |
import subprocess |
|
21 |
import sys |
|
22 |
import threading |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
23 |
|
|
2018.18.4
by Martin Pool
Change Transport.local_abspath to raise NotLocalUrl, and test. |
24 |
from bzrlib import ( |
25 |
errors, |
|
|
2804.4.1
by Alexander Belchenko
some win32-specific fixes for selftest |
26 |
osutils, |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
27 |
tests, |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
28 |
transport, |
|
2018.18.4
by Martin Pool
Change Transport.local_abspath to raise NotLocalUrl, and test. |
29 |
urlutils, |
30 |
)
|
|
|
4634.108.13
by John Arbash Meinel
Add a test case. |
31 |
from bzrlib.transport import ( |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
32 |
chroot, |
|
4946.1.2
by John Arbash Meinel
Clean up a few more imports. |
33 |
fakenfs, |
|
4912.2.4
by Martin Pool
Add test for unhtml_roughly, and truncate at 1000 bytes |
34 |
http, |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
35 |
local, |
|
4634.108.13
by John Arbash Meinel
Add a test case. |
36 |
memory, |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
37 |
pathfilter, |
|
4946.1.2
by John Arbash Meinel
Clean up a few more imports. |
38 |
readonly, |
|
4634.108.13
by John Arbash Meinel
Add a test case. |
39 |
)
|
|
5017.3.22
by Vincent Ladeuil
selftest -s bt.test_transport passing |
40 |
from bzrlib.tests import ( |
41 |
features, |
|
42 |
test_server, |
|
43 |
)
|
|
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
44 |
|
45 |
||
46 |
# TODO: Should possibly split transport-specific tests into their own files.
|
|
|
1185.58.2
by John Arbash Meinel
Added mode to the appropriate transport functions, and tests to make sure they work. |
47 |
|
48 |
||
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
49 |
class TestTransport(tests.TestCase): |
|
1185.58.3
by John Arbash Meinel
code cleanup |
50 |
"""Test the non transport-concrete class functionality.""" |
51 |
||
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
52 |
# FIXME: These tests should use addCleanup() and/or overrideAttr() instead
|
53 |
# of try/finally -- vila 20100205
|
|
54 |
||
|
2241.3.1
by ghigo
uncomment test test__get_set_protocol_handlers |
55 |
def test__get_set_protocol_handlers(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
56 |
handlers = transport._get_protocol_handlers() |
|
2241.3.1
by ghigo
uncomment test test__get_set_protocol_handlers |
57 |
self.assertNotEqual([], handlers.keys( )) |
58 |
try: |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
59 |
transport._clear_protocol_handlers() |
60 |
self.assertEqual([], transport._get_protocol_handlers().keys()) |
|
|
2241.3.1
by ghigo
uncomment test test__get_set_protocol_handlers |
61 |
finally: |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
62 |
transport._set_protocol_handlers(handlers) |
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
63 |
|
64 |
def test_get_transport_modules(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
65 |
handlers = transport._get_protocol_handlers() |
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
66 |
# don't pollute the current handlers
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
67 |
transport._clear_protocol_handlers() |
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
68 |
class SampleHandler(object): |
69 |
"""I exist, isnt that enough?""" |
|
70 |
try: |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
71 |
transport._clear_protocol_handlers() |
72 |
transport.register_transport_proto('foo') |
|
73 |
transport.register_lazy_transport('foo', |
|
74 |
'bzrlib.tests.test_transport', |
|
75 |
'TestTransport.SampleHandler') |
|
76 |
transport.register_transport_proto('bar') |
|
77 |
transport.register_lazy_transport('bar', |
|
78 |
'bzrlib.tests.test_transport', |
|
79 |
'TestTransport.SampleHandler') |
|
|
3004.2.1
by Vincent Ladeuil
Fix 150860 by leaving port as user specified it. |
80 |
self.assertEqual([SampleHandler.__module__, |
|
4634.43.21
by Andrew Bennetts
Update test_get_transport_modules for pathfilter. |
81 |
'bzrlib.transport.chroot', |
82 |
'bzrlib.transport.pathfilter'], |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
83 |
transport._get_transport_modules()) |
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
84 |
finally: |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
85 |
transport._set_protocol_handlers(handlers) |
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
86 |
|
87 |
def test_transport_dependency(self): |
|
88 |
"""Transport with missing dependency causes no error""" |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
89 |
saved_handlers = transport._get_protocol_handlers() |
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
90 |
# don't pollute the current handlers
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
91 |
transport._clear_protocol_handlers() |
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
92 |
try: |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
93 |
transport.register_transport_proto('foo') |
94 |
transport.register_lazy_transport( |
|
95 |
'foo', 'bzrlib.tests.test_transport', 'BadTransportHandler') |
|
|
1843.1.1
by John Arbash Meinel
Update get_transport to raise a nicer error which includes dependency info |
96 |
try: |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
97 |
transport.get_transport('foo://fooserver/foo') |
98 |
except errors.UnsupportedProtocol, e: |
|
|
1843.1.1
by John Arbash Meinel
Update get_transport to raise a nicer error which includes dependency info |
99 |
e_str = str(e) |
100 |
self.assertEquals('Unsupported protocol' |
|
101 |
' for url "foo://fooserver/foo":'
|
|
102 |
' Unable to import library "some_lib":'
|
|
103 |
' testing missing dependency', str(e)) |
|
104 |
else: |
|
105 |
self.fail('Did not raise UnsupportedProtocol') |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
106 |
finally: |
|
1540.3.10
by Martin Pool
[broken] keep hooking pycurl into test framework |
107 |
# restore original values
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
108 |
transport._set_protocol_handlers(saved_handlers) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
109 |
|
|
1540.3.10
by Martin Pool
[broken] keep hooking pycurl into test framework |
110 |
def test_transport_fallback(self): |
111 |
"""Transport with missing dependency causes no error""" |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
112 |
saved_handlers = transport._get_protocol_handlers() |
|
1540.3.10
by Martin Pool
[broken] keep hooking pycurl into test framework |
113 |
try: |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
114 |
transport._clear_protocol_handlers() |
115 |
transport.register_transport_proto('foo') |
|
116 |
transport.register_lazy_transport( |
|
117 |
'foo', 'bzrlib.tests.test_transport', 'BackupTransportHandler') |
|
118 |
transport.register_lazy_transport( |
|
119 |
'foo', 'bzrlib.tests.test_transport', 'BadTransportHandler') |
|
120 |
t = transport.get_transport('foo://fooserver/foo') |
|
|
1540.3.10
by Martin Pool
[broken] keep hooking pycurl into test framework |
121 |
self.assertTrue(isinstance(t, BackupTransportHandler)) |
122 |
finally: |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
123 |
transport._set_protocol_handlers(saved_handlers) |
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
124 |
|
|
4011.4.1
by Jelmer Vernooij
Point out bzr+ssh:// to the user when they use ssh://. |
125 |
def test_ssh_hints(self): |
126 |
"""Transport ssh:// should raise an error pointing out bzr+ssh://""" |
|
127 |
try: |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
128 |
transport.get_transport('ssh://fooserver/foo') |
129 |
except errors.UnsupportedProtocol, e: |
|
|
4011.4.1
by Jelmer Vernooij
Point out bzr+ssh:// to the user when they use ssh://. |
130 |
e_str = str(e) |
131 |
self.assertEquals('Unsupported protocol' |
|
132 |
' for url "ssh://fooserver/foo":'
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
133 |
' bzr supports bzr+ssh to operate over ssh,'
|
134 |
' use "bzr+ssh://fooserver/foo".', |
|
|
4011.4.1
by Jelmer Vernooij
Point out bzr+ssh:// to the user when they use ssh://. |
135 |
str(e)) |
136 |
else: |
|
137 |
self.fail('Did not raise UnsupportedProtocol') |
|
138 |
||
|
2052.6.1
by Robert Collins
``Transport.get`` has had its interface made more clear for ease of use. |
139 |
def test_LateReadError(self): |
140 |
"""The LateReadError helper should raise on read().""" |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
141 |
a_file = transport.LateReadError('a path') |
|
2052.6.1
by Robert Collins
``Transport.get`` has had its interface made more clear for ease of use. |
142 |
try: |
143 |
a_file.read() |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
144 |
except errors.ReadError, error: |
|
2052.6.1
by Robert Collins
``Transport.get`` has had its interface made more clear for ease of use. |
145 |
self.assertEqual('a path', error.path) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
146 |
self.assertRaises(errors.ReadError, a_file.read, 40) |
|
2052.6.1
by Robert Collins
``Transport.get`` has had its interface made more clear for ease of use. |
147 |
a_file.close() |
148 |
||
|
1996.3.20
by John Arbash Meinel
[merge] bzr.dev 2063 |
149 |
def test__combine_paths(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
150 |
t = transport.Transport('/') |
|
1996.3.20
by John Arbash Meinel
[merge] bzr.dev 2063 |
151 |
self.assertEqual('/home/sarah/project/foo', |
152 |
t._combine_paths('/home/sarah', 'project/foo')) |
|
153 |
self.assertEqual('/etc', |
|
154 |
t._combine_paths('/home/sarah', '../../etc')) |
|
|
2070.3.2
by Andrew Bennetts
Merge from bzr.dev |
155 |
self.assertEqual('/etc', |
156 |
t._combine_paths('/home/sarah', '../../../etc')) |
|
157 |
self.assertEqual('/etc', |
|
158 |
t._combine_paths('/home/sarah', '/etc')) |
|
|
1996.3.20
by John Arbash Meinel
[merge] bzr.dev 2063 |
159 |
|
|
2018.18.4
by Martin Pool
Change Transport.local_abspath to raise NotLocalUrl, and test. |
160 |
def test_local_abspath_non_local_transport(self): |
161 |
# the base implementation should throw
|
|
|
4634.108.13
by John Arbash Meinel
Add a test case. |
162 |
t = memory.MemoryTransport() |
|
2018.18.4
by Martin Pool
Change Transport.local_abspath to raise NotLocalUrl, and test. |
163 |
e = self.assertRaises(errors.NotLocalUrl, t.local_abspath, 't') |
164 |
self.assertEqual('memory:///t is not a local path.', str(e)) |
|
165 |
||
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
166 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
167 |
class TestCoalesceOffsets(tests.TestCase): |
|
3059.2.17
by Vincent Ladeuil
Limit GET requests by body size instead of number of ranges. |
168 |
|
169 |
def check(self, expected, offsets, limit=0, max_size=0, fudge=0): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
170 |
coalesce = transport.Transport._coalesce_offsets |
171 |
exp = [transport._CoalescedOffset(*x) for x in expected] |
|
|
3059.2.17
by Vincent Ladeuil
Limit GET requests by body size instead of number of ranges. |
172 |
out = list(coalesce(offsets, limit=limit, fudge_factor=fudge, |
173 |
max_size=max_size)) |
|
|
1864.5.9
by John Arbash Meinel
Switch to returning an object to make the api more understandable. |
174 |
self.assertEqual(exp, out) |
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
175 |
|
176 |
def test_coalesce_empty(self): |
|
177 |
self.check([], []) |
|
178 |
||
179 |
def test_coalesce_simple(self): |
|
180 |
self.check([(0, 10, [(0, 10)])], [(0, 10)]) |
|
181 |
||
182 |
def test_coalesce_unrelated(self): |
|
183 |
self.check([(0, 10, [(0, 10)]), |
|
184 |
(20, 10, [(0, 10)]), |
|
185 |
], [(0, 10), (20, 10)]) |
|
|
3059.2.17
by Vincent Ladeuil
Limit GET requests by body size instead of number of ranges. |
186 |
|
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
187 |
def test_coalesce_unsorted(self): |
188 |
self.check([(20, 10, [(0, 10)]), |
|
189 |
(0, 10, [(0, 10)]), |
|
190 |
], [(20, 10), (0, 10)]) |
|
191 |
||
192 |
def test_coalesce_nearby(self): |
|
193 |
self.check([(0, 20, [(0, 10), (10, 10)])], |
|
194 |
[(0, 10), (10, 10)]) |
|
195 |
||
196 |
def test_coalesce_overlapped(self): |
|
|
3686.1.9
by John Arbash Meinel
Overlapping ranges are not allowed anymore. |
197 |
self.assertRaises(ValueError, |
198 |
self.check, [(0, 15, [(0, 10), (5, 10)])], |
|
199 |
[(0, 10), (5, 10)]) |
|
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
200 |
|
201 |
def test_coalesce_limit(self): |
|
202 |
self.check([(10, 50, [(0, 10), (10, 10), (20, 10), |
|
203 |
(30, 10), (40, 10)]), |
|
204 |
(60, 50, [(0, 10), (10, 10), (20, 10), |
|
205 |
(30, 10), (40, 10)]), |
|
206 |
], [(10, 10), (20, 10), (30, 10), (40, 10), |
|
207 |
(50, 10), (60, 10), (70, 10), (80, 10), |
|
208 |
(90, 10), (100, 10)], |
|
209 |
limit=5) |
|
210 |
||
211 |
def test_coalesce_no_limit(self): |
|
212 |
self.check([(10, 100, [(0, 10), (10, 10), (20, 10), |
|
213 |
(30, 10), (40, 10), (50, 10), |
|
214 |
(60, 10), (70, 10), (80, 10), |
|
215 |
(90, 10)]), |
|
216 |
], [(10, 10), (20, 10), (30, 10), (40, 10), |
|
217 |
(50, 10), (60, 10), (70, 10), (80, 10), |
|
218 |
(90, 10), (100, 10)]) |
|
219 |
||
|
1864.5.3
by John Arbash Meinel
Allow collapsing ranges even if they are just 'close' |
220 |
def test_coalesce_fudge(self): |
221 |
self.check([(10, 30, [(0, 10), (20, 10)]), |
|
222 |
(100, 10, [(0, 10),]), |
|
223 |
], [(10, 10), (30, 10), (100, 10)], |
|
224 |
fudge=10 |
|
225 |
)
|
|
|
3059.2.17
by Vincent Ladeuil
Limit GET requests by body size instead of number of ranges. |
226 |
def test_coalesce_max_size(self): |
227 |
self.check([(10, 20, [(0, 10), (10, 10)]), |
|
228 |
(30, 50, [(0, 50)]), |
|
229 |
# If one range is above max_size, it gets its own coalesced
|
|
230 |
# offset
|
|
231 |
(100, 80, [(0, 80),]),], |
|
232 |
[(10, 10), (20, 10), (30, 50), (100, 80)], |
|
233 |
max_size=50 |
|
234 |
)
|
|
235 |
||
236 |
def test_coalesce_no_max_size(self): |
|
237 |
self.check([(10, 170, [(0, 10), (10, 10), (20, 50), (70, 100)]),], |
|
238 |
[(10, 10), (20, 10), (30, 50), (80, 100)], |
|
239 |
)
|
|
|
1864.5.3
by John Arbash Meinel
Allow collapsing ranges even if they are just 'close' |
240 |
|
|
3876.1.2
by John Arbash Meinel
Add a test case that checks the 100MB limit. |
241 |
def test_coalesce_default_limit(self): |
242 |
# By default we use a 100MB max size.
|
|
243 |
ten_mb = 10*1024*1024 |
|
244 |
self.check([(0, 10*ten_mb, [(i*ten_mb, ten_mb) for i in range(10)]), |
|
245 |
(10*ten_mb, ten_mb, [(0, ten_mb)])], |
|
246 |
[(i*ten_mb, ten_mb) for i in range(11)]) |
|
247 |
self.check([(0, 11*ten_mb, [(i*ten_mb, ten_mb) for i in range(11)]),], |
|
248 |
[(i*ten_mb, ten_mb) for i in range(11)], |
|
249 |
max_size=1*1024*1024*1024) |
|
250 |
||
|
1540.3.3
by Martin Pool
Review updates of pycurl transport |
251 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
252 |
class TestMemoryServer(tests.TestCase): |
|
4634.108.13
by John Arbash Meinel
Add a test case. |
253 |
|
254 |
def test_create_server(self): |
|
|
5017.3.45
by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry. |
255 |
server = memory.MemoryServer() |
|
4946.1.2
by John Arbash Meinel
Clean up a few more imports. |
256 |
server.start_server() |
|
4634.108.13
by John Arbash Meinel
Add a test case. |
257 |
url = server.get_url() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
258 |
self.assertTrue(url in transport.transport_list_registry) |
259 |
t = transport.get_transport(url) |
|
|
4634.108.13
by John Arbash Meinel
Add a test case. |
260 |
del t |
|
4946.1.2
by John Arbash Meinel
Clean up a few more imports. |
261 |
server.stop_server() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
262 |
self.assertFalse(url in transport.transport_list_registry) |
|
4634.108.13
by John Arbash Meinel
Add a test case. |
263 |
self.assertRaises(errors.UnsupportedProtocol, |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
264 |
transport.get_transport, url) |
265 |
||
266 |
||
267 |
class TestMemoryTransport(tests.TestCase): |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
268 |
|
269 |
def test_get_transport(self): |
|
|
4634.108.13
by John Arbash Meinel
Add a test case. |
270 |
memory.MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
271 |
|
272 |
def test_clone(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
273 |
t = memory.MemoryTransport() |
274 |
self.assertTrue(isinstance(t, memory.MemoryTransport)) |
|
275 |
self.assertEqual("memory:///", t.clone("/").base) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
276 |
|
277 |
def test_abspath(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
278 |
t = memory.MemoryTransport() |
279 |
self.assertEqual("memory:///relpath", t.abspath('relpath')) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
280 |
|
|
1910.15.1
by Andrew Bennetts
More tests for abspath and clone behaviour |
281 |
def test_abspath_of_root(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
282 |
t = memory.MemoryTransport() |
283 |
self.assertEqual("memory:///", t.base) |
|
284 |
self.assertEqual("memory:///", t.abspath('/')) |
|
|
1910.15.1
by Andrew Bennetts
More tests for abspath and clone behaviour |
285 |
|
|
2070.3.1
by Andrew Bennetts
Fix memory_transport.abspath('/foo') |
286 |
def test_abspath_of_relpath_starting_at_root(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
287 |
t = memory.MemoryTransport() |
288 |
self.assertEqual("memory:///foo", t.abspath('/foo')) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
289 |
|
290 |
def test_append_and_get(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
291 |
t = memory.MemoryTransport() |
292 |
t.append_bytes('path', 'content') |
|
293 |
self.assertEqual(t.get('path').read(), 'content') |
|
294 |
t.append_file('path', StringIO('content')) |
|
295 |
self.assertEqual(t.get('path').read(), 'contentcontent') |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
296 |
|
297 |
def test_put_and_get(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
298 |
t = memory.MemoryTransport() |
299 |
t.put_file('path', StringIO('content')) |
|
300 |
self.assertEqual(t.get('path').read(), 'content') |
|
301 |
t.put_bytes('path', 'content') |
|
302 |
self.assertEqual(t.get('path').read(), 'content') |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
303 |
|
304 |
def test_append_without_dir_fails(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
305 |
t = memory.MemoryTransport() |
306 |
self.assertRaises(errors.NoSuchFile, |
|
307 |
t.append_bytes, 'dir/path', 'content') |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
308 |
|
309 |
def test_put_without_dir_fails(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
310 |
t = memory.MemoryTransport() |
311 |
self.assertRaises(errors.NoSuchFile, |
|
312 |
t.put_file, 'dir/path', StringIO('content')) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
313 |
|
314 |
def test_get_missing(self): |
|
|
4634.108.13
by John Arbash Meinel
Add a test case. |
315 |
transport = memory.MemoryTransport() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
316 |
self.assertRaises(errors.NoSuchFile, transport.get, 'foo') |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
317 |
|
318 |
def test_has_missing(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
319 |
t = memory.MemoryTransport() |
320 |
self.assertEquals(False, t.has('foo')) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
321 |
|
322 |
def test_has_present(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
323 |
t = memory.MemoryTransport() |
324 |
t.append_bytes('foo', 'content') |
|
325 |
self.assertEquals(True, t.has('foo')) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
326 |
|
|
2120.3.1
by John Arbash Meinel
Fix MemoryTransport.list_dir() implementation, and update tests |
327 |
def test_list_dir(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
328 |
t = memory.MemoryTransport() |
329 |
t.put_bytes('foo', 'content') |
|
330 |
t.mkdir('dir') |
|
331 |
t.put_bytes('dir/subfoo', 'content') |
|
332 |
t.put_bytes('dirlike', 'content') |
|
|
2120.3.1
by John Arbash Meinel
Fix MemoryTransport.list_dir() implementation, and update tests |
333 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
334 |
self.assertEquals(['dir', 'dirlike', 'foo'], sorted(t.list_dir('.'))) |
335 |
self.assertEquals(['subfoo'], sorted(t.list_dir('dir'))) |
|
|
2120.3.1
by John Arbash Meinel
Fix MemoryTransport.list_dir() implementation, and update tests |
336 |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
337 |
def test_mkdir(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
338 |
t = memory.MemoryTransport() |
339 |
t.mkdir('dir') |
|
340 |
t.append_bytes('dir/path', 'content') |
|
341 |
self.assertEqual(t.get('dir/path').read(), 'content') |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
342 |
|
343 |
def test_mkdir_missing_parent(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
344 |
t = memory.MemoryTransport() |
345 |
self.assertRaises(errors.NoSuchFile, t.mkdir, 'dir/dir') |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
346 |
|
347 |
def test_mkdir_twice(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
348 |
t = memory.MemoryTransport() |
349 |
t.mkdir('dir') |
|
350 |
self.assertRaises(errors.FileExists, t.mkdir, 'dir') |
|
|
1530.1.5
by Robert Collins
Reinstate Memory parameter tests. |
351 |
|
352 |
def test_parameters(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
353 |
t = memory.MemoryTransport() |
354 |
self.assertEqual(True, t.listable()) |
|
355 |
self.assertEqual(False, t.is_readonly()) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
356 |
|
357 |
def test_iter_files_recursive(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
358 |
t = memory.MemoryTransport() |
359 |
t.mkdir('dir') |
|
360 |
t.put_bytes('dir/foo', 'content') |
|
361 |
t.put_bytes('dir/bar', 'content') |
|
362 |
t.put_bytes('bar', 'content') |
|
363 |
paths = set(t.iter_files_recursive()) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
364 |
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths) |
365 |
||
366 |
def test_stat(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
367 |
t = memory.MemoryTransport() |
368 |
t.put_bytes('foo', 'content') |
|
369 |
t.put_bytes('bar', 'phowar') |
|
370 |
self.assertEqual(7, t.stat('foo').st_size) |
|
371 |
self.assertEqual(6, t.stat('bar').st_size) |
|
372 |
||
373 |
||
374 |
class ChrootDecoratorTransportTest(tests.TestCase): |
|
|
2070.5.1
by Andrew Bennetts
Add ChrootTransportDecorator. |
375 |
"""Chroot decoration specific tests.""" |
376 |
||
|
2018.5.54
by Andrew Bennetts
Fix ChrootTransportDecorator's abspath method to be consistent with its clone |
377 |
def test_abspath(self): |
378 |
# The abspath is always relative to the chroot_url.
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
379 |
server = chroot.ChrootServer( |
380 |
transport.get_transport('memory:///foo/bar/')) |
|
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
381 |
self.start_server(server) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
382 |
t = transport.get_transport(server.get_url()) |
383 |
self.assertEqual(server.get_url(), t.abspath('/')) |
|
|
2018.5.54
by Andrew Bennetts
Fix ChrootTransportDecorator's abspath method to be consistent with its clone |
384 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
385 |
subdir_t = t.clone('subdir') |
386 |
self.assertEqual(server.get_url(), subdir_t.abspath('/')) |
|
|
2379.2.1
by Robert Collins
Rewritten chroot transport that prevents accidental chroot escapes when |
387 |
|
388 |
def test_clone(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
389 |
server = chroot.ChrootServer( |
390 |
transport.get_transport('memory:///foo/bar/')) |
|
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
391 |
self.start_server(server) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
392 |
t = transport.get_transport(server.get_url()) |
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
393 |
# relpath from root and root path are the same
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
394 |
relpath_cloned = t.clone('foo') |
395 |
abspath_cloned = t.clone('/foo') |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
396 |
self.assertEqual(server, relpath_cloned.server) |
397 |
self.assertEqual(server, abspath_cloned.server) |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
398 |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
399 |
def test_chroot_url_preserves_chroot(self): |
400 |
"""Calling get_transport on a chroot transport's base should produce a |
|
401 |
transport with exactly the same behaviour as the original chroot
|
|
402 |
transport.
|
|
403 |
||
404 |
This is so that it is not possible to escape a chroot by doing::
|
|
405 |
url = chroot_transport.base
|
|
406 |
parent_url = urlutils.join(url, '..')
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
407 |
new_t = transport.get_transport(parent_url)
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
408 |
"""
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
409 |
server = chroot.ChrootServer( |
410 |
transport.get_transport('memory:///path/subpath')) |
|
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
411 |
self.start_server(server) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
412 |
t = transport.get_transport(server.get_url()) |
413 |
new_t = transport.get_transport(t.base) |
|
414 |
self.assertEqual(t.server, new_t.server) |
|
415 |
self.assertEqual(t.base, new_t.base) |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
416 |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
417 |
def test_urljoin_preserves_chroot(self): |
418 |
"""Using urlutils.join(url, '..') on a chroot URL should not produce a |
|
419 |
URL that escapes the intended chroot.
|
|
420 |
||
421 |
This is so that it is not possible to escape a chroot by doing::
|
|
422 |
url = chroot_transport.base
|
|
423 |
parent_url = urlutils.join(url, '..')
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
424 |
new_t = transport.get_transport(parent_url)
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
425 |
"""
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
426 |
server = chroot.ChrootServer(transport.get_transport('memory:///path/')) |
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
427 |
self.start_server(server) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
428 |
t = transport.get_transport(server.get_url()) |
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
429 |
self.assertRaises( |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
430 |
errors.InvalidURLJoin, urlutils.join, t.base, '..') |
431 |
||
432 |
||
433 |
class TestChrootServer(tests.TestCase): |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
434 |
|
435 |
def test_construct(self): |
|
|
4634.108.13
by John Arbash Meinel
Add a test case. |
436 |
backing_transport = memory.MemoryTransport() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
437 |
server = chroot.ChrootServer(backing_transport) |
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
438 |
self.assertEqual(backing_transport, server.backing_transport) |
439 |
||
440 |
def test_setUp(self): |
|
|
4634.108.13
by John Arbash Meinel
Add a test case. |
441 |
backing_transport = memory.MemoryTransport() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
442 |
server = chroot.ChrootServer(backing_transport) |
|
4934.3.3
by Martin Pool
Rename Server.setUp to Server.start_server |
443 |
server.start_server() |
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
444 |
try: |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
445 |
self.assertTrue(server.scheme |
446 |
in transport._get_protocol_handlers().keys()) |
|
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
447 |
finally: |
|
4934.3.1
by Martin Pool
Rename Server.tearDown to .stop_server |
448 |
server.stop_server() |
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
449 |
|
|
4934.3.1
by Martin Pool
Rename Server.tearDown to .stop_server |
450 |
def test_stop_server(self): |
|
4634.108.13
by John Arbash Meinel
Add a test case. |
451 |
backing_transport = memory.MemoryTransport() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
452 |
server = chroot.ChrootServer(backing_transport) |
|
4934.3.3
by Martin Pool
Rename Server.setUp to Server.start_server |
453 |
server.start_server() |
|
4934.3.1
by Martin Pool
Rename Server.tearDown to .stop_server |
454 |
server.stop_server() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
455 |
self.assertFalse(server.scheme |
456 |
in transport._get_protocol_handlers().keys()) |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
457 |
|
458 |
def test_get_url(self): |
|
|
4634.108.13
by John Arbash Meinel
Add a test case. |
459 |
backing_transport = memory.MemoryTransport() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
460 |
server = chroot.ChrootServer(backing_transport) |
|
4934.3.3
by Martin Pool
Rename Server.setUp to Server.start_server |
461 |
server.start_server() |
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
462 |
try: |
463 |
self.assertEqual('chroot-%d:///' % id(server), server.get_url()) |
|
464 |
finally: |
|
|
4934.3.1
by Martin Pool
Rename Server.tearDown to .stop_server |
465 |
server.stop_server() |
|
2018.5.53
by Andrew Bennetts
Small fix to urlutils.joinpath that was causing a misbehaviour in |
466 |
|
|
2156.2.1
by v.ladeuil+lp at free
Make the tests windows compatible. |
467 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
468 |
class PathFilteringDecoratorTransportTest(tests.TestCase): |
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
469 |
"""Pathfilter decoration specific tests.""" |
470 |
||
471 |
def test_abspath(self): |
|
472 |
# The abspath is always relative to the base of the backing transport.
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
473 |
server = pathfilter.PathFilteringServer( |
474 |
transport.get_transport('memory:///foo/bar/'), |
|
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
475 |
lambda x: x) |
|
4934.3.3
by Martin Pool
Rename Server.setUp to Server.start_server |
476 |
server.start_server() |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
477 |
t = transport.get_transport(server.get_url()) |
478 |
self.assertEqual(server.get_url(), t.abspath('/')) |
|
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
479 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
480 |
subdir_t = t.clone('subdir') |
481 |
self.assertEqual(server.get_url(), subdir_t.abspath('/')) |
|
|
4934.3.1
by Martin Pool
Rename Server.tearDown to .stop_server |
482 |
server.stop_server() |
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
483 |
|
484 |
def make_pf_transport(self, filter_func=None): |
|
485 |
"""Make a PathFilteringTransport backed by a MemoryTransport. |
|
486 |
|
|
487 |
:param filter_func: by default this will be a no-op function. Use this
|
|
488 |
parameter to override it."""
|
|
489 |
if filter_func is None: |
|
490 |
filter_func = lambda x: x |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
491 |
server = pathfilter.PathFilteringServer( |
492 |
transport.get_transport('memory:///foo/bar/'), filter_func) |
|
|
4934.3.3
by Martin Pool
Rename Server.setUp to Server.start_server |
493 |
server.start_server() |
|
4934.3.1
by Martin Pool
Rename Server.tearDown to .stop_server |
494 |
self.addCleanup(server.stop_server) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
495 |
return transport.get_transport(server.get_url()) |
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
496 |
|
497 |
def test__filter(self): |
|
498 |
# _filter (with an identity func as filter_func) always returns
|
|
499 |
# paths relative to the base of the backing transport.
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
500 |
t = self.make_pf_transport() |
501 |
self.assertEqual('foo', t._filter('foo')) |
|
502 |
self.assertEqual('foo/bar', t._filter('foo/bar')) |
|
503 |
self.assertEqual('', t._filter('..')) |
|
504 |
self.assertEqual('', t._filter('/')) |
|
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
505 |
# The base of the pathfiltering transport is taken into account too.
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
506 |
t = t.clone('subdir1/subdir2') |
507 |
self.assertEqual('subdir1/subdir2/foo', t._filter('foo')) |
|
508 |
self.assertEqual('subdir1/subdir2/foo/bar', t._filter('foo/bar')) |
|
509 |
self.assertEqual('subdir1', t._filter('..')) |
|
510 |
self.assertEqual('', t._filter('/')) |
|
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
511 |
|
|
4634.44.2
by Andrew Bennetts
Add another test. |
512 |
def test_filter_invocation(self): |
513 |
filter_log = [] |
|
514 |
def filter(path): |
|
515 |
filter_log.append(path) |
|
516 |
return path |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
517 |
t = self.make_pf_transport(filter) |
518 |
t.has('abc') |
|
|
4634.44.2
by Andrew Bennetts
Add another test. |
519 |
self.assertEqual(['abc'], filter_log) |
520 |
del filter_log[:] |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
521 |
t.clone('abc').has('xyz') |
|
4634.44.2
by Andrew Bennetts
Add another test. |
522 |
self.assertEqual(['abc/xyz'], filter_log) |
523 |
del filter_log[:] |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
524 |
t.has('/abc') |
|
4634.44.2
by Andrew Bennetts
Add another test. |
525 |
self.assertEqual(['abc'], filter_log) |
526 |
||
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
527 |
def test_clone(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
528 |
t = self.make_pf_transport() |
|
4634.44.2
by Andrew Bennetts
Add another test. |
529 |
# relpath from root and root path are the same
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
530 |
relpath_cloned = t.clone('foo') |
531 |
abspath_cloned = t.clone('/foo') |
|
532 |
self.assertEqual(t.server, relpath_cloned.server) |
|
533 |
self.assertEqual(t.server, abspath_cloned.server) |
|
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
534 |
|
535 |
def test_url_preserves_pathfiltering(self): |
|
536 |
"""Calling get_transport on a pathfiltered transport's base should |
|
537 |
produce a transport with exactly the same behaviour as the original
|
|
538 |
pathfiltered transport.
|
|
539 |
||
540 |
This is so that it is not possible to escape (accidentally or
|
|
541 |
otherwise) the filtering by doing::
|
|
542 |
url = filtered_transport.base
|
|
543 |
parent_url = urlutils.join(url, '..')
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
544 |
new_t = transport.get_transport(parent_url)
|
|
4634.44.1
by Andrew Bennetts
First draft of a generic path-filtering transport decorator. |
545 |
"""
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
546 |
t = self.make_pf_transport() |
547 |
new_t = transport.get_transport(t.base) |
|
548 |
self.assertEqual(t.server, new_t.server) |
|
549 |
self.assertEqual(t.base, new_t.base) |
|
550 |
||
551 |
||
552 |
class ReadonlyDecoratorTransportTest(tests.TestCase): |
|
|
1534.4.9
by Robert Collins
Add a readonly decorator for transports. |
553 |
"""Readonly decoration specific tests.""" |
554 |
||
555 |
def test_local_parameters(self): |
|
556 |
# connect to . in readonly mode
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
557 |
t = readonly.ReadonlyTransportDecorator('readonly+.') |
558 |
self.assertEqual(True, t.listable()) |
|
559 |
self.assertEqual(True, t.is_readonly()) |
|
|
1534.4.9
by Robert Collins
Add a readonly decorator for transports. |
560 |
|
561 |
def test_http_parameters(self): |
|
|
2929.3.7
by Vincent Ladeuil
Rename bzrlib/test/HttpServer.py to bzrlib/tests/http_server.py and fix uses. |
562 |
from bzrlib.tests.http_server import HttpServer |
563 |
# connect to '.' via http which is not listable
|
|
|
1534.4.9
by Robert Collins
Add a readonly decorator for transports. |
564 |
server = HttpServer() |
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
565 |
self.start_server(server) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
566 |
t = transport.get_transport('readonly+' + server.get_url()) |
567 |
self.failUnless(isinstance(t, readonly.ReadonlyTransportDecorator)) |
|
568 |
self.assertEqual(False, t.listable()) |
|
569 |
self.assertEqual(True, t.is_readonly()) |
|
570 |
||
571 |
||
572 |
class FakeNFSDecoratorTests(tests.TestCaseInTempDir): |
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
573 |
"""NFS decorator specific tests.""" |
574 |
||
575 |
def get_nfs_transport(self, url): |
|
576 |
# connect to url with nfs decoration
|
|
577 |
return fakenfs.FakeNFSTransportDecorator('fakenfs+' + url) |
|
578 |
||
579 |
def test_local_parameters(self): |
|
|
2701.1.1
by Martin Pool
Remove Transport.should_cache. |
580 |
# the listable and is_readonly parameters
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
581 |
# are not changed by the fakenfs decorator
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
582 |
t = self.get_nfs_transport('.') |
583 |
self.assertEqual(True, t.listable()) |
|
584 |
self.assertEqual(False, t.is_readonly()) |
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
585 |
|
586 |
def test_http_parameters(self): |
|
|
2701.1.1
by Martin Pool
Remove Transport.should_cache. |
587 |
# the listable and is_readonly parameters
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
588 |
# are not changed by the fakenfs decorator
|
|
2929.3.7
by Vincent Ladeuil
Rename bzrlib/test/HttpServer.py to bzrlib/tests/http_server.py and fix uses. |
589 |
from bzrlib.tests.http_server import HttpServer |
590 |
# connect to '.' via http which is not listable
|
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
591 |
server = HttpServer() |
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
592 |
self.start_server(server) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
593 |
t = self.get_nfs_transport(server.get_url()) |
594 |
self.assertIsInstance(t, fakenfs.FakeNFSTransportDecorator) |
|
595 |
self.assertEqual(False, t.listable()) |
|
596 |
self.assertEqual(True, t.is_readonly()) |
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
597 |
|
598 |
def test_fakenfs_server_default(self): |
|
599 |
# a FakeNFSServer() should bring up a local relpath server for itself
|
|
|
5017.3.22
by Vincent Ladeuil
selftest -s bt.test_transport passing |
600 |
server = test_server.FakeNFSServer() |
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
601 |
self.start_server(server) |
602 |
# the url should be decorated appropriately
|
|
603 |
self.assertStartsWith(server.get_url(), 'fakenfs+') |
|
604 |
# and we should be able to get a transport for it
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
605 |
t = transport.get_transport(server.get_url()) |
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
606 |
# which must be a FakeNFSTransportDecorator instance.
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
607 |
self.assertIsInstance(t, fakenfs.FakeNFSTransportDecorator) |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
608 |
|
609 |
def test_fakenfs_rename_semantics(self): |
|
610 |
# a FakeNFS transport must mangle the way rename errors occur to
|
|
611 |
# look like NFS problems.
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
612 |
t = self.get_nfs_transport('.') |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
613 |
self.build_tree(['from/', 'from/foo', 'to/', 'to/bar'], |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
614 |
transport=t) |
615 |
self.assertRaises(errors.ResourceBusy, t.rename, 'from', 'to') |
|
616 |
||
617 |
||
618 |
class FakeVFATDecoratorTests(tests.TestCaseInTempDir): |
|
|
1608.2.4
by Martin Pool
[broken] Add FakeFVATTransport |
619 |
"""Tests for simulation of VFAT restrictions""" |
620 |
||
621 |
def get_vfat_transport(self, url): |
|
622 |
"""Return vfat-backed transport for test directory""" |
|
623 |
from bzrlib.transport.fakevfat import FakeVFATTransportDecorator |
|
624 |
return FakeVFATTransportDecorator('vfat+' + url) |
|
625 |
||
626 |
def test_transport_creation(self): |
|
627 |
from bzrlib.transport.fakevfat import FakeVFATTransportDecorator |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
628 |
t = self.get_vfat_transport('.') |
629 |
self.assertIsInstance(t, FakeVFATTransportDecorator) |
|
|
1608.2.4
by Martin Pool
[broken] Add FakeFVATTransport |
630 |
|
631 |
def test_transport_mkdir(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
632 |
t = self.get_vfat_transport('.') |
633 |
t.mkdir('HELLO') |
|
634 |
self.assertTrue(t.has('hello')) |
|
635 |
self.assertTrue(t.has('Hello')) |
|
|
1608.2.4
by Martin Pool
[broken] Add FakeFVATTransport |
636 |
|
|
1608.2.11
by Martin Pool
(FakeVFAT) add test for detection of invalid characters |
637 |
def test_forbidden_chars(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
638 |
t = self.get_vfat_transport('.') |
639 |
self.assertRaises(ValueError, t.has, "<NU>") |
|
640 |
||
641 |
||
642 |
class BadTransportHandler(transport.Transport): |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
643 |
def __init__(self, base_url): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
644 |
raise errors.DependencyNotPresent('some_lib', |
645 |
'testing missing dependency') |
|
646 |
||
647 |
||
648 |
class BackupTransportHandler(transport.Transport): |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
649 |
"""Test transport that works as a backup for the BadTransportHandler""" |
|
1540.3.10
by Martin Pool
[broken] keep hooking pycurl into test framework |
650 |
pass
|
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
651 |
|
652 |
||
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
653 |
class TestTransportImplementation(tests.TestCaseInTempDir): |
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
654 |
"""Implementation verification for transports. |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
655 |
|
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
656 |
To verify a transport we need a server factory, which is a callable
|
657 |
that accepts no parameters and returns an implementation of
|
|
658 |
bzrlib.transport.Server.
|
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
659 |
|
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
660 |
That Server is then used to construct transport instances and test
|
661 |
the transport via loopback activity.
|
|
662 |
||
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
663 |
Currently this assumes that the Transport object is connected to the
|
664 |
current working directory. So that whatever is done
|
|
665 |
through the transport, should show up in the working
|
|
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
666 |
directory, and vice-versa. This is a bug, because its possible to have
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
667 |
URL schemes which provide access to something that may not be
|
668 |
result in storage on the local disk, i.e. due to file system limits, or
|
|
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
669 |
due to it being a database or some other non-filesystem tool.
|
670 |
||
671 |
This also tests to make sure that the functions work with both
|
|
672 |
generators and lists (assuming iter(list) is effectively a generator)
|
|
673 |
"""
|
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
674 |
|
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
675 |
def setUp(self): |
676 |
super(TestTransportImplementation, self).setUp() |
|
677 |
self._server = self.transport_server() |
|
|
4659.1.2
by Robert Collins
Refactor creation and shutdown of test servers to use a common helper, |
678 |
self.start_server(self._server) |
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
679 |
|
|
2520.3.1
by Vincent Ladeuil
Fix 110448 by adding a relpath parameter to get_transport. |
680 |
def get_transport(self, relpath=None): |
681 |
"""Return a connected transport to the local directory. |
|
682 |
||
683 |
:param relpath: a path relative to the base url.
|
|
684 |
"""
|
|
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
685 |
base_url = self._server.get_url() |
|
2520.3.1
by Vincent Ladeuil
Fix 110448 by adding a relpath parameter to get_transport. |
686 |
url = self._adjust_url(base_url, relpath) |
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
687 |
# try getting the transport via the regular interface:
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
688 |
t = transport.get_transport(url) |
|
2485.8.39
by Vincent Ladeuil
Add tests around connection reuse. |
689 |
# vila--20070607 if the following are commented out the test suite
|
690 |
# still pass. Is this really still needed or was it a forgotten
|
|
691 |
# temporary fix ?
|
|
|
1986.2.5
by Robert Collins
Unbreak transport tests. |
692 |
if not isinstance(t, self.transport_class): |
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
693 |
# we did not get the correct transport class type. Override the
|
694 |
# regular connection behaviour by direct construction.
|
|
|
2520.3.1
by Vincent Ladeuil
Fix 110448 by adding a relpath parameter to get_transport. |
695 |
t = self.transport_class(url) |
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
696 |
return t |
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
697 |
|
698 |
||
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
699 |
class TestLocalTransports(tests.TestCase): |
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
700 |
|
701 |
def test_get_transport_from_abspath(self): |
|
|
2804.4.1
by Alexander Belchenko
some win32-specific fixes for selftest |
702 |
here = osutils.abspath('.') |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
703 |
t = transport.get_transport(here) |
704 |
self.assertIsInstance(t, local.LocalTransport) |
|
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
705 |
self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/') |
706 |
||
707 |
def test_get_transport_from_relpath(self): |
|
|
2804.4.1
by Alexander Belchenko
some win32-specific fixes for selftest |
708 |
here = osutils.abspath('.') |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
709 |
t = transport.get_transport('.') |
710 |
self.assertIsInstance(t, local.LocalTransport) |
|
|
1951.2.3
by Martin Pool
Localtransport cleanup review (john) |
711 |
self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/') |
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
712 |
|
713 |
def test_get_transport_from_local_url(self): |
|
|
2804.4.1
by Alexander Belchenko
some win32-specific fixes for selftest |
714 |
here = osutils.abspath('.') |
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
715 |
here_url = urlutils.local_path_to_url(here) + '/' |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
716 |
t = transport.get_transport(here_url) |
717 |
self.assertIsInstance(t, local.LocalTransport) |
|
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
718 |
self.assertEquals(t.base, here_url) |
|
2245.6.1
by Alexander Belchenko
win32 UNC path: recursive cloning UNC path to root stops on //HOST, not on // |
719 |
|
|
2018.18.4
by Martin Pool
Change Transport.local_abspath to raise NotLocalUrl, and test. |
720 |
def test_local_abspath(self): |
|
2804.4.1
by Alexander Belchenko
some win32-specific fixes for selftest |
721 |
here = osutils.abspath('.') |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
722 |
t = transport.get_transport(here) |
|
2018.18.4
by Martin Pool
Change Transport.local_abspath to raise NotLocalUrl, and test. |
723 |
self.assertEquals(t.local_abspath(''), here) |
724 |
||
|
2245.6.1
by Alexander Belchenko
win32 UNC path: recursive cloning UNC path to root stops on //HOST, not on // |
725 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
726 |
class TestWin32LocalTransport(tests.TestCase): |
|
2245.6.1
by Alexander Belchenko
win32 UNC path: recursive cloning UNC path to root stops on //HOST, not on // |
727 |
|
728 |
def test_unc_clone_to_root(self): |
|
729 |
# Win32 UNC path like \\HOST\path
|
|
730 |
# clone to root should stop at least at \\HOST part
|
|
731 |
# not on \\
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
732 |
t = local.EmulatedWin32LocalTransport('file://HOST/path/to/some/dir/') |
|
2245.6.1
by Alexander Belchenko
win32 UNC path: recursive cloning UNC path to root stops on //HOST, not on // |
733 |
for i in xrange(4): |
734 |
t = t.clone('..') |
|
735 |
self.assertEquals(t.base, 'file://HOST/') |
|
736 |
# make sure we reach the root
|
|
737 |
t = t.clone('..') |
|
738 |
self.assertEquals(t.base, 'file://HOST/') |
|
|
2477.1.7
by Martin Pool
test_transport must provide get_test_permutations |
739 |
|
|
2485.8.61
by Vincent Ladeuil
From review comments, use a private scheme for testing. |
740 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
741 |
class TestConnectedTransport(tests.TestCase): |
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
742 |
"""Tests for connected to remote server transports""" |
743 |
||
744 |
def test_parse_url(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
745 |
t = transport.ConnectedTransport( |
746 |
'http://simple.example.com/home/source') |
|
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
747 |
self.assertEquals(t._host, 'simple.example.com') |
|
3004.2.1
by Vincent Ladeuil
Fix 150860 by leaving port as user specified it. |
748 |
self.assertEquals(t._port, None) |
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
749 |
self.assertEquals(t._path, '/home/source/') |
750 |
self.failUnless(t._user is None) |
|
751 |
self.failUnless(t._password is None) |
|
752 |
||
|
2892.1.1
by Andrew Bennetts
Fix bug 146715: bzr+ssh:// and sftp:// should not assume port-not-specified means port 22 |
753 |
self.assertEquals(t.base, 'http://simple.example.com/home/source/') |
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
754 |
|
|
3498.2.1
by Neil Martinsen-Burrell
Fix bug 228058: user names with @ signs should work |
755 |
def test_parse_url_with_at_in_user(self): |
756 |
# Bug 228058
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
757 |
t = transport.ConnectedTransport('ftp://user@host.com@www.host.com/') |
|
3498.2.1
by Neil Martinsen-Burrell
Fix bug 228058: user names with @ signs should work |
758 |
self.assertEquals(t._user, 'user@host.com') |
759 |
||
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
760 |
def test_parse_quoted_url(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
761 |
t = transport.ConnectedTransport( |
762 |
'http://ro%62ey:h%40t@ex%41mple.com:2222/path') |
|
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
763 |
self.assertEquals(t._host, 'exAmple.com') |
764 |
self.assertEquals(t._port, 2222) |
|
765 |
self.assertEquals(t._user, 'robey') |
|
766 |
self.assertEquals(t._password, 'h@t') |
|
767 |
self.assertEquals(t._path, '/path/') |
|
768 |
||
769 |
# Base should not keep track of the password
|
|
770 |
self.assertEquals(t.base, 'http://robey@exAmple.com:2222/path/') |
|
771 |
||
772 |
def test_parse_invalid_url(self): |
|
773 |
self.assertRaises(errors.InvalidURL, |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
774 |
transport.ConnectedTransport, |
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
775 |
'sftp://lily.org:~janneke/public/bzr/gub') |
776 |
||
777 |
def test_relpath(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
778 |
t = transport.ConnectedTransport('sftp://user@host.com/abs/path') |
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
779 |
|
780 |
self.assertEquals(t.relpath('sftp://user@host.com/abs/path/sub'), 'sub') |
|
781 |
self.assertRaises(errors.PathNotChild, t.relpath, |
|
782 |
'http://user@host.com/abs/path/sub') |
|
783 |
self.assertRaises(errors.PathNotChild, t.relpath, |
|
784 |
'sftp://user2@host.com/abs/path/sub') |
|
785 |
self.assertRaises(errors.PathNotChild, t.relpath, |
|
786 |
'sftp://user@otherhost.com/abs/path/sub') |
|
787 |
self.assertRaises(errors.PathNotChild, t.relpath, |
|
788 |
'sftp://user@host.com:33/abs/path/sub') |
|
789 |
# Make sure it works when we don't supply a username
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
790 |
t = transport.ConnectedTransport('sftp://host.com/abs/path') |
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
791 |
self.assertEquals(t.relpath('sftp://host.com/abs/path/sub'), 'sub') |
792 |
||
793 |
# Make sure it works when parts of the path will be url encoded
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
794 |
t = transport.ConnectedTransport('sftp://host.com/dev/%path') |
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
795 |
self.assertEquals(t.relpath('sftp://host.com/dev/%path/sub'), 'sub') |
796 |
||
|
2485.8.32
by Vincent Ladeuil
Keep credentials used at connection creation for reconnection purposes. |
797 |
def test_connection_sharing_propagate_credentials(self): |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
798 |
t = transport.ConnectedTransport('ftp://user@host.com/abs/path') |
|
2900.2.16
by Vincent Ladeuil
Make hhtp proxy aware of AuthenticationConfig (for password). |
799 |
self.assertEquals('user', t._user) |
800 |
self.assertEquals('host.com', t._host) |
|
|
2485.8.32
by Vincent Ladeuil
Keep credentials used at connection creation for reconnection purposes. |
801 |
self.assertIs(None, t._get_connection()) |
802 |
self.assertIs(None, t._password) |
|
803 |
c = t.clone('subdir') |
|
|
2900.2.16
by Vincent Ladeuil
Make hhtp proxy aware of AuthenticationConfig (for password). |
804 |
self.assertIs(None, c._get_connection()) |
|
2485.8.32
by Vincent Ladeuil
Keep credentials used at connection creation for reconnection purposes. |
805 |
self.assertIs(None, t._password) |
806 |
||
807 |
# Simulate the user entering a password
|
|
808 |
password = 'secret' |
|
809 |
connection = object() |
|
810 |
t._set_connection(connection, password) |
|
811 |
self.assertIs(connection, t._get_connection()) |
|
812 |
self.assertIs(password, t._get_credentials()) |
|
813 |
self.assertIs(connection, c._get_connection()) |
|
814 |
self.assertIs(password, c._get_credentials()) |
|
|
2485.8.30
by Vincent Ladeuil
Implement reliable connection sharing. |
815 |
|
|
2485.8.39
by Vincent Ladeuil
Add tests around connection reuse. |
816 |
# credentials can be updated
|
817 |
new_password = 'even more secret' |
|
818 |
c._update_credentials(new_password) |
|
819 |
self.assertIs(connection, t._get_connection()) |
|
820 |
self.assertIs(new_password, t._get_credentials()) |
|
821 |
self.assertIs(connection, c._get_connection()) |
|
822 |
self.assertIs(new_password, c._get_credentials()) |
|
823 |
||
|
2477.1.7
by Martin Pool
test_transport must provide get_test_permutations |
824 |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
825 |
class TestReusedTransports(tests.TestCase): |
|
2485.8.19
by Vincent Ladeuil
Add a new ConnectedTransport class refactored from [s]ftp and http. |
826 |
"""Tests for transport reuse""" |
|
2476.3.5
by Vincent Ladeuil
Naive implementation of transport reuse by Transport.get_transport(). |
827 |
|
828 |
def test_reuse_same_transport(self): |
|
|
1551.18.10
by Aaron Bentley
get_transport appends to possible_transports if it's an empty list |
829 |
possible_transports = [] |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
830 |
t1 = transport.get_transport('http://foo/', |
831 |
possible_transports=possible_transports) |
|
|
1551.18.10
by Aaron Bentley
get_transport appends to possible_transports if it's an empty list |
832 |
self.assertEqual([t1], possible_transports) |
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
833 |
t2 = transport.get_transport('http://foo/', |
834 |
possible_transports=[t1]) |
|
|
2485.8.37
by Vincent Ladeuil
Fix merge multiple connections. Test suite *not* passing (sftp |
835 |
self.assertIs(t1, t2) |
836 |
||
837 |
# Also check that final '/' are handled correctly
|
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
838 |
t3 = transport.get_transport('http://foo/path/') |
839 |
t4 = transport.get_transport('http://foo/path', |
|
840 |
possible_transports=[t3]) |
|
|
2485.8.37
by Vincent Ladeuil
Fix merge multiple connections. Test suite *not* passing (sftp |
841 |
self.assertIs(t3, t4) |
842 |
||
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
843 |
t5 = transport.get_transport('http://foo/path') |
844 |
t6 = transport.get_transport('http://foo/path/', |
|
845 |
possible_transports=[t5]) |
|
|
2485.8.39
by Vincent Ladeuil
Add tests around connection reuse. |
846 |
self.assertIs(t5, t6) |
|
2476.3.5
by Vincent Ladeuil
Naive implementation of transport reuse by Transport.get_transport(). |
847 |
|
848 |
def test_don_t_reuse_different_transport(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
849 |
t1 = transport.get_transport('http://foo/path') |
850 |
t2 = transport.get_transport('http://bar/path', |
|
851 |
possible_transports=[t1]) |
|
|
2485.8.40
by Vincent Ladeuil
Fix typo. |
852 |
self.assertIsNot(t1, t2) |
|
2476.3.13
by Vincent Ladeuil
merge bzr.dev@2495 |
853 |
|
854 |
||
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
855 |
class TestTransportTrace(tests.TestCase): |
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
856 |
|
857 |
def test_get(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
858 |
t = transport.get_transport('trace+memory://') |
859 |
self.assertIsInstance(t, bzrlib.transport.trace.TransportTraceDecorator) |
|
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
860 |
|
861 |
def test_clone_preserves_activity(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
862 |
t = transport.get_transport('trace+memory://') |
863 |
t2 = t.clone('.') |
|
864 |
self.assertTrue(t is not t2) |
|
865 |
self.assertTrue(t._activity is t2._activity) |
|
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
866 |
|
867 |
# the following specific tests are for the operations that have made use of
|
|
868 |
# logging in tests; we could test every single operation but doing that
|
|
869 |
# still won't cause a test failure when the top level Transport API
|
|
870 |
# changes; so there is little return doing that.
|
|
871 |
def test_get(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
872 |
t = transport.get_transport('trace+memory:///') |
873 |
t.put_bytes('foo', 'barish') |
|
874 |
t.get('foo') |
|
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
875 |
expected_result = [] |
876 |
# put_bytes records the bytes, not the content to avoid memory
|
|
877 |
# pressure.
|
|
878 |
expected_result.append(('put_bytes', 'foo', 6, None)) |
|
879 |
# get records the file name only.
|
|
880 |
expected_result.append(('get', 'foo')) |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
881 |
self.assertEqual(expected_result, t._activity) |
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
882 |
|
883 |
def test_readv(self): |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
884 |
t = transport.get_transport('trace+memory:///') |
885 |
t.put_bytes('foo', 'barish') |
|
886 |
list(t.readv('foo', [(0, 1), (3, 2)], |
|
887 |
adjust_for_latency=True, upper_limit=6)) |
|
|
2745.5.3
by Robert Collins
* Move transport logging into a new transport class |
888 |
expected_result = [] |
889 |
# put_bytes records the bytes, not the content to avoid memory
|
|
890 |
# pressure.
|
|
891 |
expected_result.append(('put_bytes', 'foo', 6, None)) |
|
892 |
# readv records the supplied offset request
|
|
893 |
expected_result.append(('readv', 'foo', [(0, 1), (3, 2)], True, 6)) |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
894 |
self.assertEqual(expected_result, t._activity) |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
895 |
|
896 |
||
897 |
class TestSSHConnections(tests.TestCaseWithTransport): |
|
898 |
||
899 |
def test_bzr_connect_to_bzr_ssh(self): |
|
900 |
"""User acceptance that get_transport of a bzr+ssh:// behaves correctly. |
|
901 |
||
902 |
bzr+ssh:// should cause bzr to run a remote bzr smart server over SSH.
|
|
903 |
"""
|
|
904 |
# This test actually causes a bzr instance to be invoked, which is very
|
|
905 |
# expensive: it should be the only such test in the test suite.
|
|
906 |
# A reasonable evolution for this would be to simply check inside
|
|
907 |
# check_channel_exec_request that the command is appropriate, and then
|
|
908 |
# satisfy requests in-process.
|
|
|
4913.2.16
by John Arbash Meinel
Move bzrlib.tests.ParamikoFeature to bzrlib.tests.features.paramiko |
909 |
self.requireFeature(features.paramiko) |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
910 |
# SFTPFullAbsoluteServer has a get_url method, and doesn't
|
911 |
# override the interface (doesn't change self._vendor).
|
|
912 |
# Note that this does encryption, so can be slow.
|
|
|
4797.11.2
by Vincent Ladeuil
Stop requiring testtools for sftp use. |
913 |
from bzrlib.tests import stub_sftp |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
914 |
|
915 |
# Start an SSH server
|
|
916 |
self.command_executed = [] |
|
917 |
# XXX: This is horrible -- we define a really dumb SSH server that
|
|
918 |
# executes commands, and manage the hooking up of stdin/out/err to the
|
|
919 |
# SSH channel ourselves. Surely this has already been implemented
|
|
920 |
# elsewhere?
|
|
|
4857.2.2
by John Arbash Meinel
Change the connect-to-bzr test so that it cleans itself up. |
921 |
started = [] |
|
4797.11.2
by Vincent Ladeuil
Stop requiring testtools for sftp use. |
922 |
class StubSSHServer(stub_sftp.StubServer): |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
923 |
|
924 |
test = self |
|
925 |
||
926 |
def check_channel_exec_request(self, channel, command): |
|
927 |
self.test.command_executed.append(command) |
|
928 |
proc = subprocess.Popen( |
|
929 |
command, shell=True, stdin=subprocess.PIPE, |
|
930 |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
931 |
||
932 |
# XXX: horribly inefficient, not to mention ugly.
|
|
933 |
# Start a thread for each of stdin/out/err, and relay bytes from
|
|
934 |
# the subprocess to channel and vice versa.
|
|
935 |
def ferry_bytes(read, write, close): |
|
936 |
while True: |
|
937 |
bytes = read(1) |
|
938 |
if bytes == '': |
|
939 |
close() |
|
940 |
break
|
|
941 |
write(bytes) |
|
942 |
||
943 |
file_functions = [ |
|
944 |
(channel.recv, proc.stdin.write, proc.stdin.close), |
|
945 |
(proc.stdout.read, channel.sendall, channel.close), |
|
946 |
(proc.stderr.read, channel.sendall_stderr, channel.close)] |
|
|
4857.2.2
by John Arbash Meinel
Change the connect-to-bzr test so that it cleans itself up. |
947 |
started.append(proc) |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
948 |
for read, write, close in file_functions: |
949 |
t = threading.Thread( |
|
950 |
target=ferry_bytes, args=(read, write, close)) |
|
951 |
t.start() |
|
|
4857.2.2
by John Arbash Meinel
Change the connect-to-bzr test so that it cleans itself up. |
952 |
started.append(t) |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
953 |
|
954 |
return True |
|
955 |
||
|
4797.11.2
by Vincent Ladeuil
Stop requiring testtools for sftp use. |
956 |
ssh_server = stub_sftp.SFTPFullAbsoluteServer(StubSSHServer) |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
957 |
# We *don't* want to override the default SSH vendor: the detected one
|
958 |
# is the one to use.
|
|
|
5247.4.20
by Vincent Ladeuil
Ugly fix for the last test failure. |
959 |
|
960 |
# FIXME: I don't understand the above comment, SFTPFullAbsoluteServer
|
|
961 |
# inherits from SFTPServer which forces the SSH vendor to
|
|
962 |
# ssh.ParamikoVendor(). So it's forced, not detected. --vila 20100623
|
|
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
963 |
self.start_server(ssh_server) |
|
5247.4.20
by Vincent Ladeuil
Ugly fix for the last test failure. |
964 |
port = ssh_server.port |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
965 |
|
966 |
if sys.platform == 'win32': |
|
967 |
bzr_remote_path = sys.executable + ' ' + self.get_bzr_path() |
|
968 |
else: |
|
969 |
bzr_remote_path = self.get_bzr_path() |
|
970 |
os.environ['BZR_REMOTE_PATH'] = bzr_remote_path |
|
971 |
||
972 |
# Access the branch via a bzr+ssh URL. The BZR_REMOTE_PATH environment
|
|
973 |
# variable is used to tell bzr what command to run on the remote end.
|
|
974 |
path_to_branch = osutils.abspath('.') |
|
975 |
if sys.platform == 'win32': |
|
|
4700.1.2
by Robert Collins
Review feedback. |
976 |
# On Windows, we export all drives as '/C:/, etc. So we need to
|
977 |
# prefix a '/' to get the right path.
|
|
978 |
path_to_branch = '/' + path_to_branch |
|
979 |
url = 'bzr+ssh://fred:secret@localhost:%d%s' % (port, path_to_branch) |
|
|
5010.2.10
by Vincent Ladeuil
Fix test_transport.py imports. |
980 |
t = transport.get_transport(url) |
|
4700.1.2
by Robert Collins
Review feedback. |
981 |
self.permit_url(t.base) |
|
4700.1.1
by Robert Collins
Focus and move out of blackbox the acceptance test for bzr+ssh connection handshake/process spawning. |
982 |
t.mkdir('foo') |
983 |
||
984 |
self.assertEqual( |
|
985 |
['%s serve --inet --directory=/ --allow-writes' % bzr_remote_path], |
|
986 |
self.command_executed) |
|
|
4857.2.2
by John Arbash Meinel
Change the connect-to-bzr test so that it cleans itself up. |
987 |
# Make sure to disconnect, so that the remote process can stop, and we
|
988 |
# can cleanup. Then pause the test until everything is shutdown
|
|
989 |
t._client._medium.disconnect() |
|
990 |
if not started: |
|
991 |
return
|
|
992 |
# First wait for the subprocess
|
|
993 |
started[0].wait() |
|
994 |
# And the rest are threads
|
|
995 |
for t in started[1:]: |
|
996 |
t.join() |
|
|
4912.2.4
by Martin Pool
Add test for unhtml_roughly, and truncate at 1000 bytes |
997 |
|
998 |
||
999 |
class TestUnhtml(tests.TestCase): |
|
1000 |
||
1001 |
"""Tests for unhtml_roughly""" |
|
1002 |
||
1003 |
def test_truncation(self): |
|
1004 |
fake_html = "<p>something!\n" * 1000 |
|
1005 |
result = http.unhtml_roughly(fake_html) |
|
1006 |
self.assertEquals(len(result), 1000) |
|
1007 |
self.assertStartsWith(result, " something!") |