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