/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/tests/test_read_bundle.py

  • Committer: Jelmer Vernooij
  • Date: 2020-05-24 00:39:50 UTC
  • mto: This revision was merged to the branch mainline in revision 7504.
  • Revision ID: jelmer@jelmer.uk-20200524003950-bbc545r76vc5yajg
Add github action.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2011 Canonical Ltd
 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Test read_bundle works properly across various transports."""
 
18
 
 
19
from io import BytesIO
 
20
 
 
21
import breezy.mergeable
 
22
from ..bzr.bundle.serializer import write_bundle
 
23
import breezy.bzr.bzrdir
 
24
from .. import errors
 
25
from .. import tests
 
26
from .test_transport import TestTransportImplementation
 
27
from .per_transport import transport_test_permutations
 
28
import breezy.transport
 
29
import breezy.urlutils
 
30
from .scenarios import load_tests_apply_scenarios
 
31
 
 
32
 
 
33
load_tests = load_tests_apply_scenarios
 
34
 
 
35
 
 
36
def create_bundle_file(test_case):
 
37
    test_case.build_tree(['tree/', 'tree/a', 'tree/subdir/'])
 
38
 
 
39
    format = breezy.bzr.bzrdir.BzrDirFormat.get_default_format()
 
40
 
 
41
    bzrdir = format.initialize('tree')
 
42
    repo = bzrdir.create_repository()
 
43
    branch = repo.controldir.create_branch()
 
44
    wt = branch.controldir.create_workingtree()
 
45
 
 
46
    wt.add(['a', 'subdir/'])
 
47
    wt.commit('new project', rev_id=b'commit-1')
 
48
 
 
49
    out = BytesIO()
 
50
    write_bundle(wt.branch.repository, wt.get_parent_ids()[0], b'null:', out)
 
51
    out.seek(0)
 
52
    return out, wt
 
53
 
 
54
 
 
55
class TestReadMergeableBundleFromURL(TestTransportImplementation):
 
56
    """Test that read_bundle works properly across multiple transports"""
 
57
 
 
58
    scenarios = transport_test_permutations()
 
59
 
 
60
    def setUp(self):
 
61
        super(TestReadMergeableBundleFromURL, self).setUp()
 
62
        self.bundle_name = 'test_bundle'
 
63
        # read_mergeable_from_url will invoke get_transport which may *not*
 
64
        # respect self._transport (i.e. returns a transport that is different
 
65
        # from the one we want to test, so we must inject a correct transport
 
66
        # into possible_transports first).
 
67
        self.possible_transports = [self.get_transport(self.bundle_name)]
 
68
        self.overrideEnv('BRZ_NO_SMART_VFS', None)
 
69
        self.create_test_bundle()
 
70
 
 
71
    def read_mergeable_from_url(self, url):
 
72
        return breezy.mergeable.read_mergeable_from_url(
 
73
            url, possible_transports=self.possible_transports)
 
74
 
 
75
    def get_url(self, relpath=''):
 
76
        return breezy.urlutils.join(self._server.get_url(), relpath)
 
77
 
 
78
    def create_test_bundle(self):
 
79
        out, wt = create_bundle_file(self)
 
80
        if self.get_transport().is_readonly():
 
81
            self.build_tree_contents([(self.bundle_name, out.getvalue())])
 
82
        else:
 
83
            self.get_transport().put_file(self.bundle_name, out)
 
84
            self.log('Put to: %s', self.get_url(self.bundle_name))
 
85
        return wt
 
86
 
 
87
    def test_read_mergeable_from_url(self):
 
88
        info = self.read_mergeable_from_url(
 
89
            str(self.get_url(self.bundle_name)))
 
90
        revision = info.real_revisions[-1]
 
91
        self.assertEqual(b'commit-1', revision.revision_id)
 
92
 
 
93
    def test_read_fail(self):
 
94
        # Trying to read from a directory, or non-bundle file
 
95
        # should fail with NotABundle
 
96
        self.assertRaises(errors.NotABundle,
 
97
                          self.read_mergeable_from_url, self.get_url('tree'))
 
98
        self.assertRaises(errors.NotABundle,
 
99
                          self.read_mergeable_from_url, self.get_url('tree/a'))
 
100
 
 
101
    def test_read_mergeable_respects_possible_transports(self):
 
102
        if not isinstance(self.get_transport(self.bundle_name),
 
103
                          breezy.transport.ConnectedTransport):
 
104
            # There is no point testing transport reuse for not connected
 
105
            # transports (the test will fail even).
 
106
            raise tests.TestSkipped(
 
107
                'Need a ConnectedTransport to test transport reuse')
 
108
        url = str(self.get_url(self.bundle_name))
 
109
        self.read_mergeable_from_url(url)
 
110
        self.assertEqual(1, len(self.possible_transports))