/brz/remove-bazaar

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