/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):
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
187
        # bzr can't handle that kind change in a single commit without an
188
        # intervening bzr status (see bug #205636).
189
        self.tree.remove([name], keep_files=False)
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
190
        os.mkdir(base + name)
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
191
        self.tree.add(name)
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
192
        self.tree.commit('change %s from file to dir' % name)
193
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
194
    def _get_cmd_upload(self):
195
        upload = cmd_upload()
196
        # We don't want to use run_bzr here because redirected output are a
197
        # pain to debug. But we need to provides a valid outf.
198
        # XXX: Should a bug against bzr be filled about that ?
199
        upload._setup_outf()
200
        return upload
201
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
202
    def do_full_upload(self, *args, **kwargs):
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
203
        upload = self._get_cmd_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
204
        up_url = self.get_transport(self.upload_dir).external_url()
0.152.11 by Vincent Ladeuil
Be coherent with bzr push.
205
        if kwargs.get('directory', None) is None:
206
            kwargs['directory'] = 'branch'
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
207
        kwargs['full'] = True
0.152.34 by Martin Albisetti
* Change the default behaviour to be more verbose
208
        kwargs['quiet'] = True
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
209
        upload.run(up_url, *args, **kwargs)
210
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
211
    def do_incremental_upload(self, *args, **kwargs):
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
212
        upload = self._get_cmd_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
213
        up_url = self.get_transport(self.upload_dir).external_url()
0.152.11 by Vincent Ladeuil
Be coherent with bzr push.
214
        if kwargs.get('directory', None) is None:
215
            kwargs['directory'] = 'branch'
0.152.34 by Martin Albisetti
* Change the default behaviour to be more verbose
216
        kwargs['quiet'] = True
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
217
        upload.run(up_url, *args, **kwargs)
218
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
219
    def test_create_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
220
        self.make_local_branch()
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
221
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
222
        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).
223
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
224
        self.do_upload()
225
226
        self.assertUpFileEqual('foo', 'hello')
227
228
    def test_create_file_in_subdir(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
229
        self.make_local_branch()
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
230
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
231
        self.add_dir('dir')
232
        self.add_file('dir/goodbye', 'baz')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
233
234
        self.failIfUpFileExists('dir/goodbye')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
235
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
236
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
237
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
238
        self.assertUpFileEqual('baz', 'dir/goodbye')
239
240
    def test_modify_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
241
        self.make_local_branch()
242
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
243
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
244
        self.modify_file('hello', 'bar')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
245
246
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
247
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
248
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
249
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
250
        self.assertUpFileEqual('bar', 'hello')
251
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
252
    def test_rename_one_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
253
        self.make_local_branch()
254
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
255
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
256
        self.rename_any('hello', 'goodbye')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
257
258
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
259
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
260
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
261
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
262
        self.assertUpFileEqual('foo', 'goodbye')
263
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
264
    def test_rename_two_files(self):
265
        self.make_local_branch()
266
        self.add_file('a', 'foo')
267
        self.add_file('b', 'qux')
268
        self.do_full_upload()
269
        # We rely on the assumption that bzr will topologically sort the
270
        # renames which will cause a -> b to appear *before* b -> c
271
        self.rename_any('b', 'c')
272
        self.rename_any('a', 'b')
273
274
        self.assertUpFileEqual('foo', 'a')
275
        self.assertUpFileEqual('qux', 'b')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
276
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
277
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
278
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
279
        self.assertUpFileEqual('foo', 'b')
280
        self.assertUpFileEqual('qux', 'c')
281
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
282
    def test_upload_revision(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
283
        self.make_local_branch() # rev1
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
284
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
285
        self.add_file('hello', 'foo') # rev2
286
        self.modify_file('hello', 'bar') # rev3
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
287
288
        self.failIfUpFileExists('hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
289
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
290
        revspec = revisionspec.RevisionSpec.from_string('2')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
291
        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).
292
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
293
        self.assertUpFileEqual('foo', 'hello')
294
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
295
    def test_no_upload_when_changes(self):
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
296
        self.make_local_branch()
297
        self.add_file('a', 'foo')
298
        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).
299
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
300
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
301
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
302
    def test_no_upload_when_conflicts(self):
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
303
        self.make_local_branch()
304
        self.add_file('a', 'foo')
305
        self.run_bzr('branch branch other')
306
        self.modify_file('a', 'bar')
307
        other_tree = workingtree.WorkingTree.open('other')
308
        self.set_file_content('a', 'baz', 'other/')
309
        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).
310
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
311
        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).
312
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
313
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
314
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
315
    def test_change_file_into_dir(self):
316
        self.make_local_branch()
317
        self.add_file('hello', 'foo')
318
        self.do_full_upload()
319
        self.transform_file_into_dir('hello')
320
        self.add_file('hello/file', 'bar')
321
322
        self.assertUpFileEqual('foo', 'hello')
323
324
        self.do_upload()
