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