/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.152.71 by Vincent Ladeuil
Fix failing tests.
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
0.152.1 by Vincent Ladeuil
Empty shell
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
17
import os
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
18
import stat
0.152.32 by Vincent Ladeuil
Restore verbose as the default mode.
19
import sys
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
20
0.158.11 by Gary van der Merwe
Revert revision 57: Go back to using the cmd_object.
21
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
22
from bzrlib import (
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
23
    branch,
0.152.8 by Vincent Ladeuil
Handle uploading directories.
24
    bzrdir,
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
25
    config,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
26
    errors,
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
27
    osutils,
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
28
    remote,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
29
    revisionspec,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
30
    tests,
0.152.8 by Vincent Ladeuil
Handle uploading directories.
31
    transport,
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
32
    workingtree,
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
33
    uncommit,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
34
    )
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
35
from bzrlib.smart import server as smart_server
36
from bzrlib.tests import (
0.152.60 by Vincent Ladeuil
bzr.dev has finish renaming the tests modules.
37
    per_branch,
38
    per_transport,
0.152.71 by Vincent Ladeuil
Fix failing tests.
39
    stub_sftp,
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
40
    )
0.152.65 by Vincent Ladeuil
Fix spurious failures.
41
from bzrlib.transport import (
42
    ftp,
43
    sftp,
44
    )
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
45
from bzrlib.plugins import upload
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:
57
        import bzrlib.plugins.local_test_server
58
        from bzrlib.plugins.local_test_server import test_server
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
80
def load_tests(standard_tests, module, loader):
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()
0.158.11 by Gary van der Merwe
Revert revision 57: Go back to using the cmd_object.
122
        branch = bzrdir.BzrDir.create_branch_convenience(
0.152.8 by Vincent Ladeuil
Handle uploading directories.
123
            t.base,
124
            format=bzrdir.format_registry.make_bzrdir('default'),
125
            force_new_tree=False)
0.158.11 by Gary van der Merwe
Revert revision 57: Go back to using the cmd_object.
126
        self.tree = branch.bzrdir.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)
135
        # against servers that can't. Note that some bzrlib transports define
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.15 by Vincent Ladeuil
Simplify test writing (for good ?).
149
    def failIfUpFileExists(self, path, base=upload_dir):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
150
        self.failIfExists(osutils.pathjoin(base, path))
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
151
152
    def failUnlessUpFileExists(self, path, base=upload_dir):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
153
        self.failUnlessExists(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):
203
        self.requireFeature(tests.SymlinkFeature)
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):
209
        self.requireFeature(tests.SymlinkFeature)
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.152.68 by Vincent Ladeuil
Cleanup some pending changes.
216
        cmd = upload.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.163.1 by Vincent Ladeuil
