/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.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
156
0.152.10 by Vincent Ladeuil
Fix incremental upload cheat.
157
    def make_local_branch(self):
0.152.8 by Vincent Ladeuil
Handle uploading directories.
158
        t = transport.get_transport('branch')
159
        t.ensure_base()
0.158.5 by Gary van der Merwe
Push using lower level api to avoid output.
160
        self.branch = bzrdir.BzrDir.create_branch_convenience(
0.152.8 by Vincent Ladeuil
Handle uploading directories.
161
            t.base,
162
            format=bzrdir.format_registry.make_bzrdir('default'),
163
            force_new_tree=False)
0.158.5 by Gary van der Merwe
Push using lower level api to avoid output.
164
        self.tree = self.branch.bzrdir.create_workingtree()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
165
        self.tree.commit('initial empty tree')
166
167
    def assertUpFileEqual(self, content, path, base=upload_dir):
168
        self.assertFileEqual(content, base + path)
169
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
170
    def assertUpPathModeEqual(self, path, expected_mode, base=upload_dir):
171
        # FIXME: the tests needing that assertion should depend on the server
172
        # ability to handle chmod so that they don't fail (or be skipped)
173
        # against servers that can't. Note that some bzrlib transports define
174
        # _can_roundtrip_unix_modebits in a incomplete way, this property
175
        # should depend on both the client and the server, not the client only.
176
        st = os.stat(base + path)
177
        mode = st.st_mode & 0777
178
        if expected_mode == mode:
179
            return
180
        raise AssertionError(
181
            'For path %s, mode is %s not %s' %
182
            (base + path, oct(mode), oct(expected_mode)))
183
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
184
    def failIfUpFileExists(self, path, base=upload_dir):
185
        self.failIfExists(base + path)
186
187
    def failUnlessUpFileExists(self, path, base=upload_dir):
188
        self.failUnlessExists(base + path)
189
190
    def set_file_content(self, name, content, base=branch_dir):
191
        f = file(base + name, 'wb')
192
        try:
193
            f.write(content)
194
        finally:
195
            f.close()
196
197
    def add_file(self, name, content, base=branch_dir):
198
        self.set_file_content(name, content, base)
199
        self.tree.add(name)
200
        self.tree.commit('add file %s' % name)
201
202
    def modify_file(self, name, content, base=branch_dir):
203
        self.set_file_content(name, content, base)
204
        self.tree.commit('modify file %s' % name)
205
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
206
    def chmod_file(self, name, mode, base=branch_dir):
207
        path = base + name
208
        os.chmod(path, mode)
209
        self.tree.commit('change file %s mode to %s' % (name, oct(mode)))
210
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
211
    def delete_any(self, name, base=branch_dir):
212
        self.tree.remove([name], keep_files=False)
213
        self.tree.commit('delete %s' % name)
214
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
215
    def add_dir(self, name, base=branch_dir):
216
        os.mkdir(base + name)
217
        self.tree.add(name)
218
        self.tree.commit('add directory %s' % name)
219
220
    def rename_any(self, old_name, new_name):
221
        self.tree.rename_one(old_name, new_name)
222
        self.tree.commit('rename %s into %s' % (old_name, new_name))
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
223
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
224
    def transform_dir_into_file(self, name, content, base=branch_dir):
225
        osutils.delete_any(base + name)
226
        self.set_file_content(name, content, base)
227
        self.tree.commit('change %s from dir to file' % name)
228
229
    def transform_file_into_dir(self, name, base=branch_dir):
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
230
        # bzr can't handle that kind change in a single commit without an
231
        # intervening bzr status (see bug #205636).
232
        self.tree.remove([name], keep_files=False)
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
233
        os.mkdir(base + name)
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
234
        self.tree.add(name)
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
235
        self.tree.commit('change %s from file to dir' % name)
236
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
237
    def _get_cmd_upload(self):
238
        upload = cmd_upload()
239
        # We don't want to use run_bzr here because redirected output are a
