bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2004, 2005, 2006 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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
|
1185.11.22
by John Arbash Meinel
Major refactoring of testtransport. |
18 |
import os |
|
1185.58.2
by John Arbash Meinel
Added mode to the appropriate transport functions, and tests to make sure they work. |
19 |
import sys |
|
1185.58.4
by John Arbash Meinel
Added permission checking to Branch, and propogated that change into the stores. |
20 |
import stat |
|
1185.11.22
by John Arbash Meinel
Major refactoring of testtransport. |
21 |
from cStringIO import StringIO |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
22 |
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
23 |
import bzrlib |
|
1951.2.3
by Martin Pool
Localtransport cleanup review (john) |
24 |
from bzrlib import urlutils |
|
2379.2.1
by Robert Collins
Rewritten chroot transport that prevents accidental chroot escapes when |
25 |
from bzrlib.errors import (ConnectionError, |
26 |
DependencyNotPresent, |
|
27 |
FileExists, |
|
28 |
InvalidURLJoin, |
|
29 |
NoSuchFile, |
|
30 |
PathNotChild, |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
31 |
TransportNotPossible, |
|
1843.1.1
by John Arbash Meinel
Update get_transport to raise a nicer error which includes dependency info |
32 |
UnsupportedProtocol, |
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
33 |
)
|
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
34 |
from bzrlib.tests import TestCase, TestCaseInTempDir |
|
1864.5.9
by John Arbash Meinel
Switch to returning an object to make the api more understandable. |
35 |
from bzrlib.transport import (_CoalescedOffset, |
36 |
_get_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. |
37 |
_get_transport_modules, |
|
1534.4.9
by Robert Collins
Add a readonly decorator for transports. |
38 |
get_transport, |
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
39 |
_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. |
40 |
register_lazy_transport, |
41 |
_set_protocol_handlers, |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
42 |
Transport, |
|
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. |
43 |
)
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
44 |
from bzrlib.transport.chroot import ChrootServer |
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
45 |
from bzrlib.transport.memory import MemoryTransport |
|
2245.6.1
by Alexander Belchenko
win32 UNC path: recursive cloning UNC path to root stops on //HOST, not on // |
46 |
from bzrlib.transport.local import (LocalTransport, |
|
2245.6.2
by Alexander Belchenko
Fix name of emulated Win32LocalTransport as Robert suggested. |
47 |
EmulatedWin32LocalTransport) |
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
48 |
|
49 |
||
50 |
# 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. |
51 |
|
52 |
||
|
1185.58.3
by John Arbash Meinel
code cleanup |
53 |
class TestTransport(TestCase): |
54 |
"""Test the non transport-concrete class functionality.""" |
|
55 |
||
|
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. |
56 |
def test__get_set_protocol_handlers(self): |
57 |
handlers = _get_protocol_handlers() |
|
58 |
self.assertNotEqual({}, handlers) |
|
59 |
try: |
|
60 |
_set_protocol_handlers({}) |
|
61 |
self.assertEqual({}, _get_protocol_handlers()) |
|
62 |
finally: |
|
63 |
_set_protocol_handlers(handlers) |
|
64 |
||
65 |
def test_get_transport_modules(self): |
|
66 |
handlers = _get_protocol_handlers() |
|
67 |
class SampleHandler(object): |
|
68 |
"""I exist, isnt that enough?""" |
|
69 |
try: |
|
70 |
my_handlers = {} |
|
71 |
_set_protocol_handlers(my_handlers) |
|
72 |
register_lazy_transport('foo', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler') |
|
73 |
register_lazy_transport('bar', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler') |
|
|
2379.2.1
by Robert Collins
Rewritten chroot transport that prevents accidental chroot escapes when |
74 |
self.assertEqual([SampleHandler.__module__, 'bzrlib.transport.chroot'], |
|
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. |
75 |
_get_transport_modules()) |
76 |
finally: |
|
77 |
_set_protocol_handlers(handlers) |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
78 |
|
79 |
def test_transport_dependency(self): |
|
80 |
"""Transport with missing dependency causes no error""" |
|
81 |
saved_handlers = _get_protocol_handlers() |
|
82 |
try: |
|
83 |
register_lazy_transport('foo', 'bzrlib.tests.test_transport', |
|
84 |
'BadTransportHandler') |
|
|
1843.1.1
by John Arbash Meinel
Update get_transport to raise a nicer error which includes dependency info |
85 |
try: |
86 |
get_transport('foo://fooserver/foo') |
|
87 |
except UnsupportedProtocol, e: |
|
88 |
e_str = str(e) |
|
89 |
self.assertEquals('Unsupported protocol' |
|
90 |
' for url "foo://fooserver/foo":'
|
|
91 |
' Unable to import library "some_lib":'
|
|
92 |
' testing missing dependency', str(e)) |
|
93 |
else: |
|
94 |
self.fail('Did not raise UnsupportedProtocol') |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
95 |
finally: |
|
1540.3.10
by Martin Pool
[broken] keep hooking pycurl into test framework |
96 |
# restore original values
|
97 |
_set_protocol_handlers(saved_handlers) |
|
98 |
||
99 |
def test_transport_fallback(self): |
|
100 |
"""Transport with missing dependency causes no error""" |
|
101 |
saved_handlers = _get_protocol_handlers() |
|
102 |
try: |
|
|
1540.3.12
by Martin Pool
Multiple transports can be registered for any protocol, and they are |
103 |
_set_protocol_handlers({}) |
|
1540.3.10
by Martin Pool
[broken] keep hooking pycurl into test framework |
104 |
register_lazy_transport('foo', 'bzrlib.tests.test_transport', |
105 |
'BackupTransportHandler') |
|
106 |
register_lazy_transport('foo', 'bzrlib.tests.test_transport', |
|
107 |
'BadTransportHandler') |
|
108 |
t = get_transport('foo://fooserver/foo') |
|
109 |
self.assertTrue(isinstance(t, BackupTransportHandler)) |
|
110 |
finally: |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
111 |
_set_protocol_handlers(saved_handlers) |
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
112 |
|
|
1996.3.20
by John Arbash Meinel
[merge] bzr.dev 2063 |
113 |
def test__combine_paths(self): |
114 |
t = Transport('/') |
|
115 |
self.assertEqual('/home/sarah/project/foo', |
|
116 |
t._combine_paths('/home/sarah', 'project/foo')) |
|
117 |
self.assertEqual('/etc', |
|
118 |
t._combine_paths('/home/sarah', '../../etc')) |
|
|
2070.3.2
by Andrew Bennetts
Merge from bzr.dev |
119 |
self.assertEqual('/etc', |
120 |
t._combine_paths('/home/sarah', '../../../etc')) |
|
121 |
self.assertEqual('/etc', |
|
122 |
t._combine_paths('/home/sarah', '/etc')) |
|
|
1996.3.20
by John Arbash Meinel
[merge] bzr.dev 2063 |
123 |
|
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
124 |
|
125 |
class TestCoalesceOffsets(TestCase): |
|
126 |
||
|
1864.5.3
by John Arbash Meinel
Allow collapsing ranges even if they are just 'close' |
127 |
def check(self, expected, offsets, limit=0, fudge=0): |
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
128 |
coalesce = Transport._coalesce_offsets |
|
1864.5.9
by John Arbash Meinel
Switch to returning an object to make the api more understandable. |
129 |
exp = [_CoalescedOffset(*x) for x in expected] |
130 |
out = list(coalesce(offsets, limit=limit, fudge_factor=fudge)) |
|
131 |
self.assertEqual(exp, out) |
|
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
132 |
|
133 |
def test_coalesce_empty(self): |
|
134 |
self.check([], []) |
|
135 |
||
136 |
def test_coalesce_simple(self): |
|
137 |
self.check([(0, 10, [(0, 10)])], [(0, 10)]) |
|
138 |
||
139 |
def test_coalesce_unrelated(self): |
|
140 |
self.check([(0, 10, [(0, 10)]), |
|
141 |
(20, 10, [(0, 10)]), |
|
142 |
], [(0, 10), (20, 10)]) |
|
|
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. |
143 |
|
|
1864.5.1
by John Arbash Meinel
Change the readv combining algorithm for one that is easier to test. |
144 |
def test_coalesce_unsorted(self): |
145 |
self.check([(20, 10, [(0, 10)]), |
|
146 |
(0, 10, [(0, 10)]), |
|
147 |
], [(20, 10), (0, 10)]) |
|
148 |
||
149 |
def test_coalesce_nearby(self): |
|
150 |
self.check([(0, 20, [(0, 10), (10, 10)])], |
|
151 |
[(0, 10), (10, 10)]) |
|
152 |
||
153 |
def test_coalesce_overlapped(self): |
|
154 |
self.check([(0, 15, [(0, 10), (5, 10)])], |
|
155 |
[(0, 10), (5, 10)]) |
|
156 |
||
157 |
def test_coalesce_limit(self): |
|
158 |
self.check([(10, 50, [(0, 10), (10, 10), (20, 10), |
|
159 |
(30, 10), (40, 10)]), |
|
160 |
(60, 50, [(0, 10), (10, 10), (20, 10), |
|
161 |
(30, 10), (40, 10)]), |
|
162 |
], [(10, 10), (20, 10), (30, 10), (40, 10), |
|
163 |
(50, 10), (60, 10), (70, 10), (80, 10), |
|
164 |
(90, 10), (100, 10)], |
|
165 |
limit=5) |
|
166 |
||
167 |
def test_coalesce_no_limit(self): |
|
168 |
self.check([(10, 100, [(0, 10), (10, 10), (20, 10), |
|
169 |
(30, 10), (40, 10), (50, 10), |
|
170 |
(60, 10), (70, 10), (80, 10), |
|
171 |
(90, 10)]), |
|
172 |
], [(10, 10), (20, 10), (30, 10), (40, 10), |
|
173 |
(50, 10), (60, 10), (70, 10), (80, 10), |
|
174 |
(90, 10), (100, 10)]) |
|
175 |
||
|
1864.5.3
by John Arbash Meinel
Allow collapsing ranges even if they are just 'close' |
176 |
def test_coalesce_fudge(self): |
177 |
self.check([(10, 30, [(0, 10), (20, 10)]), |
|
178 |
(100, 10, [(0, 10),]), |
|
179 |
], [(10, 10), (30, 10), (100, 10)], |
|
180 |
fudge=10 |
|
181 |
)
|
|
182 |
||
|
1540.3.3
by Martin Pool
Review updates of pycurl transport |
183 |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
184 |
class TestMemoryTransport(TestCase): |
185 |
||
186 |
def test_get_transport(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
187 |
MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
188 |
|
189 |
def test_clone(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
190 |
transport = MemoryTransport() |
191 |
self.assertTrue(isinstance(transport, MemoryTransport)) |
|
|
1910.15.3
by Andrew Bennetts
Make memory transport pass tests. |
192 |
self.assertEqual("memory:///", transport.clone("/").base) |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
193 |
|
194 |
def test_abspath(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
195 |
transport = MemoryTransport() |
|
1685.1.42
by John Arbash Meinel
A couple more fixes to make sure memory:/// works correctly. |
196 |
self.assertEqual("memory:///relpath", transport.abspath('relpath')) |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
197 |
|
|
1910.15.1
by Andrew Bennetts
More tests for abspath and clone behaviour |
198 |
def test_abspath_of_root(self): |
199 |
transport = MemoryTransport() |
|
200 |
self.assertEqual("memory:///", transport.base) |
|
201 |
self.assertEqual("memory:///", transport.abspath('/')) |
|
202 |
||
|
2070.3.1
by Andrew Bennetts
Fix memory_transport.abspath('/foo') |
203 |
def test_abspath_of_relpath_starting_at_root(self): |
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
204 |
transport = MemoryTransport() |
|
2070.3.1
by Andrew Bennetts
Fix memory_transport.abspath('/foo') |
205 |
self.assertEqual("memory:///foo", transport.abspath('/foo')) |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
206 |
|
207 |
def test_append_and_get(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
208 |
transport = MemoryTransport() |
|
1955.3.16
by John Arbash Meinel
Switch over to Transport.append_bytes or append_files |
209 |
transport.append_bytes('path', 'content') |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
210 |
self.assertEqual(transport.get('path').read(), 'content') |
|
1955.3.16
by John Arbash Meinel
Switch over to Transport.append_bytes or append_files |
211 |
transport.append_file('path', StringIO('content')) |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
212 |
self.assertEqual(transport.get('path').read(), 'contentcontent') |
213 |
||
214 |
def test_put_and_get(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
215 |
transport = MemoryTransport() |
|
1955.3.7
by John Arbash Meinel
Fix the deprecation warnings in the transport tests themselves |
216 |
transport.put_file('path', StringIO('content')) |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
217 |
self.assertEqual(transport.get('path').read(), 'content') |
|
1955.3.7
by John Arbash Meinel
Fix the deprecation warnings in the transport tests themselves |
218 |
transport.put_bytes('path', 'content') |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
219 |
self.assertEqual(transport.get('path').read(), 'content') |
220 |
||
221 |
def test_append_without_dir_fails(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
222 |
transport = MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
223 |
self.assertRaises(NoSuchFile, |
|
1955.3.16
by John Arbash Meinel
Switch over to Transport.append_bytes or append_files |
224 |
transport.append_bytes, 'dir/path', 'content') |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
225 |
|
226 |
def test_put_without_dir_fails(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
227 |
transport = MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
228 |
self.assertRaises(NoSuchFile, |
|
1955.3.7
by John Arbash Meinel
Fix the deprecation warnings in the transport tests themselves |
229 |
transport.put_file, 'dir/path', StringIO('content')) |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
230 |
|
231 |
def test_get_missing(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
232 |
transport = MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
233 |
self.assertRaises(NoSuchFile, transport.get, 'foo') |
234 |
||
235 |
def test_has_missing(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
236 |
transport = MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
237 |
self.assertEquals(False, transport.has('foo')) |
238 |
||
239 |
def test_has_present(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
240 |
transport = MemoryTransport() |
|
1955.3.16
by John Arbash Meinel
Switch over to Transport.append_bytes or append_files |
241 |
transport.append_bytes('foo', 'content') |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
242 |
self.assertEquals(True, transport.has('foo')) |
243 |
||
|
2120.3.1
by John Arbash Meinel
Fix MemoryTransport.list_dir() implementation, and update tests |
244 |
def test_list_dir(self): |
245 |
transport = MemoryTransport() |
|
246 |
transport.put_bytes('foo', 'content') |
|
247 |
transport.mkdir('dir') |
|
248 |
transport.put_bytes('dir/subfoo', 'content') |
|
249 |
transport.put_bytes('dirlike', 'content') |
|
250 |
||
251 |
self.assertEquals(['dir', 'dirlike', 'foo'], sorted(transport.list_dir('.'))) |
|
252 |
self.assertEquals(['subfoo'], sorted(transport.list_dir('dir'))) |
|
253 |
||
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
254 |
def test_mkdir(self): |
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
255 |
transport = MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
256 |
transport.mkdir('dir') |
|
1955.3.16
by John Arbash Meinel
Switch over to Transport.append_bytes or append_files |
257 |
transport.append_bytes('dir/path', 'content') |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
258 |
self.assertEqual(transport.get('dir/path').read(), 'content') |
259 |
||
260 |
def test_mkdir_missing_parent(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
261 |
transport = MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
262 |
self.assertRaises(NoSuchFile, |
263 |
transport.mkdir, 'dir/dir') |
|
264 |
||
265 |
def test_mkdir_twice(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
266 |
transport = MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
267 |
transport.mkdir('dir') |
268 |
self.assertRaises(FileExists, transport.mkdir, 'dir') |
|
|
1530.1.5
by Robert Collins
Reinstate Memory parameter tests. |
269 |
|
270 |
def test_parameters(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
271 |
transport = MemoryTransport() |
|
1530.1.5
by Robert Collins
Reinstate Memory parameter tests. |
272 |
self.assertEqual(True, transport.listable()) |
273 |
self.assertEqual(False, transport.should_cache()) |
|
274 |
self.assertEqual(False, transport.is_readonly()) |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
275 |
|
276 |
def test_iter_files_recursive(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
277 |
transport = MemoryTransport() |
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
278 |
transport.mkdir('dir') |
|
1955.3.7
by John Arbash Meinel
Fix the deprecation warnings in the transport tests themselves |
279 |
transport.put_bytes('dir/foo', 'content') |
280 |
transport.put_bytes('dir/bar', 'content') |
|
281 |
transport.put_bytes('bar', 'content') |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
282 |
paths = set(transport.iter_files_recursive()) |
283 |
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths) |
|
284 |
||
285 |
def test_stat(self): |
|
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
286 |
transport = MemoryTransport() |
|
1955.3.7
by John Arbash Meinel
Fix the deprecation warnings in the transport tests themselves |
287 |
transport.put_bytes('foo', 'content') |
288 |
transport.put_bytes('bar', 'phowar') |
|
|
1442.1.44
by Robert Collins
Many transport related tweaks: |
289 |
self.assertEqual(7, transport.stat('foo').st_size) |
290 |
self.assertEqual(6, transport.stat('bar').st_size) |
|
|
1185.35.31
by Aaron Bentley
Throw ConnectionError instead of NoSuchFile except when we get a 404 |
291 |
|
|
2070.5.1
by Andrew Bennetts
Add ChrootTransportDecorator. |
292 |
|
293 |
class ChrootDecoratorTransportTest(TestCase): |
|
294 |
"""Chroot decoration specific tests.""" |
|
295 |
||
|
2018.5.54
by Andrew Bennetts
Fix ChrootTransportDecorator's abspath method to be consistent with its clone |
296 |
def test_abspath(self): |
297 |
# The abspath is always relative to the chroot_url.
|
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
298 |
server = ChrootServer(get_transport('memory:///foo/bar/')) |
299 |
server.setUp() |
|
300 |
transport = get_transport(server.get_url()) |
|
301 |
self.assertEqual(server.get_url(), transport.abspath('/')) |
|
|
2018.5.54
by Andrew Bennetts
Fix ChrootTransportDecorator's abspath method to be consistent with its clone |
302 |
|
303 |
subdir_transport = transport.clone('subdir') |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
304 |
self.assertEqual(server.get_url(), subdir_transport.abspath('/')) |
305 |
server.tearDown() |
|
|
2379.2.1
by Robert Collins
Rewritten chroot transport that prevents accidental chroot escapes when |
306 |
|
307 |
def test_clone(self): |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
308 |
server = ChrootServer(get_transport('memory:///foo/bar/')) |
309 |
server.setUp() |
|
310 |
transport = get_transport(server.get_url()) |
|
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
311 |
# relpath from root and root path are the same
|
312 |
relpath_cloned = transport.clone('foo') |
|
313 |
abspath_cloned = transport.clone('/foo') |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
314 |
self.assertEqual(server, relpath_cloned.server) |
315 |
self.assertEqual(server, abspath_cloned.server) |
|
316 |
server.tearDown() |
|
|
2018.5.46
by Andrew Bennetts
Fix ChrootTransportDecorator's clone to pass less surprising offsets to the decorated transport's clone. |
317 |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
318 |
def test_chroot_url_preserves_chroot(self): |
319 |
"""Calling get_transport on a chroot transport's base should produce a |
|
320 |
transport with exactly the same behaviour as the original chroot
|
|
321 |
transport.
|
|
322 |
||
323 |
This is so that it is not possible to escape a chroot by doing::
|
|
324 |
url = chroot_transport.base
|
|
325 |
parent_url = urlutils.join(url, '..')
|
|
326 |
new_transport = get_transport(parent_url)
|
|
327 |
"""
|
|
328 |
server = ChrootServer(get_transport('memory:///path/subpath')) |
|
329 |
server.setUp() |
|
330 |
transport = get_transport(server.get_url()) |
|
331 |
new_transport = get_transport(transport.base) |
|
332 |
self.assertEqual(transport.server, new_transport.server) |
|
333 |
self.assertEqual(transport.base, new_transport.base) |
|
334 |
server.tearDown() |
|
335 |
||
336 |
def test_urljoin_preserves_chroot(self): |
|
337 |
"""Using urlutils.join(url, '..') on a chroot URL should not produce a |
|
338 |
URL that escapes the intended chroot.
|
|
339 |
||
340 |
This is so that it is not possible to escape a chroot by doing::
|
|
341 |
url = chroot_transport.base
|
|
342 |
parent_url = urlutils.join(url, '..')
|
|
343 |
new_transport = get_transport(parent_url)
|
|
344 |
"""
|
|
345 |
server = ChrootServer(get_transport('memory:///path/')) |
|
346 |
server.setUp() |
|
347 |
transport = get_transport(server.get_url()) |
|
348 |
self.assertRaises( |
|
349 |
InvalidURLJoin, urlutils.join, transport.base, '..') |
|
350 |
server.tearDown() |
|
351 |
||
352 |
||
353 |
class ChrootServerTest(TestCase): |
|
354 |
||
355 |
def test_construct(self): |
|
356 |
backing_transport = MemoryTransport() |
|
357 |
server = ChrootServer(backing_transport) |
|
358 |
self.assertEqual(backing_transport, server.backing_transport) |
|
359 |
||
360 |
def test_setUp(self): |
|
361 |
backing_transport = MemoryTransport() |
|
362 |
server = ChrootServer(backing_transport) |
|
363 |
server.setUp() |
|
364 |
self.assertTrue(server.scheme in _protocol_handlers.keys()) |
|
365 |
||
366 |
def test_tearDown(self): |
|
367 |
backing_transport = MemoryTransport() |
|
368 |
server = ChrootServer(backing_transport) |
|
369 |
server.setUp() |
|
370 |
server.tearDown() |
|
371 |
self.assertFalse(server.scheme in _protocol_handlers.keys()) |
|
372 |
||
373 |
def test_get_url(self): |
|
374 |
backing_transport = MemoryTransport() |
|
375 |
server = ChrootServer(backing_transport) |
|
376 |
server.setUp() |
|
377 |
self.assertEqual('chroot-%d:///' % id(server), server.get_url()) |
|
378 |
server.tearDown() |
|
|
2018.5.53
by Andrew Bennetts
Small fix to urlutils.joinpath that was causing a misbehaviour in |
379 |
|
|
2156.2.1
by v.ladeuil+lp at free
Make the tests windows compatible. |
380 |
|
|
1534.4.9
by Robert Collins
Add a readonly decorator for transports. |
381 |
class ReadonlyDecoratorTransportTest(TestCase): |
382 |
"""Readonly decoration specific tests.""" |
|
383 |
||
384 |
def test_local_parameters(self): |
|
385 |
import bzrlib.transport.readonly as readonly |
|
386 |
# connect to . in readonly mode
|
|
387 |
transport = readonly.ReadonlyTransportDecorator('readonly+.') |
|
388 |
self.assertEqual(True, transport.listable()) |
|
389 |
self.assertEqual(False, transport.should_cache()) |
|
390 |
self.assertEqual(True, transport.is_readonly()) |
|
391 |
||
392 |
def test_http_parameters(self): |
|
|
2004.1.25
by v.ladeuil+lp at free
Shuffle http related test code. Hopefully it ends up at the right place :) |
393 |
from bzrlib.tests.HttpServer import HttpServer |
|
1534.4.9
by Robert Collins
Add a readonly decorator for transports. |
394 |
import bzrlib.transport.readonly as readonly |
395 |
# connect to . via http which is not listable
|
|
396 |
server = HttpServer() |
|
397 |
server.setUp() |
|
398 |
try: |
|
399 |
transport = get_transport('readonly+' + server.get_url()) |
|
400 |
self.failUnless(isinstance(transport, |
|
401 |
readonly.ReadonlyTransportDecorator)) |
|
402 |
self.assertEqual(False, transport.listable()) |
|
403 |
self.assertEqual(True, transport.should_cache()) |
|
404 |
self.assertEqual(True, transport.is_readonly()) |
|
405 |
finally: |
|
406 |
server.tearDown() |
|
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
407 |
|
408 |
||
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
409 |
class FakeNFSDecoratorTests(TestCaseInTempDir): |
410 |
"""NFS decorator specific tests.""" |
|
411 |
||
412 |
def get_nfs_transport(self, url): |
|
413 |
import bzrlib.transport.fakenfs as fakenfs |
|
414 |
# connect to url with nfs decoration
|
|
415 |
return fakenfs.FakeNFSTransportDecorator('fakenfs+' + url) |
|
416 |
||
417 |
def test_local_parameters(self): |
|
418 |
# the listable, should_cache and is_readonly parameters
|
|
419 |
# are not changed by the fakenfs decorator
|
|
420 |
transport = self.get_nfs_transport('.') |
|
421 |
self.assertEqual(True, transport.listable()) |
|
422 |
self.assertEqual(False, transport.should_cache()) |
|
423 |
self.assertEqual(False, transport.is_readonly()) |
|
424 |
||
425 |
def test_http_parameters(self): |
|
426 |
# the listable, should_cache and is_readonly parameters
|
|
427 |
# are not changed by the fakenfs decorator
|
|
|
2004.1.25
by v.ladeuil+lp at free
Shuffle http related test code. Hopefully it ends up at the right place :) |
428 |
from bzrlib.tests.HttpServer import HttpServer |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
429 |
# connect to . via http which is not listable
|
430 |
server = HttpServer() |
|
431 |
server.setUp() |
|
432 |
try: |
|
433 |
transport = self.get_nfs_transport(server.get_url()) |
|
434 |
self.assertIsInstance( |
|
435 |
transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator) |
|
436 |
self.assertEqual(False, transport.listable()) |
|
437 |
self.assertEqual(True, transport.should_cache()) |
|
438 |
self.assertEqual(True, transport.is_readonly()) |
|
439 |
finally: |
|
440 |
server.tearDown() |
|
441 |
||
442 |
def test_fakenfs_server_default(self): |
|
443 |
# a FakeNFSServer() should bring up a local relpath server for itself
|
|
444 |
import bzrlib.transport.fakenfs as fakenfs |
|
445 |
server = fakenfs.FakeNFSServer() |
|
446 |
server.setUp() |
|
447 |
try: |
|
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
448 |
# the url should be decorated appropriately
|
|
1951.2.3
by Martin Pool
Localtransport cleanup review (john) |
449 |
self.assertStartsWith(server.get_url(), 'fakenfs+') |
|
1558.10.2
by Robert Collins
Refactor the FakeNFS support into a TransportDecorator. |
450 |
# and we should be able to get a transport for it
|
451 |
transport = get_transport(server.get_url()) |
|
452 |
# which must be a FakeNFSTransportDecorator instance.
|
|
453 |
self.assertIsInstance( |
|
454 |
transport, fakenfs.FakeNFSTransportDecorator) |
|
455 |
finally: |
|
456 |
server.tearDown() |
|
457 |
||
458 |
def test_fakenfs_rename_semantics(self): |
|
459 |
# a FakeNFS transport must mangle the way rename errors occur to
|
|
460 |
# look like NFS problems.
|
|
461 |
transport = self.get_nfs_transport('.') |
|
462 |
self.build_tree(['from/', 'from/foo', 'to/', 'to/bar'], |
|
463 |
transport=transport) |
|
464 |
self.assertRaises(bzrlib.errors.ResourceBusy, |
|
465 |
transport.rename, 'from', 'to') |
|
466 |
||
467 |
||
|
1608.2.4
by Martin Pool
[broken] Add FakeFVATTransport |
468 |
class FakeVFATDecoratorTests(TestCaseInTempDir): |
469 |
"""Tests for simulation of VFAT restrictions""" |
|
470 |
||
471 |
def get_vfat_transport(self, url): |
|
472 |
"""Return vfat-backed transport for test directory""" |
|
473 |
from bzrlib.transport.fakevfat import FakeVFATTransportDecorator |
|
474 |
return FakeVFATTransportDecorator('vfat+' + url) |
|
475 |
||
476 |
def test_transport_creation(self): |
|
477 |
from bzrlib.transport.fakevfat import FakeVFATTransportDecorator |
|
478 |
transport = self.get_vfat_transport('.') |
|
479 |
self.assertIsInstance(transport, FakeVFATTransportDecorator) |
|
480 |
||
481 |
def test_transport_mkdir(self): |
|
482 |
transport = self.get_vfat_transport('.') |
|
483 |
transport.mkdir('HELLO') |
|
484 |
self.assertTrue(transport.has('hello')) |
|
485 |
self.assertTrue(transport.has('Hello')) |
|
486 |
||
|
1608.2.11
by Martin Pool
(FakeVFAT) add test for detection of invalid characters |
487 |
def test_forbidden_chars(self): |
488 |
transport = self.get_vfat_transport('.') |
|
489 |
self.assertRaises(ValueError, transport.has, "<NU>") |
|
490 |
||
491 |
||
|
1540.3.8
by Martin Pool
Some support for falling back between transport implementations. |
492 |
class BadTransportHandler(Transport): |
493 |
def __init__(self, base_url): |
|
494 |
raise DependencyNotPresent('some_lib', 'testing missing dependency') |
|
495 |
||
496 |
||
497 |
class BackupTransportHandler(Transport): |
|
498 |
"""Test transport that works as a backup for the BadTransportHandler""" |
|
|
1540.3.10
by Martin Pool
[broken] keep hooking pycurl into test framework |
499 |
pass
|
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
500 |
|
501 |
||
502 |
class TestTransportImplementation(TestCaseInTempDir): |
|
503 |
"""Implementation verification for transports. |
|
504 |
|
|
505 |
To verify a transport we need a server factory, which is a callable
|
|
506 |
that accepts no parameters and returns an implementation of
|
|
507 |
bzrlib.transport.Server.
|
|
508 |
|
|
509 |
That Server is then used to construct transport instances and test
|
|
510 |
the transport via loopback activity.
|
|
511 |
||
512 |
Currently this assumes that the Transport object is connected to the
|
|
513 |
current working directory. So that whatever is done
|
|
514 |
through the transport, should show up in the working
|
|
515 |
directory, and vice-versa. This is a bug, because its possible to have
|
|
516 |
URL schemes which provide access to something that may not be
|
|
517 |
result in storage on the local disk, i.e. due to file system limits, or
|
|
518 |
due to it being a database or some other non-filesystem tool.
|
|
519 |
||
520 |
This also tests to make sure that the functions work with both
|
|
521 |
generators and lists (assuming iter(list) is effectively a generator)
|
|
522 |
"""
|
|
523 |
||
524 |
def setUp(self): |
|
525 |
super(TestTransportImplementation, self).setUp() |
|
526 |
self._server = self.transport_server() |
|
527 |
self._server.setUp() |
|
|
2018.5.104
by Andrew Bennetts
Completely rework chrooted transports. |
528 |
self.addCleanup(self._server.tearDown) |
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
529 |
|
530 |
def get_transport(self): |
|
531 |
"""Return a connected transport to the local directory.""" |
|
532 |
base_url = self._server.get_url() |
|
533 |
# try getting the transport via the regular interface:
|
|
534 |
t = get_transport(base_url) |
|
|
1986.2.5
by Robert Collins
Unbreak transport tests. |
535 |
if not isinstance(t, self.transport_class): |
|
1871.1.2
by Robert Collins
Reduce code duplication in transport-parameterised tests. |
536 |
# we did not get the correct transport class type. Override the
|
537 |
# regular connection behaviour by direct construction.
|
|
538 |
t = self.transport_class(base_url) |
|
539 |
return t |
|
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
540 |
|
541 |
||
542 |
class TestLocalTransports(TestCase): |
|
543 |
||
544 |
def test_get_transport_from_abspath(self): |
|
545 |
here = os.path.abspath('.') |
|
546 |
t = get_transport(here) |
|
547 |
self.assertIsInstance(t, LocalTransport) |
|
548 |
self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/') |
|
549 |
||
550 |
def test_get_transport_from_relpath(self): |
|
551 |
here = os.path.abspath('.') |
|
552 |
t = get_transport('.') |
|
553 |
self.assertIsInstance(t, LocalTransport) |
|
|
1951.2.3
by Martin Pool
Localtransport cleanup review (john) |
554 |
self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/') |
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
555 |
|
556 |
def test_get_transport_from_local_url(self): |
|
557 |
here = os.path.abspath('.') |
|
558 |
here_url = urlutils.local_path_to_url(here) + '/' |
|
559 |
t = get_transport(here_url) |
|
560 |
self.assertIsInstance(t, LocalTransport) |
|
561 |
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 // |
562 |
|
563 |
||
564 |
class TestWin32LocalTransport(TestCase): |
|
565 |
||
566 |
def test_unc_clone_to_root(self): |
|
567 |
# Win32 UNC path like \\HOST\path
|
|
568 |
# clone to root should stop at least at \\HOST part
|
|
569 |
# not on \\
|
|
|
2245.6.2
by Alexander Belchenko
Fix name of emulated Win32LocalTransport as Robert suggested. |
570 |
t = 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 // |
571 |
for i in xrange(4): |
572 |
t = t.clone('..') |
|
573 |
self.assertEquals(t.base, 'file://HOST/') |
|
574 |
# make sure we reach the root
|
|
575 |
t = t.clone('..') |
|
576 |
self.assertEquals(t.base, 'file://HOST/') |