/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.5 by Gary van der Merwe
Push using lower level api to avoid output.
21
from cStringIO import StringIO
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.5 by Gary van der Merwe
Push using lower level api to avoid output.
34
from bzrlib.push import _show_push_branch
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.5 by Gary van der Merwe
Push using lower level api to avoid output.
164
        self.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.5 by Gary van der Merwe
Push using lower level api to avoid output.
168
        self.tree = self.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()
422
        self.add_file('hello', 'foo')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
423
        try:
424
            self.assertFalse(self.get_upload_auto())
425
        except errors.NotBranchError:
426
            pass
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
427
        self.do_full_upload(auto=True)
428
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
429
        self.assertTrue(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
430
        # and check that it stays set until it is unset
431
        self.add_file('bye', 'bar')
432
        self.do_full_upload()
433
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
434
        self.assertTrue(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
435
436
    def test_upload_noauto(self):
437
        """Test that upload --no-auto unsets the upload_auto option"""
438
        self.make_local_branch()
439
        self.add_file('hello', 'foo')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
440
        try:
441
            self.assertFalse(self.get_upload_auto())
442
        except errors.NotBranchError:
0.158.7 by Gary van der Merwe
Clean up white space.
443
            pass
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
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.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
447
        self.add_file('bye', 'bar')
448
        self.do_full_upload(auto=False)
449
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
450
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
451
        # and check that it stays unset until it is set
452
        self.add_file('again', 'baz')
453
        self.do_full_upload()
454
        self.assertUpFileEqual('baz', 'again')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
455
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
456
0.156.1 by James Westby
Use open_containing rather than open, so that you can upload from a subdir.
457
    def test_upload_from_subdir(self):
458
        self.make_local_branch()
459
        self.build_tree(['branch/foo/', 'branch/foo/bar'])
460
        self.tree.add(['foo/', 'foo/bar'])
461
        self.tree.commit("Add directory")
462
        self.do_full_upload(directory='branch/foo')
463
0.158.9 by Gary van der Merwe
Add a check to make sure we are not uploading to an existing wt.
464
    def test_no_upload_remote_wt(self):
465
        self.make_local_branch()
466
        self.add_file('hello', 'foo')
467
468
        #Create branch in remote tree to create wt
469
        t = transport.get_transport(self.upload_dir)
470
        self.branch = bzrdir.BzrDir.create_branch_convenience(
471
            t.base,
472
            format=bzrdir.format_registry.make_bzrdir('default'),
473
            force_new_tree=True)
474
475
        self.assertRaises(CannotUploadToWT, self.do_upload)
476
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
477
478
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
479
480
    do_upload = TestUploadMixin.do_full_upload
481
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
482
    def test_full_upload_empty_tree(self):
483
        self.make_local_branch()
484
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
485
        self.do_full_upload()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
486
0.155.1 by James Westby
Switch most of the logic to a class outside of the command class.
487
        self.failUnlessUpFileExists(BzrUploader.bzr_upload_revid_file_name)
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
488
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
489
    def test_invalid_revspec(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
490
        self.make_local_branch()
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
491
        rev1 = revisionspec.RevisionSpec.from_string('1')
492
        rev2 = revisionspec.RevisionSpec.from_string('2')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
493
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
494
        self.assertRaises(errors.BzrCommandError,
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
495
                          self.do_incremental_upload, revision=[rev1, rev2])
496
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
497
    def test_create_remote_dir_twice(self):
498
        self.make_local_branch()
499
        self.add_dir('dir')
500
        self.do_full_upload()
501
        self.add_file('dir/goodbye', 'baz')
502
503
        self.failIfUpFileExists('dir/goodbye')
504
505
        self.do_full_upload()
506
507
        self.assertUpFileEqual('baz', 'dir/goodbye')
508
        self.assertUpPathModeEqual('dir', 0775)
509
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
510
511
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
512
513
    do_upload = TestUploadMixin.do_incremental_upload
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
514
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
515
    # XXX: full upload doesn't handle deletions....
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
516
517
    def test_delete_one_file(self):
518
        self.make_local_branch()
519
        self.add_file('hello', 'foo')
520
        self.do_full_upload()
521
        self.delete_any('hello')
522
523
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
524
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
525
        self.do_upload()
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.failIfUpFileExists('hello')
528
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
529
    def test_delete_dir_and_subdir(self):
530
        self.make_local_branch()
531
        self.add_dir('dir')
532
        self.add_dir('dir/subdir')
533
        self.add_file('dir/subdir/a', 'foo')
534
        self.do_full_upload()
535
        self.rename_any('dir/subdir/a', 'a')
536
        self.delete_any('dir/subdir')
537
        self.delete_any('dir')
538
539
        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).
540
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
541
        self.do_upload()
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.failIfUpFileExists('dir/subdir/a')
544
        self.failIfUpFileExists('dir/subdir')
545
        self.failIfUpFileExists('dir')
546
        self.assertUpFileEqual('foo', 'a')
547
548
    def test_delete_one_file_rename_to_deleted(self):
549
        self.make_local_branch()
550
        self.add_file('a', 'foo')
551
        self.add_file('b', 'bar')
552
        self.do_full_upload()
553
        self.delete_any('a')
554
        self.rename_any('b', 'a')
555
556
        self.assertUpFileEqual('foo', 'a')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
557
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
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.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
560
        self.failIfUpFileExists('b')
561
        self.assertUpFileEqual('bar', 'a')
562
563
    def test_rename_outside_dir_delete_dir(self):
564
        self.make_local_branch()
565
        self.add_dir('dir')
566
        self.add_file('dir/a', 'foo')
567
        self.do_full_upload()
568
        self.rename_any('dir/a', 'a')
569
        self.delete_any('dir')
570
571
        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).
572
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
573
        self.do_upload()
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.failIfUpFileExists('dir/a')
576
        self.failIfUpFileExists('dir')
577
        self.assertUpFileEqual('foo', 'a')
578
0.152.31 by Vincent Ladeuil
Cosmetic change.
579
    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
580
        self.make_local_branch()
581
        self.add_file('hello', 'bar')
0.152.31 by Vincent Ladeuil
Cosmetic change.
582
0.155.1 by James Westby
Switch most of the logic to a class outside of the command class.
583
        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).
