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