/brz/remove-bazaar

To get this branch, use:
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
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
18
import sys
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
19
20
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
21
from bzrlib import (
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
22
    branch,
0.152.8 by Vincent Ladeuil
Handle uploading directories.
23
    bzrdir,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
24
    errors,
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
25
    osutils,
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
26
    remote,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
27
    revisionspec,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
28
    tests,
0.152.8 by Vincent Ladeuil
Handle uploading directories.
29
    transport,
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
30
    workingtree,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
31
    )
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
32
from bzrlib.smart import server as smart_server
33
34
from bzrlib.tests import (
35
    test_transport_implementations,
36
    branch_implementations,
37
    )
38
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
39
40
from bzrlib.plugins.upload import cmd_upload
0.152.1 by Vincent Ladeuil
Empty shell
41
42
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
43
class TransportAdapter(
44
    test_transport_implementations.TransportTestProviderAdapter):
45
    """A tool to generate a suite testing all transports for a single test.
46
47
    We restrict the transports to the ones we want to support.
48
    """
49
50
    def _test_permutations(self):
51
        """Return a list of the klass, server_factory pairs to test."""
52
        result = []
53
        transport_modules =['bzrlib.transport.ftp',
54
                            'bzrlib.transport.sftp']
55
        for module in transport_modules:
56
            try:
57
                permutations = self.get_transport_test_permutations(
58
                    reduce(getattr, (module).split('.')[1:],
59
                           __import__(module)))
60
                for (klass, server_factory) in permutations:
61
                    scenario = (server_factory.__name__,
62
                        {"transport_class":klass,
63
                         "transport_server":server_factory})
64
                    result.append(scenario)
65
            except errors.DependencyNotPresent, e:
66
                # Continue even if a dependency prevents us 
67
                # from adding this test
68
                pass
69
        return result
70
71
72
def load_tests(standard_tests, module, loader):
73
    """Multiply tests for tranport implementations."""
74
    result = loader.suiteClass()
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
75
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
76
    is_testing_for_transports = tests.condition_isinstance(
77
        (TestFullUpload,
78
         TestIncrementalUpload,))
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
79
    transport_adapter = TransportAdapter()
80
81
    is_testing_for_branches = tests.condition_isinstance(
82
        (TestBranchUploadLocations,))
83
    # Generate a list of branch formats and their associated bzrdir formats to
84
    # use.
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
85
    # XXX: This was copied from bzrlib.tests.branch_implementations.tests_suite
86
    # and need to be shared in a better way.
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
87
    combinations = [(format, format._matchingbzrdir) for format in
88
         branch.BranchFormat._formats.values() + branch._legacy_formats]
89
    BTPA = branch_implementations.BranchTestProviderAdapter
90
    branch_adapter = BTPA(
91
        # None here will cause the default vfs transport server to be used.
92
        None,
93
        # None here will cause a readonly decorator to be created
94
        # by the TestCaseWithTransport.get_readonly_transport method.
95
        None,
96
        combinations)
97
    branch_adapter_for_ss = BTPA(
98
        smart_server.SmartTCPServer_for_testing,
99
        smart_server.ReadonlySmartTCPServer_for_testing,
100
        [(remote.RemoteBranchFormat(), remote.RemoteBzrDirFormat())],
101
        # XXX: Report to bzr list, this parameter is not used in the
102
        # constructor
103
104
        # MemoryServer
105
        )
106
107
    for test_class in tests.iter_suite_tests(standard_tests):
108
        # Each test class is either standalone or testing for some combination
109
        # of transport or branch. Use the right adpater (or none) depending on
110
        # the class.
111
        if is_testing_for_transports(test_class):
112
            result.addTests(transport_adapter.adapt(test_class))
113
        elif is_testing_for_branches(test_class):
114
            result.addTests(branch_adapter.adapt(test_class))
115
            result.addTests(branch_adapter_for_ss.adapt(test_class))
116
        else:
117
            result.addTest(test_class)
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
118
    return result
119
120
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
121
class TestUploadMixin(object):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
122
    """Helper class to share tests between full and incremental uploads.
123
124
    This class also provides helpers to simplify test writing. The emphasis is
125
    on easy test writing, so each tree modification is committed. This doesn't
126
    preclude writing tests spawning several revisions to upload more complex
127
    changes.
128
    """
