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