Make tests requiring a unicode file system skip where applicable
259
        self.requireFeature(tests.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
269
        self.failIfUpFileExists(fpath)
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.163.1 by Vincent Ladeuil
Make tests requiring a unicode file system skip where applicable
280
        self.requireFeature(tests.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.163.1 by Vincent Ladeuil
Make tests requiring a unicode file system skip where applicable
311
        self.requireFeature(tests.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
351
        self.failIfUpFileExists('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.163.1 by Vincent Ladeuil
Make tests requiring a unicode file system skip where applicable
396
        self.requireFeature(tests.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.163.1 by Vincent Ladeuil
Make tests requiring a unicode file system skip where applicable
430
        self.requireFeature(tests.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
440
        self.failIfUpFileExists('link')
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
451
        self.failIfUpFileExists(old_name)
452
        self.failIfUpFileExists(new_name)
453
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
454
    def get_upload_auto(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
455
        return upload.get_upload_auto(self.tree.branch)
0.158.7 by Gary van der Merwe
Clean up white space.
456
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
457
    def test_upload_auto(self):
458
        """Test that upload --auto sets the upload_auto option"""
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
459
        self.make_branch_and_working_tree()
0.158.12 by Gary van der Merwe
In the auto tests, do a upload before checking that auto is not set to handle the from Remote cases correctly. Add some blank line for clarity.
460
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
461
        self.add_file('hello', 'foo')
0.158.12 by Gary van der Merwe
In the auto tests, do a upload before checking that auto is not set to handle the from Remote cases correctly. Add some blank line for clarity.
462
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
463
        self.do_full_upload(auto=True)
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
464
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
465
        self.assertTrue(self.get_upload_auto())
0.158.12 by Gary van der Merwe
In the auto tests, do a upload before checking that auto is not set to handle the from Remote cases correctly. Add some blank line for clarity.
466
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
467
        # and check that it stays set until it is unset
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
468
        self.add_file('bye', 'bar')
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
469
        self.do_full_upload()
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
470
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
471
        self.assertTrue(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
472
473
    def test_upload_noauto(self):
474
        """Test that upload --no-auto unsets the upload_auto option"""
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
475
        self.make_branch_and_working_tree()
0.158.12 by Gary van der Merwe
In the auto tests, do a upload before checking that auto is not set to handle the from Remote cases correctly. Add some blank line for clarity.
476
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
477
        self.add_file('hello', 'foo')
478
        self.do_full_upload(auto=True)
479
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
480
        self.assertTrue(self.get_upload_auto())
0.158.12 by Gary van der Merwe
In the auto tests, do a upload before checking that auto is not set to handle the from Remote cases correctly. Add some blank line for clarity.
481
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
482
        self.add_file('bye', 'bar')
483
        self.do_full_upload(auto=False)
484
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
485
        self.assertFalse(self.get_upload_auto())
0.158.12 by Gary van der Merwe
In the auto tests, do a upload before checking that auto is not set to handle the from Remote cases correctly. Add some blank line for clarity.
486
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
487
        # and check that it stays unset until it is set
488
        self.add_file('again', 'baz')
489
        self.do_full_upload()
490
        self.assertUpFileEqual('baz', 'again')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
491
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
492
0.156.1 by James Westby
Use open_containing rather than open, so that you can upload from a subdir.
493
    def test_upload_from_subdir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
494
        self.make_branch_and_working_tree()
0.156.1 by James Westby
Use open_containing rather than open, so that you can upload from a subdir.
495
        self.build_tree(['branch/foo/', 'branch/foo/bar'])
496
        self.tree.add(['foo/', 'foo/bar'])
497
        self.tree.commit("Add directory")
498
        self.do_full_upload(directory='branch/foo')
499
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
500
    def test_upload_revid_path_in_dir(self):
501
        self.make_branch_and_working_tree()
502
        self.add_dir('dir')
503
        self.add_file('dir/goodbye', 'baz')
504
505
        revid_path = 'dir/revid-path'
506
        upload.set_upload_revid_location(self.tree.branch, revid_path)
507
        self.failIfUpFileExists(revid_path)
508
509
        self.do_full_upload()
510
511
        self.add_file('dir/hello', 'foo')
512
513
        self.do_upload()
514
515
        self.failUnlessUpFileExists(revid_path)
516
        self.assertUpFileEqual('baz', 'dir/goodbye')
517
        self.assertUpFileEqual('foo', 'dir/hello')
518
0.160.1 by Martin Albisetti
Wrote the test first. TDD, dont fail me now.
519
    def test_ignore_file(self):
520
        self.make_branch_and_working_tree()
521
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
522
        self.add_file('.bzrignore-upload', 'foo')
523
        self.add_file('foo', 'bar')
524
525
        self.do_upload()
526
527
        self.failIfUpFileExists('foo')
528
529
    def test_ignore_regexp(self):
530
        self.make_branch_and_working_tree()
531
        self.do_full_upload()
532
        self.add_file('.bzrignore-upload', 'f*')
0.160.1 by Martin Albisetti
Wrote the test first. TDD, dont fail me now.
533
        self.add_file('foo', 'bar')
534
535
        self.do_upload()
536
537
        self.failIfUpFileExists('foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
538
0.160.11 by Martin Albisetti
Add test for ignoring a dir
539
    def test_ignore_directory(self):
540
        self.make_branch_and_working_tree()
541
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
542
        self.add_file('.bzrignore-upload', 'dir')
0.160.11 by Martin Albisetti
Add test for ignoring a dir
543
        self.add_dir('dir')
544
545
        self.do_upload()
546
547
        self.failIfUpFileExists('dir')
548
0.161.3 by Martin Albisetti
Write a test that verifies that nested files in ignored dirs dont get uploaded
549
    def test_ignore_nested_directory(self):
550
        self.make_branch_and_working_tree()
551
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
552
        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
553
        self.add_dir('dir')
554
        self.add_dir('dir/foo')
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
555
        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
556
557
        self.do_upload()
558
559
        self.failIfUpFileExists('dir')
560
        self.failIfUpFileExists('dir/foo/bar')
561
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
562
    def test_ignore_change_file_into_dir(self):
563
        self.make_branch_and_working_tree()
564
        self.add_file('hello', 'foo')
565
        self.do_full_upload()
566
        self.add_file('.bzrignore-upload', 'hello')
567
        self.transform_file_into_dir('hello')
568
        self.add_file('hello/file', 'bar')
569
570
        self.assertUpFileEqual('foo', 'hello')
571
572
        self.do_upload()
573
574
        self.assertUpFileEqual('foo', 'hello')
575
576
    def test_ignore_change_dir_into_file(self):
577
        self.make_branch_and_working_tree()
578
        self.add_dir('hello')
579
        self.add_file('hello/file', 'foo')
580
        self.do_full_upload()
581
582
        self.add_file('.bzrignore-upload', 'hello')
583
        self.delete_any('hello/file')
584
        self.transform_dir_into_file('hello', 'bar')
585
586
        self.assertUpFileEqual('foo', 'hello/file')
587
588
        self.do_upload()
589
590
        self.assertUpFileEqual('foo', 'hello/file')
591
592
    def test_ignore_delete_dir_in_subdir(self):
593
        self.make_branch_and_working_tree()
594
        self.add_dir('dir')
595
        self.add_dir('dir/subdir')
596
        self.add_file('dir/subdir/a', 'foo')
597
        self.do_full_upload()
598
        self.add_file('.bzrignore-upload', 'dir/subdir')
599
        self.rename_any('dir/subdir/a', 'dir/a')
600
        self.delete_any('dir/subdir')
601
602
        self.assertUpFileEqual('foo', 'dir/subdir/a')
603
604
        self.do_upload()
605
606
        # The file in the dir is not ignored. This a bit contrived but
607
        # indicates that we may encounter problems when ignored items appear
608
        # and disappear... -- vila 100106
609
        self.assertUpFileEqual('foo', 'dir/a')
610
0.160.4 by Martin Albisetti
Test passes!
611
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
612
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
613
614
    do_upload = TestUploadMixin.do_full_upload
615
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
616
    def test_full_upload_empty_tree(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
617
        self.make_branch_and_working_tree()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
618
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
619
        self.do_full_upload()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
620
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
621
        revid_path = upload.get_upload_revid_location(self.tree.branch)
622
        self.failUnlessUpFileExists(revid_path)
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
623
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
624
    def test_invalid_revspec(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
625
        self.make_branch_and_working_tree()
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
626
        rev1 = revisionspec.RevisionSpec.from_string('1')
627
        rev2 = revisionspec.RevisionSpec.from_string('2')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
628
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
629
        self.assertRaises(errors.BzrCommandError,
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
630
                          self.do_incremental_upload, revision=[rev1, rev2])
631
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
632
    def test_create_remote_dir_twice(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
633
        self.make_branch_and_working_tree()
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
634
        self.add_dir('dir')
635
        self.do_full_upload()
636
        self.add_file('dir/goodbye', 'baz')
637
638
        self.failIfUpFileExists('dir/goodbye')
639
640
        self.do_full_upload()
641
642
        self.assertUpFileEqual('baz', 'dir/goodbye')
643
        self.assertUpPathModeEqual('dir', 0775)
644
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
645
646
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
647
648
    do_upload = TestUploadMixin.do_incremental_upload
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
649
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
650
    # XXX: full upload doesn't handle deletions....
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
651
652
    def test_delete_one_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
653
        self.make_branch_and_working_tree()
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
654
        self.add_file('hello', 'foo')
655
        self.do_full_upload()
656
        self.delete_any('hello')
657
658
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
659
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
660
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
661
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
662
        self.failIfUpFileExists('hello')
663
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
664
    def test_delete_dir_and_subdir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
665
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
666
        self.add_dir('dir')
667
        self.add_dir('dir/subdir')
668
        self.add_file('dir/subdir/a', 'foo')
669
        self.do_full_upload()
670
        self.rename_any('dir/subdir/a', 'a')
671
        self.delete_any('dir/subdir')
672
        self.delete_any('dir')
673
674
        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).
675
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
676
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
677
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
678
        self.failIfUpFileExists('dir/subdir/a')
679
        self.failIfUpFileExists('dir/subdir')
680
        self.failIfUpFileExists('dir')
681
        self.assertUpFileEqual('foo', 'a')
682
683
    def test_delete_one_file_rename_to_deleted(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
684
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
685
        self.add_file('a', 'foo')
686
        self.add_file('b', 'bar')
687
        self.do_full_upload()
688
        self.delete_any('a')
689
        self.rename_any('b', 'a')
690
691
        self.assertUpFileEqual('foo', 'a')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
692
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
693
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
694
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
695
        self.failIfUpFileExists('b')
696
        self.assertUpFileEqual('bar', 'a')
697
698
    def test_rename_outside_dir_delete_dir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
699
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
700
        self.add_dir('dir')
701
        self.add_file('dir/a', 'foo')
702
        self.do_full_upload()
703
        self.rename_any('dir/a', 'a')
704
        self.delete_any('dir')
705
706
        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).
707
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
708
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
709
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
710
        self.failIfUpFileExists('dir/a')
711
        self.failIfUpFileExists('dir')
712
        self.assertUpFileEqual('foo', 'a')
713
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
714
    def test_delete_symlink(self):
715
        self.make_branch_and_working_tree()
716
        self.add_symlink('link', 'target')
717
        self.do_full_upload()
718
        self.delete_any('link')
719
720
        self.do_upload()
721
722
        self.failIfUpFileExists('link')
723
0.152.31 by Vincent Ladeuil
Cosmetic change.
724
    def test_upload_for_the_first_time_do_a_full_upload(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
725
        self.make_branch_and_working_tree()
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
726
        self.add_file('hello', 'bar')
0.152.31 by Vincent Ladeuil
Cosmetic change.
727
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
728
        revid_path = upload.get_upload_revid_location(self.tree.branch)
729
        self.failIfUpFileExists(revid_path)
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
730
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
731
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
732
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
733
        self.assertUpFileEqual('bar', 'hello')
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
734
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
735
    def test_ignore_delete_one_file(self):
736
        self.make_branch_and_working_tree()
737
        self.add_file('hello', 'foo')
738
        self.do_full_upload()
739
        self.add_file('.bzrignore-upload', 'hello')
740
        self.delete_any('hello')
741
742
        self.assertUpFileEqual('foo', 'hello')
743
744
        self.do_upload()
745
746
        self.assertUpFileEqual('foo', 'hello')
747
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
748
0.152.60 by Vincent Ladeuil
bzr.dev has finish renaming the tests modules.
749
class TestBranchUploadLocations(per_branch.TestCaseWithBranch):
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
750
751
    def test_get_upload_location_unset(self):
752
        config = self.get_branch().get_config()
753
        self.assertEqual(None, config.get_user_option('upload_location'))
754
755
    def test_get_push_location_exact(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
756
        config.ensure_config_dir_exists()
757
        fn = config.locations_config_filename()
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
758
        b = self.get_branch()
759
        open(fn, 'wt').write(("[%s]\n"
760
                                  "upload_location=foo\n" %
761
                                  b.base[:-1]))
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
762
        conf = b.get_config()
763
        self.assertEqual("foo", conf.get_user_option('upload_location'))
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
764
765
    def test_set_push_location(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
766
        conf = self.get_branch().get_config()
767
        conf.set_user_option('upload_location', 'foo')
768
        self.assertEqual('foo', conf.get_user_option('upload_location'))
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
769
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
770
771
class TestUploadFromRemoteBranch(tests.TestCaseWithTransport,
772
                                 UploadUtilsMixin):
773
0.158.17 by Vincent Ladeuil
New remote branch test.
774
    remote_branch_dir = 'remote_branch'
775
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
776
    def setUp(self):
777
        super(TestUploadFromRemoteBranch, self).setUp()
778
        self.remote_branch_url = self.make_remote_branch_without_working_tree()
779
0.158.17 by Vincent Ladeuil
New remote branch test.
780
    def make_remote_branch_without_working_tree(self):
781
        """Creates a branch without working tree to upload from.
782
783
        It's created from the existing self.branch_dir one which still has its
784
        working tree.
785
        """
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
786
        self.make_branch_and_working_tree()
787
        self.add_file('hello', 'foo')
788
0.158.17 by Vincent Ladeuil
New remote branch test.
789
        remote_branch_url = self.get_url(self.remote_branch_dir)
0.152.71 by Vincent Ladeuil
Fix failing tests.
790
        if self.transport_server is stub_sftp.SFTPHomeDirServer:
0.152.65 by Vincent Ladeuil
Fix spurious failures.
791
            # FIXME: Some policy search ends up above the user home directory
792
            # and are seen as attemps to escape test isolation
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
793
            raise tests.TestNotApplicable('Escaping test isolation')
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
794
        self.run_bzr(['push', remote_branch_url,
795
                      '--directory', self.branch_dir])
0.158.17 by Vincent Ladeuil
New remote branch test.
796
        return remote_branch_url
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
797
0.158.17 by Vincent Ladeuil
New remote branch test.
798
    def test_no_upload_to_remote_working_tree(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
799
        cmd = self._get_cmd_upload()
0.158.17 by Vincent Ladeuil
New remote branch test.
800
        up_url = self.get_url(self.branch_dir)
801
        # 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.
802
        # branch (which has a working tree).
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
803
        self.assertRaises(upload.CannotUploadToWorkingTree,
804
                          cmd.run, up_url, directory=self.remote_branch_url)
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
805
0.158.17 by Vincent Ladeuil
New remote branch test.
806
    def test_upload_without_working_tree(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
807
        self.do_full_upload(directory=self.remote_branch_url)
0.158.17 by Vincent Ladeuil
New remote branch test.
808
        self.assertUpFileEqual('foo', 'hello')
809
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
810
0.164.1 by Vincent Ladeuil
Add a test to cover bug #600628 but it is already fixed.
811
class TestUploadDiverged(tests.TestCaseWithTransport, UploadUtilsMixin):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
812
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
813
    def setUp(self):
814
        super(TestUploadDiverged, self).setUp()
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
815
        self.diverged_tree = self.make_diverged_tree_and_upload_location()
816
817
    def make_diverged_tree_and_upload_location(self):
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
818
        tree_a = self.make_branch_and_tree('tree_a')
819
        tree_a.commit('message 1', rev_id='rev1')
820
        tree_a.commit('message 2', rev_id='rev2a')
821
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
822
        uncommit.uncommit(tree_b.branch, tree=tree_b)
823
        tree_b.commit('message 2', rev_id='rev2b')
824
        # upload tree a
825
        self.do_full_upload(directory=tree_a.basedir)
826
        return tree_b
827
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
828
    def assertRevidUploaded(self, revid):
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
829
        t = self.get_transport(self.upload_dir)
830
        uploaded_revid = t.get_bytes('.bzr-upload.revid')
831
        self.assertEqual(revid, uploaded_revid)
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
832
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
833
    def test_cant_upload_diverged(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
834
        self.assertRaises(upload.DivergedUploadedTree,
835
                          self.do_incremental_upload,
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
836
                          directory=self.diverged_tree.basedir)
837
        self.assertRevidUploaded('rev2a')
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
838
839
    def test_upload_diverged_with_overwrite(self):
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
840
        self.do_incremental_upload(directory=self.diverged_tree.basedir,
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
841
                                   overwrite=True)
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
842
        self.assertRevidUploaded('rev2b')
0.164.1 by Vincent Ladeuil
Add a test to cover bug #600628 but it is already fixed.
843
844
845
class TestUploadBadRemoteReivd(tests.TestCaseWithTransport, UploadUtilsMixin):
846
847
    def test_raises_on_wrong_revid(self):
848
        tree = self.make_branch_and_working_tree()
849
        self.do_full_upload()
850
        # Put a fake revid on the remote branch
851
        t = self.get_transport(self.upload_dir)
852
        t.put_bytes('.bzr-upload.revid', 'fake')
853
        # Make a change
854
        self.add_file('foo', 'bar\n')
855
        self.assertRaises(upload.DivergedUploadedTree, self.do_full_upload)
856