129
130
    upload_dir = 'upload/'
131
    branch_dir = 'branch/'
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
132
0.152.10 by Vincent Ladeuil
Fix incremental upload cheat.
133
    def make_local_branch(self):
0.152.8 by Vincent Ladeuil
Handle uploading directories.
134
        t = transport.get_transport('branch')
135
        t.ensure_base()
136
        branch = bzrdir.BzrDir.create_branch_convenience(
137
            t.base,
138
            format=bzrdir.format_registry.make_bzrdir('default'),
139
            force_new_tree=False)
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
140
        self.tree = branch.bzrdir.create_workingtree()
141
        self.tree.commit('initial empty tree')
142
143
    def assertUpFileEqual(self, content, path, base=upload_dir):
144
        self.assertFileEqual(content, base + path)
145
146
    def failIfUpFileExists(self, path, base=upload_dir):
147
        self.failIfExists(base + path)
148
149
    def failUnlessUpFileExists(self, path, base=upload_dir):
150
        self.failUnlessExists(base + path)
151
152
    def set_file_content(self, name, content, base=branch_dir):
153
        f = file(base + name, 'wb')
154
        try:
155
            f.write(content)
156
        finally:
157
            f.close()
158
159
    def add_file(self, name, content, base=branch_dir):
160
        self.set_file_content(name, content, base)
161
        self.tree.add(name)
162
        self.tree.commit('add file %s' % name)
163
164
    def modify_file(self, name, content, base=branch_dir):
165
        self.set_file_content(name, content, base)
166
        self.tree.commit('modify file %s' % name)
167
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
168
    def delete_any(self, name, base=branch_dir):
169
        self.tree.remove([name], keep_files=False)
170
        self.tree.commit('delete %s' % name)
171
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
172
    def add_dir(self, name, base=branch_dir):
173
        os.mkdir(base + name)
174
        self.tree.add(name)
175
        self.tree.commit('add directory %s' % name)
176
177
    def rename_any(self, old_name, new_name):
178
        self.tree.rename_one(old_name, new_name)
179
        self.tree.commit('rename %s into %s' % (old_name, new_name))
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
180
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
181
    def transform_dir_into_file(self, name, content, base=branch_dir):
182
        osutils.delete_any(base + name)
183
        self.set_file_content(name, content, base)
184
        self.tree.commit('change %s from dir to file' % name)
185
186
    def transform_file_into_dir(self, name, base=branch_dir):
187
        osutils.delete_any(base + name)
188
        os.mkdir(base + name)
189
        self.tree.commit('change %s from file to dir' % name)
190
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
191
    def _get_cmd_upload(self):
192
        upload = cmd_upload()
193
        # We don't want to use run_bzr here because redirected output are a
194
        # pain to debug. But we need to provides a valid outf.
195
        # XXX: Should a bug against bzr be filled about that ?
196
        upload._setup_outf()
197
        return upload
198
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
199
    def do_full_upload(self, *args, **kwargs):
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
200
        upload = self._get_cmd_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
201
        up_url = self.get_transport(self.upload_dir).external_url()
0.152.11 by Vincent Ladeuil
Be coherent with bzr push.
202
        if kwargs.get('directory', None) is None:
203
            kwargs['directory'] = 'branch'
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
204
        kwargs['full'] = True
0.152.34 by Martin Albisetti
* Change the default behaviour to be more verbose
205
        kwargs['quiet'] = True
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
206
        upload.run(up_url, *args, **kwargs)
207
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
208
    def do_incremental_upload(self, *args, **kwargs):
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
209
        upload = self._get_cmd_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
210
        up_url = self.get_transport(self.upload_dir).external_url()
0.152.11 by Vincent Ladeuil
Be coherent with bzr push.
211
        if kwargs.get('directory', None) is None:
212
            kwargs['directory'] = 'branch'
0.152.34 by Martin Albisetti
* Change the default behaviour to be more verbose
213
        kwargs['quiet'] = True
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
214
        upload.run(up_url, *args, **kwargs)
215
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
216
    def test_create_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
217
        self.make_local_branch()
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
218
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
219
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
220
        self.do_upload()
221
222
        self.assertUpFileEqual('foo', 'hello')
