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