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