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