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