223
224
    def test_create_file_in_subdir(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
225
        self.make_local_branch()
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
226
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
227
        self.add_dir('dir')
228
        self.add_file('dir/goodbye', 'baz')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
229
230
        self.failIfUpFileExists('dir/goodbye')
231
        self.do_upload()
232
        self.assertUpFileEqual('baz', 'dir/goodbye')
233
234
    def test_modify_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
235
        self.make_local_branch()
236
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
237
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
238
        self.modify_file('hello', 'bar')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
239
240
        self.assertUpFileEqual('foo', 'hello')
241
        self.do_upload()
242
        self.assertUpFileEqual('bar', 'hello')
243
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
244
    def test_rename_one_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
245
        self.make_local_branch()
246
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
247
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
248
        self.rename_any('hello', 'goodbye')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
249
250
        self.assertUpFileEqual('foo', 'hello')
251
        self.do_upload()
252
        self.assertUpFileEqual('foo', 'goodbye')
253
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
254
    def test_rename_two_files(self):
255
        self.make_local_branch()
256
        self.add_file('a', 'foo')
257
        self.add_file('b', 'qux')
258
        self.do_full_upload()
259
        # We rely on the assumption that bzr will topologically sort the
260
        # renames which will cause a -> b to appear *before* b -> c
261
        self.rename_any('b', 'c')
262
        self.rename_any('a', 'b')
263
264
        self.assertUpFileEqual('foo', 'a')
265
        self.assertUpFileEqual('qux', 'b')
266
        self.do_upload()
267
        self.assertUpFileEqual('foo', 'b')
268
        self.assertUpFileEqual('qux', 'c')
269
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
270
    def test_upload_revision(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
271
        self.make_local_branch() # rev1
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
272
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
273
        self.add_file('hello', 'foo') # rev2
274
        self.modify_file('hello', 'bar') # rev3
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
275
276
        self.failIfUpFileExists('hello')
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
277
        revspec = revisionspec.RevisionSpec.from_string('2')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
278
        self.do_upload(revision=[revspec])
279
        self.assertUpFileEqual('foo', 'hello')
280
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
281
    def test_upload_when_changes(self):
282
        self.make_local_branch()
283
        self.add_file('a', 'foo')
284
        self.set_file_content('a', 'bar')
285
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
286
287
    def test_upload_when_conflicts(self):
288
        self.make_local_branch()
289
        self.add_file('a', 'foo')
290
        self.run_bzr('branch branch other')
291
        self.modify_file('a', 'bar')
292
        other_tree = workingtree.WorkingTree.open('other')
293
        self.set_file_content('a', 'baz', 'other/')
294
        other_tree.commit('modify file a')
295
        self.run_bzr('merge -d branch other', retcode=1)
296
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
297
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
298
299
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
300
301
    do_upload = TestUploadMixin.do_full_upload
302
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
303
    def test_full_upload_empty_tree(self):
304
        self.make_local_branch()
305
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
306
        self.do_full_upload()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
307
0.152.31 by Vincent Ladeuil
Cosmetic change.
308
        self.failUnlessUpFileExists(cmd_upload.bzr_upload_revid_file_name)
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
309
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
310
    def test_invalid_revspec(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
311
        self.make_local_branch()
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
312
        rev1 = revisionspec.RevisionSpec.from_string('1')
313
        rev2 = revisionspec.RevisionSpec.from_string('2')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
314
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
315
        self.assertRaises(errors.BzrCommandError,
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
316
                          self.do_incremental_upload, revision=[rev1, rev2])
317
318
319
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
320
321
    do_upload = TestUploadMixin.do_incremental_upload
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
322
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
323
    # XXX: full upload doesn't handle deletions....
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
324
325
    def test_delete_one_file(self):
326
        self.make_local_branch()
327
        self.add_file('hello', 'foo')
328
        self.do_full_upload()
329
        self.delete_any('hello')
330
331
        self.assertUpFileEqual('foo', 'hello')
332
        self.do_upload()
333
        self.failIfUpFileExists('hello')
334
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
335
    def test_delete_dir_and_subdir(self):
336
        self.make_local_branch()
337
        self.add_dir('dir')
338
        self.add_dir('dir/subdir')
339
        self.add_file('dir/subdir/a', 'foo')
340
        self.do_full_upload()
341
        self.rename_any('dir/subdir/a', 'a')
342
        self.delete_any('dir/subdir')
343
        self.delete_any('dir')
344
345
        self.assertUpFileEqual('foo', 'dir/subdir/a')
346
        self.do_upload()
347
        self.failIfUpFileExists('dir/subdir/a')
348
        self.failIfUpFileExists('dir/subdir')
349
        self.failIfUpFileExists('dir')
350
        self.assertUpFileEqual('foo', 'a')
351
352
    def test_delete_one_file_rename_to_deleted(self):
353
        self.make_local_branch()
354
        self.add_file('a', 'foo')
355
        self.add_file('b', 'bar')
356
        self.do_full_upload()
357
        self.delete_any('a')
358
        self.rename_any('b', 'a')
359
360
        self.assertUpFileEqual('foo', 'a')
361
        self.do_upload()
362
        self.failIfUpFileExists('b')
363
        self.assertUpFileEqual('bar', 'a')
364
365
    def test_rename_outside_dir_delete_dir(self):
366
        self.make_local_branch()
367
        self.add_dir('dir')
368
        self.add_file('dir/a', 'foo')
369
        self.do_full_upload()
370
        self.rename_any('dir/a', 'a')
371
        self.delete_any('dir')
372
373
        self.assertUpFileEqual('foo', 'dir/a')
374
        self.do_upload()
375
        self.failIfUpFileExists('dir/a')
376
        self.failIfUpFileExists('dir')
377
        self.assertUpFileEqual('foo', 'a')
378
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
379
    # XXX: full upload doesn't handle kind changes
380
381
    def test_change_file_into_dir(self):
0.152.20 by Vincent Ladeuil
Fix wrong expected failure.
382
        raise tests.KnownFailure('bug 205636')
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
383
        self.make_local_branch()
384
        self.add_file('hello', 'foo')
385
        self.do_full_upload()
386
        self.transform_file_into_dir('hello')
387
        self.add_file('hello/file', 'bar')
388
389
        self.assertUpFileEqual('foo', 'hello')
390
        self.do_upload()
391
        self.assertUpFileEqual('bar', 'hello/file')
392
393
    def test_change_dir_into_file(self):
394
        self.make_local_branch()
395
        self.add_dir('hello')
396
        self.add_file('hello/file', 'foo')
397
        self.do_full_upload()
398
        self.delete_any('hello/file')
399
        self.transform_dir_into_file('hello', 'bar')
400
401
        self.assertUpFileEqual('foo', 'hello/file')
402
        self.do_upload()
403
        self.assertUpFileEqual('bar', 'hello')
404
0.152.31 by Vincent Ladeuil
Cosmetic change.
405
    def test_upload_for_the_first_time_do_a_full_upload(self):
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
406
        self.make_local_branch()
407
        self.add_file('hello', 'bar')
0.152.31 by Vincent Ladeuil
Cosmetic change.
408
409
        self.failIfUpFileExists(cmd_upload.bzr_upload_revid_file_name)
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
410
        self.do_upload()
411
        self.assertUpFileEqual('bar', 'hello')
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
412
0.153.1 by Vincent Ladeuil
Clean up references to verbose.
413
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
414
class TestBranchUploadLocations(branch_implementations.TestCaseWithBranch):
415
416
    def test_get_upload_location_unset(self):
417
        config = self.get_branch().get_config()
418
        self.assertEqual(None, config.get_user_option('upload_location'))
419
420
    def test_get_push_location_exact(self):
421
        from bzrlib.config import (locations_config_filename,
422
                                   ensure_config_dir_exists)
423
        ensure_config_dir_exists()
424
        fn = locations_config_filename()
425
        b = self.get_branch()
426
        open(fn, 'wt').write(("[%s]\n"
427
                                  "upload_location=foo\n" %
428
                                  b.base[:-1]))
429
        config = b.get_config()
430
        self.assertEqual("foo", config.get_user_option('upload_location'))
431
432
    def test_set_push_location(self):
433
        config = self.get_branch().get_config()
434
        config.set_user_option('upload_location', 'foo')
435
        self.assertEqual('foo', config.get_user_option('upload_location'))
436