240
        # pain to debug. But we need to provides a valid outf.
241
        # XXX: Should a bug against bzr be filled about that ?
242
        upload._setup_outf()
243
        return upload
244
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
245
    def do_full_upload(self, *args, **kwargs):
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
246
        upload = self._get_cmd_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
247
        up_url = self.get_transport(self.upload_dir).external_url()
0.152.11 by Vincent Ladeuil
Be coherent with bzr push.
248
        if kwargs.get('directory', None) is None:
249
            kwargs['directory'] = 'branch'
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
250
        kwargs['full'] = True
0.152.34 by Martin Albisetti
* Change the default behaviour to be more verbose
251
        kwargs['quiet'] = True
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
252
        upload.run(up_url, *args, **kwargs)
253
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
254
    def do_incremental_upload(self, *args, **kwargs):
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
255
        upload = self._get_cmd_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
256
        up_url = self.get_transport(self.upload_dir).external_url()
0.152.11 by Vincent Ladeuil
Be coherent with bzr push.
257
        if kwargs.get('directory', None) is None:
258
            kwargs['directory'] = 'branch'
0.152.34 by Martin Albisetti
* Change the default behaviour to be more verbose
259
        kwargs['quiet'] = True
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
260
        upload.run(up_url, *args, **kwargs)
261
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
262
    def test_create_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
263
        self.make_local_branch()
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
264
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
265
        self.add_file('hello', 'foo')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
266
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
267
        self.do_upload()
268
269
        self.assertUpFileEqual('foo', 'hello')
