/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):
259
        self._test_create_file(u'hell\u00d8')
260
261
    def _test_create_file_in_dir(self, dir_name, file_name):
262
        self.make_branch_and_working_tree()
263
        self.do_full_upload()
264
        self.add_dir(dir_name)
265
        fpath = '%s/%s' % (dir_name, file_name)
266
        self.add_file(fpath, 'baz')
267
268
        self.failIfUpFileExists(fpath)
269
270
        self.do_upload()
271
272
        self.assertUpFileEqual('baz', fpath)
273
        self.assertUpPathModeEqual(dir_name, 0775)
274
275
    def test_create_file_in_dir(self):
276
        self._test_create_file_in_dir('dir', 'goodbye')
277
278
    def test_unicode_create_file_in_dir(self):
279
        self._test_create_file_in_dir(u'dir\u00d8', u'goodbye\u00d8')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
280
281
    def test_modify_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
282
        self.make_branch_and_working_tree()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
283
        self.add_file('hello', 'foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
284
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
285
        self.modify_file('hello', 'bar')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
286
287
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
288
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
289
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
290
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
291
        self.assertUpFileEqual('bar', 'hello')
292
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
293
    def _test_rename_one_file(self, old_name, new_name):
294
        self.make_branch_and_working_tree()
295
        self.add_file(old_name, 'foo')
296
        self.do_full_upload()
297
        self.rename_any(old_name, new_name)
298
299
        self.assertUpFileEqual('foo', old_name)
300
301
        self.do_upload()
302
303
        self.assertUpFileEqual('foo', new_name)
304
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
305
    def test_rename_one_file(self):
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
306
        self._test_rename_one_file('hello', 'goodbye')
307
308
    def test_unicode_rename_one_file(self):
309
        self._test_rename_one_file(u'hello\u00d8', u'goodbye\u00d8')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
310
0.152.52 by Vincent Ladeuil
Fix bug #270219 by handling content changes during renames.
311
    def test_rename_and_change_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
312
        self.make_branch_and_working_tree()
0.152.52 by Vincent Ladeuil
Fix bug #270219 by handling content changes during renames.
313
        self.add_file('hello', 'foo')
314
        self.do_full_upload()
315
        self.rename_any('hello', 'goodbye')
316
        self.modify_file('goodbye', 'bar')
317
318
        self.assertUpFileEqual('foo', 'hello')
319
320
        self.do_upload()
321
322
        self.assertUpFileEqual('bar', 'goodbye')
323
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
324
    def test_rename_two_files(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
325
        self.make_branch_and_working_tree()
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
326
        self.add_file('a', 'foo')
327
        self.add_file('b', 'qux')
328
        self.do_full_upload()
329
        # We rely on the assumption that bzr will topologically sort the
330
        # renames which will cause a -> b to appear *before* b -> c
331
        self.rename_any('b', 'c')
332
        self.rename_any('a', 'b')
333
334
        self.assertUpFileEqual('foo', 'a')
335
        self.assertUpFileEqual('qux', 'b')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
336
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
337
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
338
0.152.16 by Vincent Ladeuil
Handle renames. Robust implementation.
339
        self.assertUpFileEqual('foo', 'b')
340
        self.assertUpFileEqual('qux', 'c')
341
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
342
    def test_upload_revision(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
343
        self.make_branch_and_working_tree() # rev1
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
344
        self.do_full_upload()
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
345
        self.add_file('hello', 'foo') # rev2
346
        self.modify_file('hello', 'bar') # rev3
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
347
348
        self.failIfUpFileExists('hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
349
0.152.15 by Vincent Ladeuil
Simplify test writing (for good ?).
350
        revspec = revisionspec.RevisionSpec.from_string('2')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
351
        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).
352
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
353
        self.assertUpFileEqual('foo', 'hello')
354
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
355
    def test_no_upload_when_changes(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
356
        self.make_branch_and_working_tree()
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
357
        self.add_file('a', 'foo')
358
        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).
359
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
360
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
361
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
362
    def test_no_upload_when_conflicts(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
363
        self.make_branch_and_working_tree()
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
364
        self.add_file('a', 'foo')
365
        self.run_bzr('branch branch other')
366
        self.modify_file('a', 'bar')
367
        other_tree = workingtree.WorkingTree.open('other')
368
        self.set_file_content('a', 'baz', 'other/')
369
        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).
370
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
371
        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).
372
0.152.33 by Vincent Ladeuil
Ensure that we refuse to upload if the working tree contains
373
        self.assertRaises(errors.UncommittedChanges, self.do_upload)
374
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
375
    def _test_change_file_into_dir(self, file_name):
376
        self.make_branch_and_working_tree()
377
        self.add_file(file_name, 'foo')
378
        self.do_full_upload()
379
        self.transform_file_into_dir(file_name)
380
        fpath = '%s/%s' % (file_name, 'file')
381
        self.add_file(fpath, 'bar')
382
383
        self.assertUpFileEqual('foo', file_name)
384
385
        self.do_upload()
386
387
        self.assertUpFileEqual('bar', fpath)
388
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
389
    def test_change_file_into_dir(self):
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
390
        self._test_change_file_into_dir('hello')
391
392
    def test_unicode_change_file_into_dir(self):
393
        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).
394
395
    def test_change_dir_into_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
396
        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).
