/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.152.93 by Vincent Ladeuil
Migrate to config stacks
1
# Copyright (C) 2008-2012 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.32 by Vincent Ladeuil
Restore verbose as the default mode.
18
import sys
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
19
0.158.11 by Gary van der Merwe
Revert revision 57: Go back to using the cmd_object.
20
6645.2.1 by Jelmer Vernooij
Bundle the upload plugin.
21
from .... import (
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
22
    config,
6658.5.2 by Jelmer Vernooij
Remove breezy.bzrdir.format_registry.
23
    controldir,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
24
    errors,
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
25
    osutils,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
26
    revisionspec,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
27
    tests,
0.152.8 by Vincent Ladeuil
Handle uploading directories.
28
    transport,
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
29
    workingtree,
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
30
    uncommit,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
31
    )
6645.2.1 by Jelmer Vernooij
Bundle the upload plugin.
32
from ....tests import (
0.152.89 by Vincent Ladeuil
Cope with bzr.dev changes
33
    features,
0.152.60 by Vincent Ladeuil
bzr.dev has finish renaming the tests modules.
34
    per_branch,
35
    per_transport,
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
36
    )
6645.2.1 by Jelmer Vernooij
Bundle the upload plugin.
37
from ....transport import (
0.152.65 by Vincent Ladeuil
Fix spurious failures.
38
    ftp,
39
    )
6645.2.1 by Jelmer Vernooij
Bundle the upload plugin.
40
from .. import (
0.165.1 by Jelmer Vernooij
Support lazily loading.
41
    cmds,
42
    )
0.152.1 by Vincent Ladeuil
Empty shell
43
44
0.152.58 by Vincent Ladeuil
Make the test suite pass again catchiing up bzr.dev changes.
45
def get_transport_scenarios():
46
    result = []
0.152.60 by Vincent Ladeuil
bzr.dev has finish renaming the tests modules.
47
    basis = per_transport.transport_test_permutations()
0.152.58 by Vincent Ladeuil
Make the test suite pass again catchiing up bzr.dev changes.
48
    # Keep only the interesting ones for upload
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
49
    usable_classes = {ftp.FtpTransport}
50
    if features.paramiko.available():
51
        from ....transport import sftp
52
        usable_classes.add(sftp.SFTPTransport)
0.152.59 by Vincent Ladeuil
Make the test suite pass, but not the nearly empty one :).
53
    for name, d in basis:
0.152.58 by Vincent Ladeuil
Make the test suite pass again catchiing up bzr.dev changes.
54
        t_class = d['transport_class']
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
55
        if t_class in usable_classes:
0.152.65 by Vincent Ladeuil
Fix spurious failures.
56
            result.append((name, d))
0.152.58 by Vincent Ladeuil
Make the test suite pass again catchiing up bzr.dev changes.
57
    try:
6645.2.1 by Jelmer Vernooij
Bundle the upload plugin.
58
        import breezy.plugins.local_test_server
59
        from breezy.plugins.local_test_server import test_server
0.152.58 by Vincent Ladeuil
Make the test suite pass again catchiing up bzr.dev changes.
60
        if False:
61
            # XXX: Disable since we can't get chmod working for anonymous
62
            # user
63
            scenario = ('vsftpd',
64
                        {'transport_class': test_server.FtpTransport,
65
                         'transport_server': test_server.Vsftpd,
66
                         })
67
            result.append(scenario)
68
        from test_server import ProftpdFeature
69
        if ProftpdFeature().available():
70
            scenario = ('proftpd',
71
                        {'transport_class': test_server.FtpTransport,
72
                         'transport_server': test_server.Proftpd,
73
                         })
74
            result.append(scenario)
75
        # XXX: add support for pyftpdlib
76
    except ImportError:
77
        pass
78
    return result
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
79
80
6645.2.1 by Jelmer Vernooij
Bundle the upload plugin.
81
def load_tests(loader, standard_tests, pattern):
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
82
    """Multiply tests for tranport implementations."""
83
    result = loader.suiteClass()
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
84
0.152.58 by Vincent Ladeuil
Make the test suite pass again catchiing up bzr.dev changes.
85
    # one for each transport implementation
86
    t_tests, remaining_tests = tests.split_suite_by_condition(
87
        standard_tests, tests.condition_isinstance((
88
                TestFullUpload,
89
                TestIncrementalUpload,
90
                TestUploadFromRemoteBranch,
91
                )))
92
    tests.multiply_tests(t_tests, get_transport_scenarios(), result)
93
94
    # one for each branch format
95
    b_tests, remaining_tests = tests.split_suite_by_condition(
96
        remaining_tests, tests.condition_isinstance((
97
                TestBranchUploadLocations,
98
                )))
0.152.60 by Vincent Ladeuil
bzr.dev has finish renaming the tests modules.
99
    tests.multiply_tests(b_tests, per_branch.branch_scenarios(),
0.152.58 by Vincent Ladeuil
Make the test suite pass again catchiing up bzr.dev changes.
100
                         result)
