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