/brz/remove-bazaar

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