101
102
    # No parametrization for the remaining tests
103
    result.addTests(remaining_tests)
104
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
105
    return result
106
107
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
108
class UploadUtilsMixin(object):
109
    """Helper class to write upload tests.
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
110
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
111
    This class provides helpers to simplify test writing. The emphasis is on
112
    easy test writing, so each tree modification is committed. This doesn't
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
113
    preclude writing tests spawning several revisions to upload more complex
114
    changes.
115
    """
116
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
117
    upload_dir = 'upload'
118
    branch_dir = 'branch'
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
119
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
120
    def make_branch_and_working_tree(self):
121
        t = transport.get_transport(self.branch_dir)
0.152.8 by Vincent Ladeuil
Handle uploading directories.
122
        t.ensure_base()
6667.2.1 by Jelmer Vernooij
Some cleanup; s/BzrDir/ControlDir/, remove some unused imports.
123
        branch = controldir.ControlDir.create_branch_convenience(
0.152.8 by Vincent Ladeuil
Handle uploading directories.
124
            t.base,
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
125
            format=controldir.format_registry.make_controldir('default'),
0.152.8 by Vincent Ladeuil
Handle uploading directories.
126
            force_new_tree=False)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
127
        self.tree = branch.controldir.create_workingtree()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
128
        self.tree.commit('initial empty tree')
129
130
    def assertUpFileEqual(self, content, path, base=upload_dir):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
131
        self.assertFileEqual(content, osutils.pathjoin(base, path))
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
132
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
133
    def assertUpPathModeEqual(self, path, expected_mode, base=upload_dir):
134
        # FIXME: the tests needing that assertion should depend on the server
135
        # ability to handle chmod so that they don't fail (or be skipped)
6645.2.1 by Jelmer Vernooij
Bundle the upload plugin.
136
        # against servers that can't. Note that some breezy transports define
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
137
        # _can_roundtrip_unix_modebits in a incomplete way, this property
138
        # 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.
139
        # But the client will know or can find if the server support chmod so
140
        # that's the client that will report it anyway.
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
141
        full_path = osutils.pathjoin(base, path)
142
        st = os.stat(full_path)
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
143
        mode = st.st_mode & 0o777
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
144
        if expected_mode == mode:
145
            return
