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