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