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