/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/upload/tests/test_upload.py

  • Committer: Jelmer Vernooij
  • Date: 2017-11-13 22:52:33 UTC
  • mfrom: (6816 trunk)
  • mto: This revision was merged to the branch mainline in revision 6819.
  • Revision ID: jelmer@jelmer.uk-20171113225233-gma778z1cy8nqiig
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    features,
34
34
    per_branch,
35
35
    per_transport,
36
 
    stub_sftp,
37
36
    )
38
37
from ....transport import (
39
38
    ftp,
40
 
    sftp,
41
39
    )
42
40
from .. import (
43
41
    cmds,
48
46
    result = []
49
47
    basis = per_transport.transport_test_permutations()
50
48
    # Keep only the interesting ones for upload
 
49
    usable_classes = {ftp.FtpTransport}
 
50
    if features.paramiko.available():
 
51
        from ....transport import sftp
 
52
        usable_classes.add(sftp.SFTPTransport)
51
53
    for name, d in basis:
52
54
        t_class = d['transport_class']
53
 
        if t_class in (ftp.FtpTransport, sftp.SFTPTransport):
 
55
        if t_class in usable_classes:
54
56
            result.append((name, d))
55
57
    try:
56
58
        import breezy.plugins.local_test_server
138
140
        # that's the client that will report it anyway.
139
141
        full_path = osutils.pathjoin(base, path)
140
142
        st = os.stat(full_path)
141
 
        mode = st.st_mode & 0777
 
143
        mode = st.st_mode & 0o777
142
144
        if expected_mode == mode:
143
145
            return
144
146
        raise AssertionError(
152
154
        self.assertPathExists(osutils.pathjoin(base, path))
153
155
 
154
156
    def set_file_content(self, path, content, base=branch_dir):
155
 
        f = file(osutils.pathjoin(base, path), 'wb')
156
 
        try:
 
157
        with open(osutils.pathjoin(base, path), 'wb') as f:
157
158
            f.write(content)
158
 
        finally:
159
 
            f.close()
160
159
 
161
160
    def add_file(self, path, content, base=branch_dir):
162
161
        self.set_file_content(path, content, base)
270
269
        self.do_upload()
271
270
 
272
271
        self.assertUpFileEqual('baz', fpath)
273
 
        self.assertUpPathModeEqual(dir_name, 0775)
 
272
        self.assertUpPathModeEqual(dir_name, 0o775)
274
273
 
275
274
    def test_create_file_in_dir(self):
276
275
        self._test_create_file_in_dir('dir', 'goodbye')
412
411
    def _test_make_file_executable(self, file_name):
413
412
        self.make_branch_and_working_tree()
414
413
        self.add_file(file_name, 'foo')
415
 
        self.chmod_file(file_name, 0664)
 
414
        self.chmod_file(file_name, 0o664)
416
415
        self.do_full_upload()
417
 
        self.chmod_file(file_name, 0755)
 
416
        self.chmod_file(file_name, 0o755)
418
417
 
419
 
        self.assertUpPathModeEqual(file_name, 0664)
 
418
        self.assertUpPathModeEqual(file_name, 0o664)
420
419
 
421
420
        self.do_upload()
422
421
 
423
 
        self.assertUpPathModeEqual(file_name, 0775)
 
422
        self.assertUpPathModeEqual(file_name, 0o775)
424
423
 
425
424
    def test_make_file_executable(self):
426
425
        self._test_make_file_executable('hello')
643
642
        self.do_full_upload()
644
643
 
645
644
        self.assertUpFileEqual('baz', 'dir/goodbye')
646
 
        self.assertUpPathModeEqual('dir', 0775)
 
645
        self.assertUpPathModeEqual('dir', 0o775)
647
646
 
648
647
 
649
648
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
776
775
 
777
776
    def setUp(self):
778
777
        super(TestUploadFromRemoteBranch, self).setUp()
 
778
        if self._will_escape_isolation(self.transport_server):
 
779
            # FIXME: Some policy search ends up above the user home directory
 
780
            # and are seen as attemps to escape test isolation
 
781
            raise tests.TestNotApplicable('Escaping test isolation')
779
782
        self.remote_branch_url = self.make_remote_branch_without_working_tree()
780
783
 
 
784
    @staticmethod
 
785
    def _will_escape_isolation(transport_server):
 
786
        if not features.paramiko.available():
 
787
            return False
 
788
        from ....tests import stub_sftp
 
789
        if transport_server is stub_sftp.SFTPHomeDirServer:
 
790
            return True
 
791
        return False
 
792
 
781
793
    def make_remote_branch_without_working_tree(self):
782
794
        """Creates a branch without working tree to upload from.
783
795
 
788
800
        self.add_file('hello', 'foo')
789
801
 
790
802
        remote_branch_url = self.get_url(self.remote_branch_dir)
791
 
        if self.transport_server is stub_sftp.SFTPHomeDirServer:
792
 
            # FIXME: Some policy search ends up above the user home directory
793
 
            # and are seen as attemps to escape test isolation
794
 
            raise tests.TestNotApplicable('Escaping test isolation')
795
803
        self.run_bzr(['push', remote_branch_url,
796
804
                      '--directory', self.branch_dir])
797
805
        return remote_branch_url