584
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
585
        self.do_upload()
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.assertUpFileEqual('bar', 'hello')
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
588
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
589
class TestUploadFromRemote(TestUploadMixin):
590
    
591
    def do_full_upload(self, *args, **kwargs):
592
        up_url = self.get_transport(self.upload_dir).external_url()
0.158.7 by Gary van der Merwe
Clean up white space.
593
0.158.5 by Gary van der Merwe
Push using lower level api to avoid output.
594
        rev_id = self.branch.last_revision()
595
        output = StringIO()
596
        _show_push_branch(self.branch, rev_id, up_url, output)
0.158.7 by Gary van der Merwe
Clean up white space.
597
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
598
        upload = self._get_cmd_upload()
599
        if kwargs.get('directory', None) is None:
600
            kwargs['directory'] = up_url
601
        kwargs['full'] = True
602
        kwargs['quiet'] = True
603
        upload.run(up_url, *args, **kwargs)
604
605
    def do_incremental_upload(self, *args, **kwargs):
606
        up_url = self.get_transport(self.upload_dir).external_url()
0.158.7 by Gary van der Merwe
Clean up white space.
607
0.158.5 by Gary van der Merwe
Push using lower level api to avoid output.
608
        rev_id = self.branch.last_revision()
609
        output = StringIO()
610
        _show_push_branch(self.branch, rev_id, up_url, output)
0.158.7 by Gary van der Merwe
Clean up white space.
611
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
612
        upload = self._get_cmd_upload()
613
        if kwargs.get('directory', None) is None:
614
            kwargs['directory'] = up_url
615
        kwargs['quiet'] = True
616
        upload.run(up_url, *args, **kwargs)
0.158.7 by Gary van der Merwe
Clean up white space.
617
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
618
    def test_no_upload_when_changes(self):
619
        raise tests.TestNotApplicable()
620
621
    def test_no_upload_when_conflicts(self):
622
        raise tests.TestNotApplicable()
0.158.7 by Gary van der Merwe
Clean up white space.
623
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
624
    remote_branch = None
625
    def get_upload_auto(self):
626
        if not self.remote_branch:
627
            self.remote_branch = branch.Branch.open_from_transport(\
628
                self.get_transport(self.upload_dir))
0.158.7 by Gary van der Merwe
Clean up white space.
629
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
630
        return get_upload_auto(self.remote_branch)
631
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
632
class TestFullUploadFromRemote(tests.TestCaseWithTransport, TestUploadFromRemote):
0.158.7 by Gary van der Merwe
Clean up white space.
633
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
634
    do_upload = TestUploadFromRemote.do_full_upload
635
636
class TestIncrementalUploadFromRemote(tests.TestCaseWithTransport, TestUploadFromRemote):
0.158.7 by Gary van der Merwe
Clean up white space.
637
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
638
    do_upload = TestUploadFromRemote.do_incremental_upload
0.153.1 by Vincent Ladeuil
Clean up references to verbose.
639
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
640
class TestBranchUploadLocations(branch_implementations.TestCaseWithBranch):
641
642
    def test_get_upload_location_unset(self):
643
        config = self.get_branch().get_config()
644
        self.assertEqual(None, config.get_user_option('upload_location'))
645
646
    def test_get_push_location_exact(self):
647
        from bzrlib.config import (locations_config_filename,
648
                                   ensure_config_dir_exists)
649
        ensure_config_dir_exists()
650
        fn = locations_config_filename()
651
        b = self.get_branch()
652
        open(fn, 'wt').write(("[%s]\n"
653
                                  "upload_location=foo\n" %
654
                                  b.base[:-1]))
655
        config = b.get_config()
656
        self.assertEqual("foo", config.get_user_option('upload_location'))
657
658
    def test_set_push_location(self):
659
        config = self.get_branch().get_config()
660
        config.set_user_option('upload_location', 'foo')
661
        self.assertEqual('foo', config.get_user_option('upload_location'))
662