397
        self.add_dir('hello')
398
        self.add_file('hello/file', 'foo')
399
        self.do_full_upload()
400
        self.delete_any('hello/file')
401
        self.transform_dir_into_file('hello', 'bar')
402
403
        self.assertUpFileEqual('foo', 'hello/file')
404
405
        self.do_upload()
406
407
        self.assertUpFileEqual('bar', 'hello')
408
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
409
    def _test_make_file_executable(self, file_name):
410
        self.make_branch_and_working_tree()
411
        self.add_file(file_name, 'foo')
412
        self.chmod_file(file_name, 0664)
413
        self.do_full_upload()
414
        self.chmod_file(file_name, 0755)
415
416
        self.assertUpPathModeEqual(file_name, 0664)
417
418
        self.do_upload()
419
420
        self.assertUpPathModeEqual(file_name, 0775)
421
0.152.46 by Vincent Ladeuil
Handle x mode bit for files and provides default mode bits for
422
    def test_make_file_executable(self):
0.152.70 by Vincent Ladeuil
Ensure we use the transport API correctly for unicode paths.
423
        self._test_make_file_executable('hello')
424
425
    def test_unicode_make_file_executable(self):
426
        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
427
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
428
    def test_create_symlink(self):
429
        self.make_branch_and_working_tree()
430
        self.do_full_upload()
431
        self.add_symlink('link', 'target')
432
433
        self.do_upload()
434
435
        self.failIfUpFileExists('link')
436
437
    def test_rename_symlink(self):
438
        self.make_branch_and_working_tree()
439
        old_name, new_name = 'old-link', 'new-link'
440
        self.add_symlink(old_name, 'target')
441
        self.do_full_upload()
442
        self.rename_any(old_name, new_name)
443
444
        self.do_upload()
445
446
        self.failIfUpFileExists(old_name)
447
        self.failIfUpFileExists(new_name)