325
326
        self.assertUpFileEqual('bar', 'hello/file')
327
328
    def test_change_dir_into_file(self):
329
        self.make_local_branch()
330
        self.add_dir('hello')
331
        self.add_file('hello/file', 'foo')
332
        self.do_full_upload()
333
        self.delete_any('hello/file')
334
        self.transform_dir_into_file('hello', 'bar')
335
336
        self.assertUpFileEqual('foo', 'hello/file')
337
338
        self.do_upload()
339
340
        self.assertUpFileEqual('bar', 'hello')
341
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
342
343
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
344
345
    do_upload = TestUploadMixin.do_full_upload
346
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
347
    def test_full_upload_empty_tree(self):
348
        self.make_local_branch()
349
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
350
        self.do_full_upload()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
351
0.152.31 by Vincent Ladeuil
Cosmetic change.
352
        self.failUnlessUpFileExists(cmd_upload.bzr_upload_revid_file_name)
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
353
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
354
    def test_invalid_revspec(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
355
        self.make_local_branch()
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
356
        rev1 = revisionspec.RevisionSpec.from_string('1')
357
        rev2 = revisionspec.RevisionSpec.from_string('2')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
358
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
359
        self.assertRaises(errors.BzrCommandError,
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
360
                          self.do_incremental_upload, revision=[rev1, rev2])
361
362
363
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
364
365
    do_upload = TestUploadMixin.do_incremental_upload
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
366
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
367
    # XXX: full upload doesn't handle deletions....
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
368
369
    def test_delete_one_file(self):
370
        self.make_local_branch()
371
        self.add_file('hello', 'foo')
372
        self.do_full_upload()
373
        self.delete_any('hello')
374
375
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
376
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
377
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
378
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
379
        self.failIfUpFileExists('hello')
380
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
381
    def test_delete_dir_and_subdir(self):
382
        self.make_local_branch()
383
        self.add_dir('dir')
384
        self.add_dir('dir/subdir')
385
        self.add_file('dir/subdir/a', 'foo')
386
        self.do_full_upload()
387
        self.rename_any('dir/subdir/a', 'a')
388
        self.delete_any('dir/subdir')
389
        self.delete_any('dir')
390
391
        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).
392
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
393
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
394
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
395
        self.failIfUpFileExists('dir/subdir/a')
396
        self.failIfUpFileExists('dir/subdir')
397
        self.failIfUpFileExists('dir')
398
        self.assertUpFileEqual('foo', 'a')
399
400
    def test_delete_one_file_rename_to_deleted(self):
401
        self.make_local_branch()
402
        self.add_file('a', 'foo')
403
        self.add_file('b', 'bar')
404
        self.do_full_upload()
405
        self.delete_any('a')
406
        self.rename_any('b', 'a')
407
408
        self.assertUpFileEqual('foo', 'a')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
409
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
410
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
411
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
412
        self.failIfUpFileExists('b')
413
        self.assertUpFileEqual('bar', 'a')
414
415
    def test_rename_outside_dir_delete_dir(self):
416
        self.make_local_branch()
417
        self.add_dir('dir')
418
        self.add_file('dir/a', 'foo')
419
        self.do_full_upload()
420
        self.rename_any('dir/a', 'a')
421
        self.delete_any('dir')
422
423
        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).
424
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
425
        self.do_upload()
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.failIfUpFileExists('dir/a')
428
        self.failIfUpFileExists('dir')
429
        self.assertUpFileEqual('foo', 'a')
430
0.152.31 by Vincent Ladeuil
Cosmetic change.
431
    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
432
        self.make_local_branch()
433
        self.add_file('hello', 'bar')
0.152.31 by Vincent Ladeuil
Cosmetic change.
434
435
        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).
436
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
437
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
438
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
439
        self.assertUpFileEqual('bar', 'hello')
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
440
0.153.1 by Vincent Ladeuil
Clean up references to verbose.
441
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
442
class TestBranchUploadLocations(branch_implementations.TestCaseWithBranch):
443
444
    def test_get_upload_location_unset(self):
445
        config = self.get_branch().get_config()
446
        self.assertEqual(None, config.get_user_option('upload_location'))
447
448
    def test_get_push_location_exact(self):
449
        from bzrlib.config import (locations_config_filename,
450
                                   ensure_config_dir_exists)
451
        ensure_config_dir_exists()
452
        fn = locations_config_filename()
453
        b = self.get_branch()
454
        open(fn, 'wt').write(("[%s]\n"
455
                                  "upload_location=foo\n" %
456
                                  b.base[:-1]))
457
        config = b.get_config()
458
        self.assertEqual("foo", config.get_user_option('upload_location'))
459
460
    def test_set_push_location(self):
461
        config = self.get_branch().get_config()
462
        config.set_user_option('upload_location', 'foo')
463
        self.assertEqual('foo', config.get_user_option('upload_location'))
464