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