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