270
271
    def test_create_file_in_subdir(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
272
        self.make_local_branch()
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
273
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
274
        self.add_dir('dir')
275
        self.add_file('dir/goodbye', 'baz')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
276
277
        self.failIfUpFileExists('dir/goodbye')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
278
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
279
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
280
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
281
        self.assertUpFileEqual('baz', 'dir/goodbye')
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
282
        self.assertUpPathModeEqual('dir', 0775)
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
283
284
    def test_modify_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
285
        self.make_local_branch()
286
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
287
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
288
        self.modify_file('hello', 'bar')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
289
290
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
291
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
292
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
293
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
294
        self.assertUpFileEqual('bar', 'hello')
295
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
296
    def test_rename_one_file(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
297
        self.make_local_branch()
298
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
299
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
300
        self.rename_any('hello', 'goodbye')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
301
302
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
303
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
304
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
305
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
306
        self.assertUpFileEqual('foo', 'goodbye')
307
0.152.52 by Vincent Ladeuil
Fix bug #270219 by handling content changes during renames.
308
    def test_rename_and_change_file(self):
309
        self.make_local_branch()
310
        self.add_file('hello', 'foo')
311
        self.do_full_upload()
312
        self.rename_any('hello', 'goodbye')
313
        self.modify_file('goodbye', 'bar')
314
315
        self.assertUpFileEqual('foo', 'hello')
316
317
        self.do_upload()
318
319
        self.assertUpFileEqual('bar', 'goodbye')
320
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
321
    def test_rename_two_files(self):
322
        self.make_local_branch()
323
        self.add_file('a', 'foo')
324
        self.add_file('b', 'qux')
325
        self.do_full_upload()
326
        # We rely on the assumption that bzr will topologically sort the
327
        # renames which will cause a -> b to appear *before* b -> c
328
        self.rename_any('b', 'c')
329
        self.rename_any('a', 'b')
330
331
        self.assertUpFileEqual('foo', 'a')
332
        self.assertUpFileEqual('qux', 'b')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
333
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
334
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
335
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
336
        self.assertUpFileEqual('foo', 'b')
337
        self.assertUpFileEqual('qux', 'c')
338
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
339
    def test_upload_revision(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
340
        self.make_local_branch() # rev1
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
341
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
342
        self.add_file('hello', 'foo') # rev2
343
        self.modify_file('hello', 'bar') # rev3
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
344
345
        self.failIfUpFileExists('hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
346
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
347
        revspec = revisionspec.RevisionSpec.from_string('2')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
348
        self.do_upload(revision=[revspec])
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
349
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
350
        self.assertUpFileEqual('foo', 'hello')
351
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
352
    def test_no_upload_when_changes(self):
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
353
        self.make_local_branch()
354
        self.add_file('a', 'foo')
355
        self.set_file_content('a', 'bar')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
356
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
357
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
358
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
359
    def test_no_upload_when_conflicts(self):
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
360
        self.make_local_branch()
361
        self.add_file('a', 'foo')
362
        self.run_bzr('branch branch other')
363
        self.modify_file('a', 'bar')
364
        other_tree = workingtree.WorkingTree.open('other')
365
        self.set_file_content('a', 'baz', 'other/')
366
        other_tree.commit('modify file a')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
367
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
368
        self.run_bzr('merge -d branch other', retcode=1)
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
369
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
370
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
371
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
372
    def test_change_file_into_dir(self):
373
        self.make_local_branch()
374
        self.add_file('hello', 'foo')
375
        self.do_full_upload()
376
        self.transform_file_into_dir('hello')
377
        self.add_file('hello/file', 'bar')
378
379
        self.assertUpFileEqual('foo', 'hello')
380
381
        self.do_upload()
382
383
        self.assertUpFileEqual('bar', 'hello/file')
384
385
    def test_change_dir_into_file(self):
386
        self.make_local_branch()
387
        self.add_dir('hello')
388
        self.add_file('hello/file', 'foo')
389
        self.do_full_upload()
390
        self.delete_any('hello/file')
391
        self.transform_dir_into_file('hello', 'bar')
392
393
        self.assertUpFileEqual('foo', 'hello/file')
394
395
        self.do_upload()
396
397
        self.assertUpFileEqual('bar', 'hello')
398
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
399
    def test_make_file_executable(self):
400
        self.make_local_branch()
401
        self.add_file('hello', 'foo')
402
        self.chmod_file('hello', 0664)
403
        self.do_full_upload()
404
        self.chmod_file('hello', 0755)
405
406
        self.assertUpPathModeEqual('hello', 0664)
407
408
        self.do_upload()
409
410
        self.assertUpPathModeEqual('hello', 0775)
411
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
412
    def get_upload_auto(self):
413
        return get_upload_auto(self.tree.branch)
0.158.7 by Gary van der Merwe
Clean up white space.
414
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
415
    def test_upload_auto(self):
416
        """Test that upload --auto sets the upload_auto option"""
417
        self.make_local_branch()
418
        self.add_file('hello', 'foo')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
419
        try:
420
            self.assertFalse(self.get_upload_auto())
421
        except errors.NotBranchError:
422
            pass
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
423
        self.do_full_upload(auto=True)
424
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
425
        self.assertTrue(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
426
        # and check that it stays set until it is unset
427
        self.add_file('bye', 'bar')
428
        self.do_full_upload()
429
        self.assertUpFileEqual('bar', 'bye')
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
432
    def test_upload_noauto(self):
433
        """Test that upload --no-auto unsets the upload_auto option"""
434
        self.make_local_branch()
435
        self.add_file('hello', 'foo')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
436
        try:
437
            self.assertFalse(self.get_upload_auto())
438
        except errors.NotBranchError:
0.158.7 by Gary van der Merwe
Clean up white space.
439
            pass
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
440
        self.do_full_upload(auto=True)
441
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
442
        self.assertTrue(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
443
        self.add_file('bye', 'bar')
444
        self.do_full_upload(auto=False)
445
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
446
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
447
        # and check that it stays unset until it is set
448
        self.add_file('again', 'baz')
449
        self.do_full_upload()
450
        self.assertUpFileEqual('baz', 'again')
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
0.156.1 by James Westby
Use open_containing rather than open, so that you can upload from a subdir.
453
    def test_upload_from_subdir(self):
454
        self.make_local_branch()
455
        self.build_tree(['branch/foo/', 'branch/foo/bar'])
456
        self.tree.add(['foo/', 'foo/bar'])
457
        self.tree.commit("Add directory")
458
        self.do_full_upload(directory='branch/foo')
459
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
460
461
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
462
463
    do_upload = TestUploadMixin.do_full_upload
464
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
465
    def test_full_upload_empty_tree(self):
466
        self.make_local_branch()
467
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
468
        self.do_full_upload()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
469
0.155.1 by James Westby
Switch most of the logic to a class outside of the command class.
470
        self.failUnlessUpFileExists(BzrUploader.bzr_upload_revid_file_name)
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
471
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
472
    def test_invalid_revspec(self):
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
473
        self.make_local_branch()
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
474
        rev1 = revisionspec.RevisionSpec.from_string('1')
475
        rev2 = revisionspec.RevisionSpec.from_string('2')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
476
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
477
        self.assertRaises(errors.BzrCommandError,
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
478
                          self.do_incremental_upload, revision=[rev1, rev2])
479
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
480
    def test_create_remote_dir_twice(self):
481
        self.make_local_branch()
482
        self.add_dir('dir')
483
        self.do_full_upload()
484
        self.add_file('dir/goodbye', 'baz')
485
486
        self.failIfUpFileExists('dir/goodbye')
487
488
        self.do_full_upload()
489
490
        self.assertUpFileEqual('baz', 'dir/goodbye')
491
        self.assertUpPathModeEqual('dir', 0775)
492
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
493
494
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
495
496
    do_upload = TestUploadMixin.do_incremental_upload
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
497
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
498
    # XXX: full upload doesn't handle deletions....
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
499
500
    def test_delete_one_file(self):
501
        self.make_local_branch()
502
        self.add_file('hello', 'foo')
503
        self.do_full_upload()
504
        self.delete_any('hello')
505
506
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
507
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
508
        self.do_upload()
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.failIfUpFileExists('hello')
511
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
512
    def test_delete_dir_and_subdir(self):
513
        self.make_local_branch()
514
        self.add_dir('dir')
515
        self.add_dir('dir/subdir')
516
        self.add_file('dir/subdir/a', 'foo')
517
        self.do_full_upload()
518
        self.rename_any('dir/subdir/a', 'a')
519
        self.delete_any('dir/subdir')
520
        self.delete_any('dir')
521
522
        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).
523
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
524
        self.do_upload()
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.failIfUpFileExists('dir/subdir/a')
527
        self.failIfUpFileExists('dir/subdir')
528
        self.failIfUpFileExists('dir')
529
        self.assertUpFileEqual('foo', 'a')
530
531
    def test_delete_one_file_rename_to_deleted(self):
532
        self.make_local_branch()
533
        self.add_file('a', 'foo')
534
        self.add_file('b', 'bar')
535
        self.do_full_upload()
536
        self.delete_any('a')
537
        self.rename_any('b', 'a')
538
539
        self.assertUpFileEqual('foo', 'a')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
540
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
541
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
542
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
543
        self.failIfUpFileExists('b')
544
        self.assertUpFileEqual('bar', 'a')
545
546
    def test_rename_outside_dir_delete_dir(self):
547
        self.make_local_branch()
548
        self.add_dir('dir')
549
        self.add_file('dir/a', 'foo')
550
        self.do_full_upload()
551
        self.rename_any('dir/a', 'a')
552
        self.delete_any('dir')
553
554
        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).
555
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
556
        self.do_upload()
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.failIfUpFileExists('dir/a')
559
        self.failIfUpFileExists('dir')
560
        self.assertUpFileEqual('foo', 'a')
561
0.152.31 by Vincent Ladeuil
Cosmetic change.
562
    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
563
        self.make_local_branch()
564
        self.add_file('hello', 'bar')
0.152.31 by Vincent Ladeuil
Cosmetic change.
565
0.155.1 by James Westby
Switch most of the logic to a class outside of the command class.
566
        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).
567
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
568
        self.do_upload()
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.assertUpFileEqual('bar', 'hello')
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
571
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
572
class TestUploadFromRemote(TestUploadMixin):
573
    
574
    def do_full_upload(self, *args, **kwargs):
575
        up_url = self.get_transport(self.upload_dir).external_url()
0.158.7 by Gary van der Merwe
Clean up white space.
576
0.158.5 by Gary van der Merwe
Push using lower level api to avoid output.
577
        rev_id = self.branch.last_revision()
578
        output = StringIO()
579
        _show_push_branch(self.branch, rev_id, up_url, output)
0.158.7 by Gary van der Merwe
Clean up white space.
580
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
581
        upload = self._get_cmd_upload()
582
        if kwargs.get('directory', None) is None:
583
            kwargs['directory'] = up_url
584
        kwargs['full'] = True
585
        kwargs['quiet'] = True
586
        upload.run(up_url, *args, **kwargs)
587
588
    def do_incremental_upload(self, *args, **kwargs):
589
        up_url = self.get_transport(self.upload_dir).external_url()
0.158.7 by Gary van der Merwe
Clean up white space.
590
0.158.5 by Gary van der Merwe
Push using lower level api to avoid output.
591
        rev_id = self.branch.last_revision()
592
        output = StringIO()
593
        _show_push_branch(self.branch, rev_id, up_url, output)
0.158.7 by Gary van der Merwe
Clean up white space.
594
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
595
        upload = self._get_cmd_upload()
596
        if kwargs.get('directory', None) is None:
597
            kwargs['directory'] = up_url
598
        kwargs['quiet'] = True
599
        upload.run(up_url, *args, **kwargs)
0.158.7 by Gary van der Merwe
Clean up white space.
600
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
601
    def test_no_upload_when_changes(self):
602
        raise tests.TestNotApplicable()
603
604
    def test_no_upload_when_conflicts(self):
605
        raise tests.TestNotApplicable()
0.158.7 by Gary van der Merwe
Clean up white space.
606
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
607
    remote_branch = None
608
    def get_upload_auto(self):
609
        if not self.remote_branch:
610
            self.remote_branch = branch.Branch.open_from_transport(\
611
                self.get_transport(self.upload_dir))
0.158.7 by Gary van der Merwe
Clean up white space.
612
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
613
        return get_upload_auto(self.remote_branch)
614
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
615
class TestFullUploadFromRemote(tests.TestCaseWithTransport, TestUploadFromRemote):
0.158.7 by Gary van der Merwe
Clean up white space.
616
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
617
    do_upload = TestUploadFromRemote.do_full_upload
618
619
class TestIncrementalUploadFromRemote(tests.TestCaseWithTransport, TestUploadFromRemote):
0.158.7 by Gary van der Merwe
Clean up white space.
620
0.158.3 by Gary van der Merwe
Add test for upload from remote. Not working.
621
    do_upload = TestUploadFromRemote.do_incremental_upload
0.153.1 by Vincent Ladeuil
Clean up references to verbose.
622
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
623
class TestBranchUploadLocations(branch_implementations.TestCaseWithBranch):
624
625
    def test_get_upload_location_unset(self):
626
        config = self.get_branch().get_config()
627
        self.assertEqual(None, config.get_user_option('upload_location'))
628
629
    def test_get_push_location_exact(self):
630
        from bzrlib.config import (locations_config_filename,
631
                                   ensure_config_dir_exists)
632
        ensure_config_dir_exists()
633
        fn = locations_config_filename()
634
        b = self.get_branch()
635
        open(fn, 'wt').write(("[%s]\n"
636
                                  "upload_location=foo\n" %
637
                                  b.base[:-1]))
638
        config = b.get_config()
639
        self.assertEqual("foo", config.get_user_option('upload_location'))
640
641
    def test_set_push_location(self):
642
        config = self.get_branch().get_config()
643
        config.set_user_option('upload_location', 'foo')
644
        self.assertEqual('foo', config.get_user_option('upload_location'))
645