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