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