~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_controldir_colo/test_supported.py

  • Committer: Patch Queue Manager
  • Date: 2016-01-31 13:36:59 UTC
  • mfrom: (6613.1.5 1538480-match-hostname)
  • Revision ID: pqm@pqm.ubuntu.com-20160131133659-ouy92ee2wlv9xz8m
(vila) Use ssl.match_hostname instead of our own. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for bzr directories that support colocated branches."""
18
18
 
19
 
import bzrlib.branch
20
 
from bzrlib import errors
 
19
from bzrlib.branch import Branch
 
20
from bzrlib import (
 
21
    errors,
 
22
    tests,
 
23
    urlutils,
 
24
    )
21
25
from bzrlib.tests import (
22
 
    TestNotApplicable,
23
 
    )
24
 
from bzrlib.transport import (
25
 
    get_transport,
26
 
    )
27
 
 
28
 
from bzrlib.tests.per_controldir_colo import (
29
 
    TestCaseWithControlDir,
30
 
    )
31
 
 
32
 
 
33
 
class TestColocatedBranchSupport(TestCaseWithControlDir):
 
26
    per_controldir,
 
27
    )
 
28
from bzrlib.tests.features import (
 
29
    UnicodeFilenameFeature,
 
30
    )
 
31
 
 
32
 
 
33
class TestColocatedBranchSupport(per_controldir.TestCaseWithControlDir):
34
34
 
35
35
    def test_destroy_colocated_branch(self):
36
36
        branch = self.make_branch('branch')
37
37
        bzrdir = branch.bzrdir
38
38
        colo_branch = bzrdir.create_branch('colo')
39
 
        bzrdir.destroy_branch("colo")
40
 
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch, 
 
39
        try:
 
40
            bzrdir.destroy_branch("colo")
 
41
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
 
42
            raise tests.TestNotApplicable('Format does not support destroying branch')
 
43
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch,
41
44
                          "colo")
42
45
 
43
46
    def test_create_colo_branch(self):
46
49
            # unsupported formats are not loopback testable
47
50
            # because the default open will not open them and
48
51
            # they may not be initializable.
49
 
            raise TestNotApplicable('Control dir format not supported')
50
 
        t = get_transport(self.get_url())
 
52
            raise tests.TestNotApplicable('Control dir format not supported')
 
53
        t = self.get_transport()
51
54
        try:
52
55
            made_control = self.bzrdir_format.initialize(t.base)
53
56
        except errors.UninitializableFormat:
54
 
            raise TestNotApplicable('Control dir does not support creating '
55
 
                'new branches.')
56
 
        made_repo = made_control.create_repository()
 
57
            raise tests.TestNotApplicable(
 
58
                'Control dir does not support creating new branches.')
 
59
        made_control.create_repository()
57
60
        made_branch = made_control.create_branch("colo")
58
 
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
59
 
        self.assertEqual(made_control, made_branch.bzrdir)
 
61
        self.assertIsInstance(made_branch, Branch)
 
62
        self.assertEquals("colo", made_branch.name)
 
63
        self.assertEqual(made_control, made_branch.bzrdir)
 
64
 
 
65
    def test_open_by_url(self):
 
66
        # a bzrdir can construct a branch and repository for itself.
 
67
        if not self.bzrdir_format.is_supported():
 
68
            # unsupported formats are not loopback testable
 
69
            # because the default open will not open them and
 
70
            # they may not be initializable.
 
71
            raise tests.TestNotApplicable('Control dir format not supported')
 
72
        t = self.get_transport()
 
73
        try:
 
74
            made_control = self.bzrdir_format.initialize(t.base)
 
75
        except errors.UninitializableFormat:
 
76
            raise tests.TestNotApplicable(
 
77
                'Control dir does not support creating new branches.')
 
78
        made_control.create_repository()
 
79
        made_branch = made_control.create_branch(name="colo")
 
80
        other_branch = made_control.create_branch(name="othercolo")
 
81
        self.assertIsInstance(made_branch, Branch)
 
82
        self.assertEqual(made_control, made_branch.bzrdir)
 
83
        self.assertNotEqual(made_branch.user_url, other_branch.user_url)
 
84
        self.assertNotEqual(made_branch.control_url, other_branch.control_url)
 
85
        re_made_branch = Branch.open(made_branch.user_url)
 
86
        self.assertEquals(re_made_branch.name, "colo")
 
87
        self.assertEqual(made_branch.control_url, re_made_branch.control_url)
 
88
        self.assertEqual(made_branch.user_url, re_made_branch.user_url)
 
89
 
 
90
    def test_sprout_into_colocated(self):
 
91
        # a bzrdir can construct a branch and repository for itself.
 
92
        if not self.bzrdir_format.is_supported():
 
93
            # unsupported formats are not loopback testable
 
94
            # because the default open will not open them and
 
95
            # they may not be initializable.
 
96
            raise tests.TestNotApplicable('Control dir format not supported')
 
97
        from_tree = self.make_branch_and_tree('from')
 
98
        revid = from_tree.commit("rev1")
 
99
        try:
 
100
            other_branch = self.make_branch("to")
 
101
        except errors.UninitializableFormat:
 
102
            raise tests.TestNotApplicable(
 
103
                'Control dir does not support creating new branches.')
 
104
        to_dir = from_tree.bzrdir.sprout(
 
105
            urlutils.join_segment_parameters(
 
106
                other_branch.bzrdir.user_url, {"branch": "target"}))
 
107
        to_branch = to_dir.open_branch(name="target")
 
108
        self.assertEquals(revid, to_branch.last_revision())
 
109
 
 
110
    def test_unicode(self):
 
111
        self.requireFeature(UnicodeFilenameFeature)
 
112
        if not self.bzrdir_format.is_supported():
 
113
            # unsupported formats are not loopback testable
 
114
            # because the default open will not open them and
 
115
            # they may not be initializable.
 
116
            raise tests.TestNotApplicable('Control dir format not supported')
 
117
        t = self.get_transport()
 
118
        try:
 
119
            made_control = self.bzrdir_format.initialize(t.base)
 
120
        except errors.UninitializableFormat:
 
121
            raise tests.TestNotApplicable(
 
122
                'Control dir does not support creating new branches.')
 
123
        made_control.create_repository()
 
124
        made_branch = made_control.create_branch(name=u"col\xe9")
 
125
        self.assertTrue(
 
126
            u"col\xe9" in [b.name for b in made_control.list_branches()])
 
127
        made_branch = Branch.open(made_branch.user_url)
 
128
        self.assertEquals(u"col\xe9", made_branch.name)
 
129
        made_control.destroy_branch(u"col\xe9")
 
130
 
 
131
    def test_get_branches(self):
 
132
        repo = self.make_repository('branch-1')
 
133
        target_branch = repo.bzrdir.create_branch(name='foo')
 
134
        self.assertEqual(['foo'], repo.bzrdir.get_branches().keys())
 
135
        self.assertEqual(target_branch.base,
 
136
                         repo.bzrdir.get_branches()['foo'].base)
 
137
 
 
138
    def test_branch_name_with_slash(self):
 
139
        repo = self.make_repository('branch-1')
 
140
        try:
 
141
            target_branch = repo.bzrdir.create_branch(name='foo/bar')
 
142
        except errors.InvalidBranchName:
 
143
            raise tests.TestNotApplicable(
 
144
                "format does not support branches with / in their name")
 
145
        self.assertEqual(['foo/bar'], repo.bzrdir.get_branches().keys())
 
146
        self.assertEqual(
 
147
            target_branch.base, repo.bzrdir.open_branch(name='foo/bar').base)
 
148
 
 
149
    def test_branch_reference(self):
 
150
        referenced = self.make_branch('referenced')
 
151
        repo = self.make_repository('repo')
 
152
        try:
 
153
            repo.bzrdir.set_branch_reference(referenced, name='foo')
 
154
        except errors.IncompatibleFormat:
 
155
            raise tests.TestNotApplicable(
 
156
                'Control dir does not support creating branch references.')
 
157
        self.assertEquals(referenced.base,
 
158
            repo.bzrdir.get_branch_reference('foo'))