bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.152.6
by Vincent Ladeuil
Really use the transports and test against all targeted protocols. |
1 |
# Copyright (C) 2008 Canonical Ltd
|
|
0.152.1
by Vincent Ladeuil
Empty shell |
2 |
#
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
17 |
import os |
18 |
||
19 |
||
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
20 |
from bzrlib import ( |
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
21 |
branch, |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
22 |
bzrdir, |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
23 |
errors, |
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
24 |
remote, |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
25 |
revisionspec, |
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
26 |
tests, |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
27 |
transport, |
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
28 |
)
|
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
29 |
from bzrlib.smart import server as smart_server |
30 |
||
31 |
from bzrlib.tests import ( |
|
32 |
test_transport_implementations, |
|
33 |
branch_implementations, |
|
34 |
)
|
|
35 |
||
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
36 |
|
37 |
from bzrlib.plugins.upload import cmd_upload |
|
|
0.152.1
by Vincent Ladeuil
Empty shell |
38 |
|
39 |
||
|
0.152.6
by Vincent Ladeuil
Really use the transports and test against all targeted protocols. |
40 |
class TransportAdapter( |
41 |
test_transport_implementations.TransportTestProviderAdapter): |
|
42 |
"""A tool to generate a suite testing all transports for a single test. |
|
43 |
||
44 |
We restrict the transports to the ones we want to support.
|
|
45 |
"""
|
|
46 |
||
47 |
def _test_permutations(self): |
|
48 |
"""Return a list of the klass, server_factory pairs to test.""" |
|
49 |
result = [] |
|
50 |
transport_modules =['bzrlib.transport.ftp', |
|
51 |
'bzrlib.transport.sftp'] |
|
52 |
for module in transport_modules: |
|
53 |
try: |
|
54 |
permutations = self.get_transport_test_permutations( |
|
55 |
reduce(getattr, (module).split('.')[1:], |
|
56 |
__import__(module))) |
|
57 |
for (klass, server_factory) in permutations: |
|
58 |
scenario = (server_factory.__name__, |
|
59 |
{"transport_class":klass, |
|
60 |
"transport_server":server_factory}) |
|
61 |
result.append(scenario) |
|
62 |
except errors.DependencyNotPresent, e: |
|
63 |
# Continue even if a dependency prevents us
|
|
64 |
# from adding this test
|
|
65 |
pass
|
|
66 |
return result |
|
67 |
||
68 |
||
69 |
def load_tests(standard_tests, module, loader): |
|
70 |
"""Multiply tests for tranport implementations.""" |
|
71 |
result = loader.suiteClass() |
|
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
72 |
|
73 |
is_testing_for_transports = tests.condition_isinstance((TestUpload,)) |
|
74 |
transport_adapter = TransportAdapter() |
|
75 |
||
76 |
is_testing_for_branches = tests.condition_isinstance( |
|
77 |
(TestBranchUploadLocations,)) |
|
78 |
# Generate a list of branch formats and their associated bzrdir formats to
|
|
79 |
# use.
|
|
80 |
combinations = [(format, format._matchingbzrdir) for format in |
|
81 |
branch.BranchFormat._formats.values() + branch._legacy_formats] |
|
82 |
BTPA = branch_implementations.BranchTestProviderAdapter |
|
83 |
branch_adapter = BTPA( |
|
84 |
# None here will cause the default vfs transport server to be used.
|
|
85 |
None, |
|
86 |
# None here will cause a readonly decorator to be created
|
|
87 |
# by the TestCaseWithTransport.get_readonly_transport method.
|
|
88 |
None, |
|
89 |
combinations) |
|
90 |
branch_adapter_for_ss = BTPA( |
|
91 |
smart_server.SmartTCPServer_for_testing, |
|
92 |
smart_server.ReadonlySmartTCPServer_for_testing, |
|
93 |
[(remote.RemoteBranchFormat(), remote.RemoteBzrDirFormat())], |
|
94 |
# XXX: Report to bzr list, this parameter is not used in the
|
|
95 |
# constructor
|
|
96 |
||
97 |
# MemoryServer
|
|
98 |
)
|
|
99 |
||
100 |
for test_class in tests.iter_suite_tests(standard_tests): |
|
101 |
# Each test class is either standalone or testing for some combination
|
|
102 |
# of transport or branch. Use the right adpater (or none) depending on
|
|
103 |
# the class.
|
|
104 |
if is_testing_for_transports(test_class): |
|
105 |
result.addTests(transport_adapter.adapt(test_class)) |
|
106 |
elif is_testing_for_branches(test_class): |
|
107 |
result.addTests(branch_adapter.adapt(test_class)) |
|
108 |
result.addTests(branch_adapter_for_ss.adapt(test_class)) |
|
109 |
else: |
|
110 |
result.addTest(test_class) |
|
|
0.152.6
by Vincent Ladeuil
Really use the transports and test against all targeted protocols. |
111 |
return result |
112 |
||
113 |
||
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
114 |
class TestUpload(tests.TestCaseWithTransport): |
115 |
||
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
116 |
def make_local_branch(self): |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
117 |
t = transport.get_transport('branch') |
118 |
t.ensure_base() |
|
119 |
branch = bzrdir.BzrDir.create_branch_convenience( |
|
120 |
t.base, |
|
121 |
format=bzrdir.format_registry.make_bzrdir('default'), |
|
122 |
force_new_tree=False) |
|
123 |
tree = branch.bzrdir.create_workingtree() |
|
124 |
return tree |
|
125 |
||
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
126 |
def build_branch_contents(self, reltree, relpath='branch/'): |
127 |
"""Build the tree content at relpath.""" |
|
128 |
abstree = [] |
|
129 |
for relitem in reltree: |
|
130 |
abstree.append((relpath + relitem[0],) + relitem[1:]) |
|
131 |
self.build_tree_contents(abstree) |
|
132 |
||
133 |
def assertUpFileEqual(self, content, path, relpath='upload/'): |
|
134 |
self.assertFileEqual(content, relpath + path) |
|
135 |
||
136 |
def failIfUpFileExists(self, path, relpath='upload/'): |
|
137 |
self.failIfExists(relpath + path) |
|
138 |
||
|
0.152.13
by Vincent Ladeuil
Test uploading an empty tree. |
139 |
def failUnlessUpFileExists(self, path, relpath='upload/'): |
140 |
self.failUnlessExists(relpath + path) |
|
141 |
||
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
142 |
def full_upload(self, *args, **kwargs): |
143 |
upload = cmd_upload() |
|
144 |
up_url = self.get_transport('upload').external_url() |
|
|
0.152.11
by Vincent Ladeuil
Be coherent with bzr push. |
145 |
if kwargs.get('directory', None) is None: |
146 |
kwargs['directory'] = 'branch' |
|
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
147 |
kwargs['full'] = True |
148 |
upload.run(up_url, *args, **kwargs) |
|
149 |
||
150 |
def incremental_upload(self, *args, **kwargs): |
|
151 |
upload = cmd_upload() |
|
152 |
up_url = self.get_transport('upload').external_url() |
|
|
0.152.11
by Vincent Ladeuil
Be coherent with bzr push. |
153 |
if kwargs.get('directory', None) is None: |
154 |
kwargs['directory'] = 'branch' |
|
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
155 |
upload.run(up_url, *args, **kwargs) |
156 |
||
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
157 |
def _add_hello(self, tree): |
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
158 |
self.build_branch_contents([('hello', 'foo')]) |
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
159 |
tree.add('hello') |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
160 |
tree.commit('add hello') |
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
161 |
|
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
162 |
def _modify_hello_add_goodbye(self, tree): |
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
163 |
self.build_branch_contents([('hello', 'bar'), |
164 |
('dir/',), |
|
165 |
('dir/goodbye', 'baz')]) |
|
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
166 |
tree.add('dir') |
167 |
tree.add('dir/goodbye') |
|
168 |
tree.commit('modify hello, add goodbye') |
|
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
169 |
|
|
0.152.13
by Vincent Ladeuil
Test uploading an empty tree. |
170 |
def test_full_upload_empty_tree(self): |
171 |
self.make_local_branch() |
|
172 |
||
173 |
self.full_upload() |
|
174 |
||
175 |
upload = cmd_upload() |
|
176 |
self.failUnlessUpFileExists(upload.bzr_upload_revid_file_name) |
|
177 |
||
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
178 |
def test_full_upload(self): |
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
179 |
tree = self.make_local_branch() |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
180 |
self._add_hello(tree) |
181 |
self._modify_hello_add_goodbye(tree) |
|
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
182 |
|
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
183 |
self.full_upload() |
184 |
||
185 |
self.assertUpFileEqual('bar', 'hello') |
|
186 |
self.assertUpFileEqual('baz', 'dir/goodbye') |
|
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
187 |
|
188 |
def test_incremental_upload(self): |
|
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
189 |
tree = self.make_local_branch() |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
190 |
self._add_hello(tree) |
191 |
self._modify_hello_add_goodbye(tree) |
|
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
192 |
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
193 |
# Upload revision 1 only
|
194 |
revspec = revisionspec.RevisionSpec.from_string('1') |
|
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
195 |
self.full_upload(revision=[revspec]) |
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
196 |
|
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
197 |
self.assertUpFileEqual('foo', 'hello') |
198 |
self.failIfUpFileExists('upload/dir/goodbye') |
|
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
199 |
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
200 |
# Upload current revision
|
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
201 |
self.incremental_upload() |
|
0.152.2
by v.ladeuil+lp at free
Add failing tests for basic usage. |
202 |
|
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
203 |
self.assertUpFileEqual('bar', 'hello') |
204 |
self.assertUpFileEqual('baz', 'dir/goodbye') |
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
205 |
|
206 |
def test_invalid_revspec(self): |
|
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
207 |
tree = self.make_local_branch() |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
208 |
rev1 = revisionspec.RevisionSpec.from_string('1') |
209 |
rev2 = revisionspec.RevisionSpec.from_string('2') |
|
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
210 |
|
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
211 |
self.full_upload() |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
212 |
|
|
0.152.9
by Vincent Ladeuil
Recfactoring to simplify tests writing. |
213 |
self.assertRaises(errors.BzrCommandError, |
214 |
self.incremental_upload, revision=[rev1, rev2]) |
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
215 |
|
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
216 |
|
217 |
class TestBranchUploadLocations(branch_implementations.TestCaseWithBranch): |
|
218 |
||
219 |
def test_get_upload_location_unset(self): |
|
220 |
config = self.get_branch().get_config() |
|
221 |
self.assertEqual(None, config.get_user_option('upload_location')) |
|
222 |
||
223 |
def test_get_push_location_exact(self): |
|
224 |
from bzrlib.config import (locations_config_filename, |
|
225 |
ensure_config_dir_exists) |
|
226 |
ensure_config_dir_exists() |
|
227 |
fn = locations_config_filename() |
|
228 |
b = self.get_branch() |
|
229 |
open(fn, 'wt').write(("[%s]\n" |
|
230 |
"upload_location=foo\n" % |
|
231 |
b.base[:-1])) |
|
232 |
config = b.get_config() |
|
233 |
self.assertEqual("foo", config.get_user_option('upload_location')) |
|
234 |
||
235 |
def test_set_push_location(self): |
|
236 |
config = self.get_branch().get_config() |
|
237 |
config.set_user_option('upload_location', 'foo') |
|
238 |
self.assertEqual('foo', config.get_user_option('upload_location')) |
|
239 |