146
        raise AssertionError(
147
            'For path %s, mode is %s not %s' %
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
148
            (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
149
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
150
    def assertUpPathDoesNotExist(self, path, base=upload_dir):
151
        self.assertPathDoesNotExist(osutils.pathjoin(base, path))
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
152
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
153
    def assertUpPathExists(self, path, base=upload_dir):
154
        self.assertPathExists(osutils.pathjoin(base, path))
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
155
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
156
    def set_file_content(self, path, content, base=branch_dir):
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
157
        with open(osutils.pathjoin(base, path), 'wb') as f:
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
158
            f.write(content)
159
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
160
    def add_file(self, path, content, base=branch_dir):
161
        self.set_file_content(path, content, base)
162
        self.tree.add(path)
163
        self.tree.commit('add file %s' % path)
164
165
    def modify_file(self, path, content, base=branch_dir):
166
        self.set_file_content(path, content, base)
167
        self.tree.commit('modify file %s' % path)
168
169
    def chmod_file(self, path, mode, base=branch_dir):
170
        full_path = osutils.pathjoin(base, path)
171
        os.chmod(full_path, mode)
172
        self.tree.commit('change file %s mode to %s' % (path, oct(mode)))
173
174
    def delete_any(self, path, base=branch_dir):
175
        self.tree.remove([path], keep_files=False)
176
        self.tree.commit('delete %s' % path)
177
178
    def add_dir(self, path, base=branch_dir):
179
        os.mkdir(osutils.pathjoin(base, path))
180
        self.tree.add(path)
181
        self.tree.commit('add directory %s' % path)
182
183
    def rename_any(self, old_path, new_path):
184
        self.tree.rename_one(old_path, new_path)
185
        self.tree.commit('rename %s into %s' % (old_path, new_path))
186
187
    def transform_dir_into_file(self, path, content, base=branch_dir):
188
        osutils.delete_any(osutils.pathjoin(base, path))
189
        self.set_file_content(path, content, base)
190
        self.tree.commit('change %s from dir to file' % path)
191
192
    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).
193
        # bzr can't handle that kind change in a single commit without an
194
        # intervening bzr status (see bug #205636).
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
195
        self.tree.remove([path], keep_files=False)
196
        os.mkdir(osutils.pathjoin(base, path))
197
        self.tree.add(path)
198
        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.
199
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
200
    def add_symlink(self, path, target, base=branch_dir):
0.152.89 by Vincent Ladeuil
Cope with bzr.dev changes
201
        self.requireFeature(features.SymlinkFeature)
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
202
        os.symlink(target, osutils.pathjoin(base, path))
203
        self.tree.add(path)
204
        self.tree.commit('add symlink %s -> %s' % (path, target))
205
206
    def modify_symlink(self, path, target, base=branch_dir):
0.152.89 by Vincent Ladeuil
Cope with bzr.dev changes
207
        self.requireFeature(features.SymlinkFeature)
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
208
        full_path = osutils.pathjoin(base, path)
209
        os.unlink(full_path)
210
        os.symlink(target, full_path)
211
        self.tree.commit('modify symlink %s -> %s' % (path, target))
212
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
213
    def _get_cmd_upload(self):
0.165.1 by Jelmer Vernooij
Support lazily loading.
214
        cmd = cmds.cmd_upload()
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
215
        # We don't want to use run_bzr here because redirected output are a
216
        # pain to debug. But we need to provides a valid outf.
217
        # XXX: Should a bug against bzr be filled about that ?
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
218
219
        # Short story: we don't expect any output so we may just use stdout
220
        cmd.outf = sys.stdout
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
221
        return cmd
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
222
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
223
    def do_full_upload(self, *args, **kwargs):
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
224
        upload = self._get_cmd_upload()
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
225
        up_url = self.get_url(self.upload_dir)
0.152.11 by Vincent Ladeuil
Be coherent with bzr push.
226
        if kwargs.get('directory', None) is None:
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
227
            kwargs['directory'] = self.branch_dir
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
228
        kwargs['full'] = True
0.152.34 by Martin Albisetti
* Change the default behaviour to be more verbose
229
        kwargs['quiet'] = True
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
230
        upload.run(up_url, *args, **kwargs)
231
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
232
    def do_incremental_upload(self, *args, **kwargs):
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
233
        upload = self._get_cmd_upload()
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
234
        up_url = self.get_url(self.upload_dir)
0.152.11 by Vincent Ladeuil
Be coherent with bzr push.
235
        if kwargs.get('directory', None) is None:
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
236
            kwargs['directory'] = self.branch_dir
0.152.34 by Martin Albisetti
* Change the default behaviour to be more verbose
237
        kwargs['quiet'] = True
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
238
        upload.run(up_url, *args, **kwargs)
239
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
240
241
class TestUploadMixin(UploadUtilsMixin):
242
    """Helper class to share tests between full and incremental uploads."""
243
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
244
    def _test_create_file(self, file_name):
245
        self.make_branch_and_working_tree()
246
        self.do_full_upload()
247
        self.add_file(file_name, 'foo')
248
249
        self.do_upload()
250
251
        self.assertUpFileEqual('foo', file_name)
252
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
253
    def test_create_file(self):
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
254
        self._test_create_file('hello')
255
256
    def test_unicode_create_file(self):
0.152.89 by Vincent Ladeuil
Cope with bzr.dev changes
257
        self.requireFeature(features.UnicodeFilenameFeature)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
258
        self._test_create_file(u'hell\u00d8')
259
260
    def _test_create_file_in_dir(self, dir_name, file_name):
261
        self.make_branch_and_working_tree()
262
        self.do_full_upload()
263
        self.add_dir(dir_name)
264
        fpath = '%s/%s' % (dir_name, file_name)
265
        self.add_file(fpath, 'baz')
266
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
267
        self.assertUpPathDoesNotExist(fpath)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
268
269
        self.do_upload()
270
271
        self.assertUpFileEqual('baz', fpath)
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
272
        self.assertUpPathModeEqual(dir_name, 0o775)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
273
274
    def test_create_file_in_dir(self):
275
        self._test_create_file_in_dir('dir', 'goodbye')
276
277
    def test_unicode_create_file_in_dir(self):
0.152.89 by Vincent Ladeuil
Cope with bzr.dev changes
278
        self.requireFeature(features.UnicodeFilenameFeature)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
279
        self._test_create_file_in_dir(u'dir\u00d8', u'goodbye\u00d8')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
280
281
    def test_modify_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
282
        self.make_branch_and_working_tree()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
283
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
284
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
285
        self.modify_file('hello', 'bar')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
286
287
        self.assertUpFileEqual('foo', 'hello')
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('bar', 'hello')
292
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
293
    def _test_rename_one_file(self, old_name, new_name):
294
        self.make_branch_and_working_tree()
295
        self.add_file(old_name, 'foo')
296
        self.do_full_upload()
297
        self.rename_any(old_name, new_name)
298
299
        self.assertUpFileEqual('foo', old_name)
300
301
        self.do_upload()
302
303
        self.assertUpFileEqual('foo', new_name)
304
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
305
    def test_rename_one_file(self):
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
306
        self._test_rename_one_file('hello', 'goodbye')
307
308
    def test_unicode_rename_one_file(self):
0.152.89 by Vincent Ladeuil
Cope with bzr.dev changes
309
        self.requireFeature(features.UnicodeFilenameFeature)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
310
        self._test_rename_one_file(u'hello\u00d8', u'goodbye\u00d8')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
311
0.152.52 by Vincent Ladeuil
Fix bug #270219 by handling content changes during renames.
312
    def test_rename_and_change_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
313
        self.make_branch_and_working_tree()
0.152.52 by Vincent Ladeuil
Fix bug #270219 by handling content changes during renames.
314
        self.add_file('hello', 'foo')
315
        self.do_full_upload()
316
        self.rename_any('hello', 'goodbye')
317
        self.modify_file('goodbye', 'bar')
318
319
        self.assertUpFileEqual('foo', 'hello')
320
321
        self.do_upload()
322
323
        self.assertUpFileEqual('bar', 'goodbye')
324
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
325
    def test_rename_two_files(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
326
        self.make_branch_and_working_tree()
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
327
        self.add_file('a', 'foo')
328
        self.add_file('b', 'qux')
329
        self.do_full_upload()
330
        # We rely on the assumption that bzr will topologically sort the
331
        # renames which will cause a -> b to appear *before* b -> c
332
        self.rename_any('b', 'c')
333
        self.rename_any('a', 'b')
334
335
        self.assertUpFileEqual('foo', 'a')
336
        self.assertUpFileEqual('qux', 'b')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
337
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
338
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
339
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
340
        self.assertUpFileEqual('foo', 'b')
341
        self.assertUpFileEqual('qux', 'c')
342
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
343
    def test_upload_revision(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
344
        self.make_branch_and_working_tree() # rev1
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
345
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
346
        self.add_file('hello', 'foo') # rev2
347
        self.modify_file('hello', 'bar') # rev3
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
348
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
349
        self.assertUpPathDoesNotExist('hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
350
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
351
        revspec = revisionspec.RevisionSpec.from_string('2')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
352
        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).
353
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
354
        self.assertUpFileEqual('foo', 'hello')
355
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
356
    def test_no_upload_when_changes(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
357
        self.make_branch_and_working_tree()
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
358
        self.add_file('a', 'foo')
359
        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).
360
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
361
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
362
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
363
    def test_no_upload_when_conflicts(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
364
        self.make_branch_and_working_tree()
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
365
        self.add_file('a', 'foo')
366
        self.run_bzr('branch branch other')
367
        self.modify_file('a', 'bar')
368
        other_tree = workingtree.WorkingTree.open('other')
369
        self.set_file_content('a', 'baz', 'other/')
370
        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).
371
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
372
        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).
373
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
374
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
375
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
376
    def _test_change_file_into_dir(self, file_name):
377
        self.make_branch_and_working_tree()
378
        self.add_file(file_name, 'foo')
379
        self.do_full_upload()
380
        self.transform_file_into_dir(file_name)
381
        fpath = '%s/%s' % (file_name, 'file')
382
        self.add_file(fpath, 'bar')
383
384
        self.assertUpFileEqual('foo', file_name)
385
386
        self.do_upload()
387
388
        self.assertUpFileEqual('bar', fpath)
389
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
390
    def test_change_file_into_dir(self):
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
391
        self._test_change_file_into_dir('hello')
392
393
    def test_unicode_change_file_into_dir(self):
0.152.89 by Vincent Ladeuil
Cope with bzr.dev changes
394
        self.requireFeature(features.UnicodeFilenameFeature)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
395
        self._test_change_file_into_dir(u'hello\u00d8')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
396
397
    def test_change_dir_into_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
398
        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).
399
        self.add_dir('hello')
400
        self.add_file('hello/file', 'foo')
401
        self.do_full_upload()
402
        self.delete_any('hello/file')
403
        self.transform_dir_into_file('hello', 'bar')
404
405
        self.assertUpFileEqual('foo', 'hello/file')
406
407
        self.do_upload()
408
409
        self.assertUpFileEqual('bar', 'hello')
410
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
411
    def _test_make_file_executable(self, file_name):
412
        self.make_branch_and_working_tree()
413
        self.add_file(file_name, 'foo')
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
414
        self.chmod_file(file_name, 0o664)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
415
        self.do_full_upload()
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
416
        self.chmod_file(file_name, 0o755)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
417
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
418
        self.assertUpPathModeEqual(file_name, 0o664)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
419
420
        self.do_upload()
421
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
422
        self.assertUpPathModeEqual(file_name, 0o775)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
423
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
424
    def test_make_file_executable(self):
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
425
        self._test_make_file_executable('hello')
426
427
    def test_unicode_make_file_executable(self):
0.152.89 by Vincent Ladeuil
Cope with bzr.dev changes
428
        self.requireFeature(features.UnicodeFilenameFeature)
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
429
        self._test_make_file_executable(u'hello\u00d8')
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
430
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
431
    def test_create_symlink(self):
432
        self.make_branch_and_working_tree()
433
        self.do_full_upload()
434
        self.add_symlink('link', 'target')
435
436
        self.do_upload()
437
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
438
        self.assertUpPathDoesNotExist('link')
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
439
440
    def test_rename_symlink(self):
441
        self.make_branch_and_working_tree()
442
        old_name, new_name = 'old-link', 'new-link'
443
        self.add_symlink(old_name, 'target')
444
        self.do_full_upload()
445
        self.rename_any(old_name, new_name)
446
447
        self.do_upload()
448
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
449
        self.assertUpPathDoesNotExist(old_name)
450
        self.assertUpPathDoesNotExist(new_name)
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
451
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
452
    def get_upload_auto(self):
0.152.93 by Vincent Ladeuil
Migrate to config stacks
453
        # We need a fresh branch to check what has been saved on disk
6667.2.1 by Jelmer Vernooij
Some cleanup; s/BzrDir/ControlDir/, remove some unused imports.
454
        b = controldir.ControlDir.open(self.tree.basedir).open_branch()
0.152.93 by Vincent Ladeuil
Migrate to config stacks
455
        return b.get_config_stack().get('upload_auto')
0.158.7 by Gary van der Merwe
Clean up white space.
456
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
457
    def test_upload_auto(self):
458
        """Test that upload --auto sets the upload_auto option"""
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
459
        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.
460
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
461
        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.
462
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
463
        self.do_full_upload(auto=True)
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
464
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
465
        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.
466
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
467
        # and check that it stays set until it is unset
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
468
        self.add_file('bye', 'bar')
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
469
        self.do_full_upload()
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
470
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
471
        self.assertTrue(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
472
473
    def test_upload_noauto(self):
474
        """Test that upload --no-auto unsets the upload_auto option"""
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
475
        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.
476
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
477
        self.add_file('hello', 'foo')
478
        self.do_full_upload(auto=True)
479
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
480
        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.
481
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
482
        self.add_file('bye', 'bar')
483
        self.do_full_upload(auto=False)
484
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
485
        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.
486
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
487
        # and check that it stays unset until it is set
488
        self.add_file('again', 'baz')
489
        self.do_full_upload()
490
        self.assertUpFileEqual('baz', 'again')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
491
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
492
0.156.1 by James Westby
Use open_containing rather than open, so that you can upload from a subdir.
493
    def test_upload_from_subdir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
494
        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.
495
        self.build_tree(['branch/foo/', 'branch/foo/bar'])
496
        self.tree.add(['foo/', 'foo/bar'])
497
        self.tree.commit("Add directory")
498
        self.do_full_upload(directory='branch/foo')
499
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
500
    def test_upload_revid_path_in_dir(self):
501
        self.make_branch_and_working_tree()
502
        self.add_dir('dir')
503
        self.add_file('dir/goodbye', 'baz')
504
505
        revid_path = 'dir/revid-path'
0.152.93 by Vincent Ladeuil
Migrate to config stacks
506
        self.tree.branch.get_config_stack(
507
            ).set('upload_revid_location', revid_path)
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
508
        self.assertUpPathDoesNotExist(revid_path)
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
509
510
        self.do_full_upload()
511
512
        self.add_file('dir/hello', 'foo')
513
514
        self.do_upload()
515
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
516
        self.assertUpPathExists(revid_path)
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
517
        self.assertUpFileEqual('baz', 'dir/goodbye')
518
        self.assertUpFileEqual('foo', 'dir/hello')
519
0.160.1 by Martin Albisetti
Wrote the test first. TDD, dont fail me now.
520
    def test_ignore_file(self):
521
        self.make_branch_and_working_tree()
522
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
523
        self.add_file('.bzrignore-upload', 'foo')
524
        self.add_file('foo', 'bar')
525
526
        self.do_upload()
527
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
528
        self.assertUpPathDoesNotExist('foo')
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
529
530
    def test_ignore_regexp(self):
531
        self.make_branch_and_working_tree()
532
        self.do_full_upload()
533
        self.add_file('.bzrignore-upload', 'f*')
0.160.1 by Martin Albisetti
Wrote the test first. TDD, dont fail me now.
534
        self.add_file('foo', 'bar')
535
536
        self.do_upload()
537
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
538
        self.assertUpPathDoesNotExist('foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
539
0.160.11 by Martin Albisetti
Add test for ignoring a dir
540
    def test_ignore_directory(self):
541
        self.make_branch_and_working_tree()
542
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
543
        self.add_file('.bzrignore-upload', 'dir')
0.160.11 by Martin Albisetti
Add test for ignoring a dir
544
        self.add_dir('dir')
545
546
        self.do_upload()
547
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
548
        self.assertUpPathDoesNotExist('dir')
0.160.11 by Martin Albisetti
Add test for ignoring a dir
549
0.161.3 by Martin Albisetti
Write a test that verifies that nested files in ignored dirs dont get uploaded
550
    def test_ignore_nested_directory(self):
551
        self.make_branch_and_working_tree()
552
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
553
        self.add_file('.bzrignore-upload', 'dir')
0.161.3 by Martin Albisetti
Write a test that verifies that nested files in ignored dirs dont get uploaded
554
        self.add_dir('dir')
555
        self.add_dir('dir/foo')
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
556
        self.add_file('dir/foo/bar', 'bar contents')
0.161.3 by Martin Albisetti
Write a test that verifies that nested files in ignored dirs dont get uploaded
557
558
        self.do_upload()
559
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
560
        self.assertUpPathDoesNotExist('dir')
561
        self.assertUpPathDoesNotExist('dir/foo/bar')
0.161.3 by Martin Albisetti
Write a test that verifies that nested files in ignored dirs dont get uploaded
562
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
563
    def test_ignore_change_file_into_dir(self):
564
        self.make_branch_and_working_tree()
565
        self.add_file('hello', 'foo')
566
        self.do_full_upload()
567
        self.add_file('.bzrignore-upload', 'hello')
568
        self.transform_file_into_dir('hello')
569
        self.add_file('hello/file', 'bar')
570
571
        self.assertUpFileEqual('foo', 'hello')
572
573
        self.do_upload()
574
575
        self.assertUpFileEqual('foo', 'hello')
576
577
    def test_ignore_change_dir_into_file(self):
578
        self.make_branch_and_working_tree()
579
        self.add_dir('hello')
580
        self.add_file('hello/file', 'foo')
581
        self.do_full_upload()
582
583
        self.add_file('.bzrignore-upload', 'hello')
584
        self.delete_any('hello/file')
585
        self.transform_dir_into_file('hello', 'bar')
586
587
        self.assertUpFileEqual('foo', 'hello/file')
588
589
        self.do_upload()
590
591
        self.assertUpFileEqual('foo', 'hello/file')
592
593
    def test_ignore_delete_dir_in_subdir(self):
594
        self.make_branch_and_working_tree()
595
        self.add_dir('dir')
596
        self.add_dir('dir/subdir')
597
        self.add_file('dir/subdir/a', 'foo')
598
        self.do_full_upload()
599
        self.add_file('.bzrignore-upload', 'dir/subdir')
600
        self.rename_any('dir/subdir/a', 'dir/a')
601
        self.delete_any('dir/subdir')
602
603
        self.assertUpFileEqual('foo', 'dir/subdir/a')
604
605
        self.do_upload()
606
607
        # The file in the dir is not ignored. This a bit contrived but
608
        # indicates that we may encounter problems when ignored items appear
609
        # and disappear... -- vila 100106
610
        self.assertUpFileEqual('foo', 'dir/a')
611
0.160.4 by Martin Albisetti
Test passes!
612
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
613
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
614
615
    do_upload = TestUploadMixin.do_full_upload
616
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
617
    def test_full_upload_empty_tree(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
618
        self.make_branch_and_working_tree()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
619
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
620
        self.do_full_upload()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
621
0.152.93 by Vincent Ladeuil
Migrate to config stacks
622
        revid_path = self.tree.branch.get_config_stack(
623
            ).get('upload_revid_location')
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
624
        self.assertUpPathExists(revid_path)
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
625
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
626
    def test_invalid_revspec(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
627
        self.make_branch_and_working_tree()
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
628
        rev1 = revisionspec.RevisionSpec.from_string('1')
629
        rev2 = revisionspec.RevisionSpec.from_string('2')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
630
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
631
        self.assertRaises(errors.BzrCommandError,
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
632
                          self.do_incremental_upload, revision=[rev1, rev2])
633
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
634
    def test_create_remote_dir_twice(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
635
        self.make_branch_and_working_tree()
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
636
        self.add_dir('dir')
637
        self.do_full_upload()
638
        self.add_file('dir/goodbye', 'baz')
639
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
640
        self.assertUpPathDoesNotExist('dir/goodbye')
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
641
642
        self.do_full_upload()
643
644
        self.assertUpFileEqual('baz', 'dir/goodbye')
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
645
        self.assertUpPathModeEqual('dir', 0o775)
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
646
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
647
648
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
649
650
    do_upload = TestUploadMixin.do_incremental_upload
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
651
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
652
    # XXX: full upload doesn't handle deletions....
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
653
654
    def test_delete_one_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
655
        self.make_branch_and_working_tree()
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
656
        self.add_file('hello', 'foo')
657
        self.do_full_upload()
658
        self.delete_any('hello')
659
660
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
661
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
662
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
663
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
664
        self.assertUpPathDoesNotExist('hello')
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
665
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
666
    def test_delete_dir_and_subdir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
667
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
668
        self.add_dir('dir')
669
        self.add_dir('dir/subdir')
670
        self.add_file('dir/subdir/a', 'foo')
671
        self.do_full_upload()
672
        self.rename_any('dir/subdir/a', 'a')
673
        self.delete_any('dir/subdir')
674
        self.delete_any('dir')
675
676
        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).
677
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
678
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
679
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
680
        self.assertUpPathDoesNotExist('dir/subdir/a')
681
        self.assertUpPathDoesNotExist('dir/subdir')
682
        self.assertUpPathDoesNotExist('dir')
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
683
        self.assertUpFileEqual('foo', 'a')
684
685
    def test_delete_one_file_rename_to_deleted(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
686
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
687
        self.add_file('a', 'foo')
688
        self.add_file('b', 'bar')
689
        self.do_full_upload()
690
        self.delete_any('a')
691
        self.rename_any('b', 'a')
692
693
        self.assertUpFileEqual('foo', 'a')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
694
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
695
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
696
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
697
        self.assertUpPathDoesNotExist('b')
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
698
        self.assertUpFileEqual('bar', 'a')
699
700
    def test_rename_outside_dir_delete_dir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
701
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
702
        self.add_dir('dir')
703
        self.add_file('dir/a', 'foo')
704
        self.do_full_upload()
705
        self.rename_any('dir/a', 'a')
706
        self.delete_any('dir')
707
708
        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).
709
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
710
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
711
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
712
        self.assertUpPathDoesNotExist('dir/a')
713
        self.assertUpPathDoesNotExist('dir')
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
714
        self.assertUpFileEqual('foo', 'a')
715
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
716
    def test_delete_symlink(self):
717
        self.make_branch_and_working_tree()
718
        self.add_symlink('link', 'target')
719
        self.do_full_upload()
720
        self.delete_any('link')
721
722
        self.do_upload()
723
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
724
        self.assertUpPathDoesNotExist('link')
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
725
0.152.31 by Vincent Ladeuil
Cosmetic change.
726
    def test_upload_for_the_first_time_do_a_full_upload(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
727
        self.make_branch_and_working_tree()
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
728
        self.add_file('hello', 'bar')
0.152.31 by Vincent Ladeuil
Cosmetic change.
729
0.152.93 by Vincent Ladeuil
Migrate to config stacks
730
        revid_path = self.tree.branch.get_config_stack(
731
            ).get('upload_revid_location')
0.152.86 by Vincent Ladeuil
Get rid of the deprecation warnings while running the test suite
732
        self.assertUpPathDoesNotExist(revid_path)
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
733
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
734
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
735
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
736
        self.assertUpFileEqual('bar', 'hello')
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
737
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
738
    def test_ignore_delete_one_file(self):
739
        self.make_branch_and_working_tree()
740
        self.add_file('hello', 'foo')
741
        self.do_full_upload()
742
        self.add_file('.bzrignore-upload', 'hello')
743
        self.delete_any('hello')
744
745
        self.assertUpFileEqual('foo', 'hello')
746
747
        self.do_upload()
748
749
        self.assertUpFileEqual('foo', 'hello')
750
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
751
0.152.60 by Vincent Ladeuil
bzr.dev has finish renaming the tests modules.
752
class TestBranchUploadLocations(per_branch.TestCaseWithBranch):
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
753
754
    def test_get_upload_location_unset(self):
0.152.93 by Vincent Ladeuil
Migrate to config stacks
755
        conf = self.get_branch().get_config_stack()
756
        self.assertEqual(None, conf.get('upload_location'))
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
757
758
    def test_get_push_location_exact(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
759
        config.ensure_config_dir_exists()
760
        fn = config.locations_config_filename()
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
761
        b = self.get_branch()
0.152.93 by Vincent Ladeuil
Migrate to config stacks
762
        with open(fn, 'wt') as f:
763
            f.write(("[%s]\n" "upload_location=foo\n" % b.base.rstrip("/")))
764
        self.assertEqual("foo", b.get_config_stack().get('upload_location'))
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
765
766
    def test_set_push_location(self):
0.152.93 by Vincent Ladeuil
Migrate to config stacks
767
        conf = self.get_branch().get_config_stack()
768
        conf.set('upload_location', 'foo')
769
        self.assertEqual('foo', conf.get('upload_location'))
770
771
772
class TestUploadFromRemoteBranch(tests.TestCaseWithTransport, UploadUtilsMixin):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
773
0.158.17 by Vincent Ladeuil
New remote branch test.
774
    remote_branch_dir = 'remote_branch'
775
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
776
    def setUp(self):
777
        super(TestUploadFromRemoteBranch, self).setUp()
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
778
        if self._will_escape_isolation(self.transport_server):
779
            # FIXME: Some policy search ends up above the user home directory
780
            # and are seen as attemps to escape test isolation
781
            raise tests.TestNotApplicable('Escaping test isolation')
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
782
        self.remote_branch_url = self.make_remote_branch_without_working_tree()
783
6813.2.1 by Martin
Make upload tests pass if paramiko is not installed
784
    @staticmethod
785
    def _will_escape_isolation(transport_server):
786
        if not features.paramiko.available():
787
            return False
788
        from ....tests import stub_sftp
789
        if transport_server is stub_sftp.SFTPHomeDirServer:
790
            return True
791
        return False
792
0.158.17 by Vincent Ladeuil
New remote branch test.
793
    def make_remote_branch_without_working_tree(self):
794
        """Creates a branch without working tree to upload from.
795
796
        It's created from the existing self.branch_dir one which still has its
797
        working tree.
798
        """
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
799
        self.make_branch_and_working_tree()
800
        self.add_file('hello', 'foo')
801
0.158.17 by Vincent Ladeuil
New remote branch test.
802
        remote_branch_url = self.get_url(self.remote_branch_dir)
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
803
        self.run_bzr(['push', remote_branch_url,
804
                      '--directory', self.branch_dir])
0.158.17 by Vincent Ladeuil
New remote branch test.
805
        return remote_branch_url
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
806
0.158.17 by Vincent Ladeuil
New remote branch test.
807
    def test_no_upload_to_remote_working_tree(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
808
        cmd = self._get_cmd_upload()
0.158.17 by Vincent Ladeuil
New remote branch test.
809
        up_url = self.get_url(self.branch_dir)
810
        # Let's try to upload from the just created remote branch into the
0.152.60 by Vincent Ladeuil
bzr.dev has finish renaming the tests modules.
811
        # branch (which has a working tree).
0.165.1 by Jelmer Vernooij
Support lazily loading.
812
        self.assertRaises(cmds.CannotUploadToWorkingTree,
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
813
                          cmd.run, up_url, directory=self.remote_branch_url)
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
814
0.158.17 by Vincent Ladeuil
New remote branch test.
815
    def test_upload_without_working_tree(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
816
        self.do_full_upload(directory=self.remote_branch_url)
0.158.17 by Vincent Ladeuil
New remote branch test.
817
        self.assertUpFileEqual('foo', 'hello')
818
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
819
0.164.1 by Vincent Ladeuil
Add a test to cover bug #600628 but it is already fixed.
820
class TestUploadDiverged(tests.TestCaseWithTransport, UploadUtilsMixin):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
821
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
822
    def setUp(self):
823
        super(TestUploadDiverged, self).setUp()
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
824
        self.diverged_tree = self.make_diverged_tree_and_upload_location()
825
826
    def make_diverged_tree_and_upload_location(self):
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
827
        tree_a = self.make_branch_and_tree('tree_a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
828
        tree_a.commit('message 1', rev_id=b'rev1')
829
        tree_a.commit('message 2', rev_id=b'rev2a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
830
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
831
        uncommit.uncommit(tree_b.branch, tree=tree_b)
6855.4.1 by Jelmer Vernooij
Yet more bees.
832
        tree_b.commit('message 2', rev_id=b'rev2b')
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
833
        # upload tree a
834
        self.do_full_upload(directory=tree_a.basedir)
835
        return tree_b
836
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
837
    def assertRevidUploaded(self, revid):
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
838
        t = self.get_transport(self.upload_dir)
839
        uploaded_revid = t.get_bytes('.bzr-upload.revid')
840
        self.assertEqual(revid, uploaded_revid)
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
841
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
842
    def test_cant_upload_diverged(self):
0.165.1 by Jelmer Vernooij
Support lazily loading.
843
        self.assertRaises(cmds.DivergedUploadedTree,
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
844
                          self.do_incremental_upload,
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
845
                          directory=self.diverged_tree.basedir)
6855.4.1 by Jelmer Vernooij
Yet more bees.
846
        self.assertRevidUploaded(b'rev2a')
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
847
848
    def test_upload_diverged_with_overwrite(self):
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
849
        self.do_incremental_upload(directory=self.diverged_tree.basedir,
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
850
                                   overwrite=True)
6855.4.1 by Jelmer Vernooij
Yet more bees.
851
        self.assertRevidUploaded(b'rev2b')
0.164.1 by Vincent Ladeuil
Add a test to cover bug #600628 but it is already fixed.
852
853
854
class TestUploadBadRemoteReivd(tests.TestCaseWithTransport, UploadUtilsMixin):
855
856
    def test_raises_on_wrong_revid(self):
857
        tree = self.make_branch_and_working_tree()
858
        self.do_full_upload()
859
        # Put a fake revid on the remote branch
860
        t = self.get_transport(self.upload_dir)
861
        t.put_bytes('.bzr-upload.revid', 'fake')
862
        # Make a change
863
        self.add_file('foo', 'bar\n')
0.165.1 by Jelmer Vernooij
Support lazily loading.
864
        self.assertRaises(cmds.DivergedUploadedTree, self.do_full_upload)
0.164.1 by Vincent Ladeuil
Add a test to cover bug #600628 but it is already fixed.
865