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