448
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
449
    def get_upload_auto(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
450
        return upload.get_upload_auto(self.tree.branch)
0.158.7 by Gary van der Merwe
Clean up white space.
451
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
452
    def test_upload_auto(self):
453
        """Test that upload --auto sets the upload_auto option"""
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
454
        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.
455
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
456
        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.
457
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
458
        self.do_full_upload(auto=True)
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
459
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
460
        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.
461
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
462
        # and check that it stays set until it is unset
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
463
        self.add_file('bye', 'bar')
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
464
        self.do_full_upload()
0.158.21 by Vincent Ladeuil
Revert test while keeping Gary's refactoring.
465
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
466
        self.assertTrue(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
467
468
    def test_upload_noauto(self):
469
        """Test that upload --no-auto unsets the upload_auto option"""
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
470
        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.
471
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
472
        self.add_file('hello', 'foo')
473
        self.do_full_upload(auto=True)
474
        self.assertUpFileEqual('foo', 'hello')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
475
        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.
476
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
477
        self.add_file('bye', 'bar')
478
        self.do_full_upload(auto=False)
479
        self.assertUpFileEqual('bar', 'bye')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
480
        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.
481
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
482
        # and check that it stays unset until it is set
483
        self.add_file('again', 'baz')
484
        self.do_full_upload()
485
        self.assertUpFileEqual('baz', 'again')
0.158.6 by Gary van der Merwe
Correctly test auto when testing remote branches.
486
        self.assertFalse(self.get_upload_auto())
0.155.4 by James Westby
Add the groundwork for --auto that enables the hook for a branch.
487
0.156.1 by James Westby
Use open_containing rather than open, so that you can upload from a subdir.
488
    def test_upload_from_subdir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
489
        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.
490
        self.build_tree(['branch/foo/', 'branch/foo/bar'])
491
        self.tree.add(['foo/', 'foo/bar'])
492
        self.tree.commit("Add directory")
493
        self.do_full_upload(directory='branch/foo')
494
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
495
    def test_upload_revid_path_in_dir(self):
496
        self.make_branch_and_working_tree()
497
        self.add_dir('dir')
498
        self.add_file('dir/goodbye', 'baz')
499
500
        revid_path = 'dir/revid-path'
501
        upload.set_upload_revid_location(self.tree.branch, revid_path)
502
        self.failIfUpFileExists(revid_path)
503
504
        self.do_full_upload()
505
506
        self.add_file('dir/hello', 'foo')
507
508
        self.do_upload()
509
510
        self.failUnlessUpFileExists(revid_path)
511
        self.assertUpFileEqual('baz', 'dir/goodbye')
512
        self.assertUpFileEqual('foo', 'dir/hello')
513
0.160.1 by Martin Albisetti
Wrote the test first. TDD, dont fail me now.
514
    def test_ignore_file(self):
515
        self.make_branch_and_working_tree()
516
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
517
        self.add_file('.bzrignore-upload', 'foo')
518
        self.add_file('foo', 'bar')
519
520
        self.do_upload()
521
522
        self.failIfUpFileExists('foo')
523
524
    def test_ignore_regexp(self):
525
        self.make_branch_and_working_tree()
526
        self.do_full_upload()
527
        self.add_file('.bzrignore-upload', 'f*')
0.160.1 by Martin Albisetti
Wrote the test first. TDD, dont fail me now.
528
        self.add_file('foo', 'bar')
529
530
        self.do_upload()
531
532
        self.failIfUpFileExists('foo')
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
533
0.160.11 by Martin Albisetti
Add test for ignoring a dir
534
    def test_ignore_directory(self):
535
        self.make_branch_and_working_tree()
536
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
537
        self.add_file('.bzrignore-upload', 'dir')
0.160.11 by Martin Albisetti
Add test for ignoring a dir
538
        self.add_dir('dir')
539
540
        self.do_upload()
541
542
        self.failIfUpFileExists('dir')
543
0.161.3 by Martin Albisetti
Write a test that verifies that nested files in ignored dirs dont get uploaded
544
    def test_ignore_nested_directory(self):
545
        self.make_branch_and_working_tree()
546
        self.do_full_upload()
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
547
        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
548
        self.add_dir('dir')
549
        self.add_dir('dir/foo')
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
550
        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
551
552
        self.do_upload()
553
554
        self.failIfUpFileExists('dir')
555
        self.failIfUpFileExists('dir/foo/bar')
556
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
557
    def test_ignore_change_file_into_dir(self):
558
        self.make_branch_and_working_tree()
559
        self.add_file('hello', 'foo')
560
        self.do_full_upload()
561
        self.add_file('.bzrignore-upload', 'hello')
562
        self.transform_file_into_dir('hello')
563
        self.add_file('hello/file', 'bar')
564
565
        self.assertUpFileEqual('foo', 'hello')
566
567
        self.do_upload()
568
569
        self.assertUpFileEqual('foo', 'hello')
570
571
    def test_ignore_change_dir_into_file(self):
572
        self.make_branch_and_working_tree()
573
        self.add_dir('hello')
574
        self.add_file('hello/file', 'foo')
575
        self.do_full_upload()
576
577
        self.add_file('.bzrignore-upload', 'hello')
578
        self.delete_any('hello/file')
579
        self.transform_dir_into_file('hello', 'bar')
580
581
        self.assertUpFileEqual('foo', 'hello/file')
582
583
        self.do_upload()
584
585
        self.assertUpFileEqual('foo', 'hello/file')
586
587
    def test_ignore_delete_dir_in_subdir(self):
588
        self.make_branch_and_working_tree()
589
        self.add_dir('dir')
590
        self.add_dir('dir/subdir')
591
        self.add_file('dir/subdir/a', 'foo')
592
        self.do_full_upload()
593
        self.add_file('.bzrignore-upload', 'dir/subdir')
594
        self.rename_any('dir/subdir/a', 'dir/a')
595
        self.delete_any('dir/subdir')
596
597
        self.assertUpFileEqual('foo', 'dir/subdir/a')
598
599
        self.do_upload()
600
601
        # The file in the dir is not ignored. This a bit contrived but
602
        # indicates that we may encounter problems when ignored items appear
603
        # and disappear... -- vila 100106
604
        self.assertUpFileEqual('foo', 'dir/a')
605
0.160.4 by Martin Albisetti
Test passes!
606
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
607
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
608
609
    do_upload = TestUploadMixin.do_full_upload
610
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
611
    def test_full_upload_empty_tree(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
612
        self.make_branch_and_working_tree()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
613
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
614
        self.do_full_upload()
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
615
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
616
        revid_path = upload.get_upload_revid_location(self.tree.branch)
617
        self.failUnlessUpFileExists(revid_path)
0.152.13 by Vincent Ladeuil
Test uploading an empty tree.
618
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
619
    def test_invalid_revspec(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
620
        self.make_branch_and_working_tree()
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
621
        rev1 = revisionspec.RevisionSpec.from_string('1')
622
        rev2 = revisionspec.RevisionSpec.from_string('2')
0.152.8 by Vincent Ladeuil
Handle uploading directories.
623
0.152.9 by Vincent Ladeuil
Recfactoring to simplify tests writing.
624
        self.assertRaises(errors.BzrCommandError,
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
625
                          self.do_incremental_upload, revision=[rev1, rev2])
626
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
627
    def test_create_remote_dir_twice(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
628
        self.make_branch_and_working_tree()
0.152.47 by Vincent Ladeuil
Don't fail a full upload on an already existing dir.
629
        self.add_dir('dir')
630
        self.do_full_upload()
631
        self.add_file('dir/goodbye', 'baz')
632
633
        self.failIfUpFileExists('dir/goodbye')
634
635
        self.do_full_upload()
636
637
        self.assertUpFileEqual('baz', 'dir/goodbye')
638
        self.assertUpPathModeEqual('dir', 0775)
639
0.152.14 by Vincent Ladeuil
Handle renames (trivial implementation).
640
641
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
642
643
    do_upload = TestUploadMixin.do_incremental_upload
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
644
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
645
    # XXX: full upload doesn't handle deletions....
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
646
647
    def test_delete_one_file(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
648
        self.make_branch_and_working_tree()
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
649
        self.add_file('hello', 'foo')
650
        self.do_full_upload()
651
        self.delete_any('hello')
652
653
        self.assertUpFileEqual('foo', 'hello')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
654
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
655
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
656
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
657
        self.failIfUpFileExists('hello')
658
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
659
    def test_delete_dir_and_subdir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
660
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
661
        self.add_dir('dir')
662
        self.add_dir('dir/subdir')
663
        self.add_file('dir/subdir/a', 'foo')
664
        self.do_full_upload()
665
        self.rename_any('dir/subdir/a', 'a')
666
        self.delete_any('dir/subdir')
667
        self.delete_any('dir')
668
669
        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).
670
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
671
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
672
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
673
        self.failIfUpFileExists('dir/subdir/a')
674
        self.failIfUpFileExists('dir/subdir')
675
        self.failIfUpFileExists('dir')
676
        self.assertUpFileEqual('foo', 'a')
677
678
    def test_delete_one_file_rename_to_deleted(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
679
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
680
        self.add_file('a', 'foo')
681
        self.add_file('b', 'bar')
682
        self.do_full_upload()
683
        self.delete_any('a')
684
        self.rename_any('b', 'a')
685
686
        self.assertUpFileEqual('foo', 'a')
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
687
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
688
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
689
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
690
        self.failIfUpFileExists('b')
691
        self.assertUpFileEqual('bar', 'a')
692
693
    def test_rename_outside_dir_delete_dir(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
694
        self.make_branch_and_working_tree()
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
695
        self.add_dir('dir')
696
        self.add_file('dir/a', 'foo')
697
        self.do_full_upload()
698
        self.rename_any('dir/a', 'a')
699
        self.delete_any('dir')
700
701
        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).
702
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
703
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
704
0.152.18 by Vincent Ladeuil
Handle deletions. Robust implementation.
705
        self.failIfUpFileExists('dir/a')
706
        self.failIfUpFileExists('dir')
707
        self.assertUpFileEqual('foo', 'a')
708
0.162.1 by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered
709
    def test_delete_symlink(self):
710
        self.make_branch_and_working_tree()
711
        self.add_symlink('link', 'target')
712
        self.do_full_upload()
713
        self.delete_any('link')
714
715
        self.do_upload()
716
717
        self.failIfUpFileExists('link')
718
0.152.31 by Vincent Ladeuil
Cosmetic change.
719
    def test_upload_for_the_first_time_do_a_full_upload(self):
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
720
        self.make_branch_and_working_tree()
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
721
        self.add_file('hello', 'bar')
0.152.31 by Vincent Ladeuil
Cosmetic change.
722
0.152.62 by Vincent Ladeuil
Fix bug #423331 by adding a way to configure the path used to
723
        revid_path = upload.get_upload_revid_location(self.tree.branch)
724
        self.failIfUpFileExists(revid_path)
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
725
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
726
        self.do_upload()
0.152.44 by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa).
727
0.152.25 by Martin Albisetti
Added test for uploading for the first time to a remote location
728
        self.assertUpFileEqual('bar', 'hello')
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
729
0.161.4 by Vincent Ladeuil
Handle regexps in .bzrignore-upload and take parents into account.
730
    def test_ignore_delete_one_file(self):
731
        self.make_branch_and_working_tree()
732
        self.add_file('hello', 'foo')
733
        self.do_full_upload()
734
        self.add_file('.bzrignore-upload', 'hello')
735
        self.delete_any('hello')
736
737
        self.assertUpFileEqual('foo', 'hello')
738
739
        self.do_upload()
740
741
        self.assertUpFileEqual('foo', 'hello')
742
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
743
0.152.60 by Vincent Ladeuil
bzr.dev has finish renaming the tests modules.
744
class TestBranchUploadLocations(per_branch.TestCaseWithBranch):
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
745
746
    def test_get_upload_location_unset(self):
747
        config = self.get_branch().get_config()
748
        self.assertEqual(None, config.get_user_option('upload_location'))
749
750
    def test_get_push_location_exact(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
751
        config.ensure_config_dir_exists()
752
        fn = config.locations_config_filename()
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
753
        b = self.get_branch()
754
        open(fn, 'wt').write(("[%s]\n"
755
                                  "upload_location=foo\n" %
756
                                  b.base[:-1]))
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
757
        conf = b.get_config()
758
        self.assertEqual("foo", conf.get_user_option('upload_location'))
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
759
760
    def test_set_push_location(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
761
        conf = self.get_branch().get_config()
762
        conf.set_user_option('upload_location', 'foo')
763
        self.assertEqual('foo', conf.get_user_option('upload_location'))
0.152.12 by Vincent Ladeuil
Implement 'upload_location' in config files.
764
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
765
766
class TestUploadFromRemoteBranch(tests.TestCaseWithTransport,
767
                                 UploadUtilsMixin):
768
0.158.17 by Vincent Ladeuil
New remote branch test.
769
    remote_branch_dir = 'remote_branch'
770
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
771
    def setUp(self):
772
        super(TestUploadFromRemoteBranch, self).setUp()
773
        self.remote_branch_url = self.make_remote_branch_without_working_tree()
774
0.158.17 by Vincent Ladeuil
New remote branch test.
775
    def make_remote_branch_without_working_tree(self):
776
        """Creates a branch without working tree to upload from.
777
778
        It's created from the existing self.branch_dir one which still has its
779
        working tree.
780
        """
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
781
        self.make_branch_and_working_tree()
782
        self.add_file('hello', 'foo')
783
0.158.17 by Vincent Ladeuil
New remote branch test.
784
        remote_branch_url = self.get_url(self.remote_branch_dir)
0.152.71 by Vincent Ladeuil
Fix failing tests.
785
        if self.transport_server is stub_sftp.SFTPHomeDirServer:
0.152.65 by Vincent Ladeuil
Fix spurious failures.
786
            # FIXME: Some policy search ends up above the user home directory
787
            # and are seen as attemps to escape test isolation
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
788
            raise tests.TestNotApplicable('Escaping test isolation')
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
789
        self.run_bzr(['push', remote_branch_url,
790
                      '--directory', self.branch_dir])
0.158.17 by Vincent Ladeuil
New remote branch test.
791
        return remote_branch_url
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
792
0.158.17 by Vincent Ladeuil
New remote branch test.
793
    def test_no_upload_to_remote_working_tree(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
794
        cmd = self._get_cmd_upload()
0.158.17 by Vincent Ladeuil
New remote branch test.
795
        up_url = self.get_url(self.branch_dir)
796
        # 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.
797
        # branch (which has a working tree).
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
798
        self.assertRaises(upload.CannotUploadToWorkingTree,
799
                          cmd.run, up_url, directory=self.remote_branch_url)
0.158.16 by Vincent Ladeuil
Start refactoring for remote branch tests.
800
0.158.17 by Vincent Ladeuil
New remote branch test.
801
    def test_upload_without_working_tree(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
802
        self.do_full_upload(directory=self.remote_branch_url)
0.158.17 by Vincent Ladeuil
New remote branch test.
803
        self.assertUpFileEqual('foo', 'hello')
804
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
805
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
806
class TestUploadDiverged(tests.TestCaseWithTransport,
807
                         UploadUtilsMixin):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
808
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
809
    def setUp(self):
810
        super(TestUploadDiverged, self).setUp()
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
811
        self.diverged_tree = self.make_diverged_tree_and_upload_location()
812
813
    def make_diverged_tree_and_upload_location(self):
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
814
        tree_a = self.make_branch_and_tree('tree_a')
815
        tree_a.commit('message 1', rev_id='rev1')
816
        tree_a.commit('message 2', rev_id='rev2a')
817
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
818
        uncommit.uncommit(tree_b.branch, tree=tree_b)
819
        tree_b.commit('message 2', rev_id='rev2b')
820
        # upload tree a
821
        self.do_full_upload(directory=tree_a.basedir)
822
        return tree_b
823
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
824
    def assertRevidUploaded(self, revid):
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
825
        t = self.get_transport(self.upload_dir)
826
        uploaded_revid = t.get_bytes('.bzr-upload.revid')
827
        self.assertEqual(revid, uploaded_revid)
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
828
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
829
    def test_cant_upload_diverged(self):
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
830
        self.assertRaises(upload.DivergedUploadedTree,
831
                          self.do_incremental_upload,
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
832
                          directory=self.diverged_tree.basedir)
833
        self.assertRevidUploaded('rev2a')
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
834
835
    def test_upload_diverged_with_overwrite(self):
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
836
        self.do_incremental_upload(directory=self.diverged_tree.basedir,
0.159.3 by Gary van der Merwe
Write tests for checking of diverged uploads.
837
                                   overwrite=True)
0.159.5 by Gary van der Merwe
Some small changes to the tests as per review.
838
        self.assertRevidUploaded('rev2b')