/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2008-2012, 2016 Canonical Ltd
3251.3.1 by Aaron Bentley
Add support for directory services
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3251.3.1 by Aaron Bentley
Add support for directory services
16
17
"""Test directory service implementation"""
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
20
    transport,
4789.13.1 by John Arbash Meinel
Change the DirectoryService tests a little bit.
21
    urlutils,
22
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
23
from ..directory_service import (
6319.2.1 by Jelmer Vernooij
Allow registering custom location aliases.
24
    AliasDirectory,
25
    DirectoryServiceRegistry,
6734.1.15 by Jelmer Vernooij
Move errors for breezy.directory_service.
26
    InvalidLocationAlias,
27
    UnsetLocationAlias,
6319.2.1 by Jelmer Vernooij
Allow registering custom location aliases.
28
    directories,
29
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
30
from . import TestCase, TestCaseWithTransport
3625.1.2 by Michael Hudson
import urlutils and write urlutils.join rather than join
31
3251.3.1 by Aaron Bentley
Add support for directory services
32
33
class FooService(object):
34
    """A directory service that maps the name to a FILE url"""
35
5278.1.2 by Martin Pool
Don't say 'Linux' except when specifically talking about the kernel
36
    # eg 'file:///foo' on Unix, or 'file:///C:/foo' on Windows
4789.13.1 by John Arbash Meinel
Change the DirectoryService tests a little bit.
37
    base = urlutils.local_path_to_url('/foo')
38
3251.3.1 by Aaron Bentley
Add support for directory services
39
    def look_up(self, name, url):
4789.13.1 by John Arbash Meinel
Change the DirectoryService tests a little bit.
40
        return self.base + name
3251.3.1 by Aaron Bentley
Add support for directory services
41
42
43
class TestDirectoryLookup(TestCase):
44
45
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
46
        super(TestDirectoryLookup, self).setUp()
3251.3.1 by Aaron Bentley
Add support for directory services
47
        self.registry = DirectoryServiceRegistry()
48
        self.registry.register('foo:', FooService, 'Map foo URLs to http urls')
49
50
    def test_get_directory_service(self):
51
        directory, suffix = self.registry.get_prefix('foo:bar')
52
        self.assertIs(FooService, directory)
53
        self.assertEqual('bar', suffix)
54
55
    def test_dereference(self):
4789.13.1 by John Arbash Meinel
Change the DirectoryService tests a little bit.
56
        self.assertEqual(FooService.base + 'bar',
3251.3.1 by Aaron Bentley
Add support for directory services
57
                         self.registry.dereference('foo:bar'))
58
        self.assertEqual('baz:qux', self.registry.dereference('baz:qux'))
59
60
    def test_get_transport(self):
61
        directories.register('foo:', FooService, 'Map foo URLs to http urls')
4985.2.1 by Vincent Ladeuil
Deploy addAttrCleanup on the whole test suite.
62
        self.addCleanup(directories.remove, 'foo:')
4789.13.1 by John Arbash Meinel
Change the DirectoryService tests a little bit.
63
        self.assertEqual(FooService.base + 'bar/',
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
64
                         transport.get_transport('foo:bar').base)
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
65
66
67
class TestAliasDirectory(TestCaseWithTransport):
68
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
69
    def setUp(self):
70
        super(TestAliasDirectory, self).setUp()
71
        self.branch = self.make_branch('.')
72
73
    def assertAliasFromBranch(self, setter, value, alias):
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
74
        setter(value)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
75
        self.assertEqual(value, directories.dereference(alias))
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
76
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
77
    def test_lookup_parent(self):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
78
        self.assertAliasFromBranch(self.branch.set_parent, 'http://a',
79
                                  ':parent')
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
80
81
    def test_lookup_submit(self):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
82
        self.assertAliasFromBranch(self.branch.set_submit_branch, 'http://b',
83
                                   ':submit')
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
84
85
    def test_lookup_public(self):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
86
        self.assertAliasFromBranch(self.branch.set_public_branch, 'http://c',
87
                                   ':public')
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
88
89
    def test_lookup_bound(self):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
90
        self.assertAliasFromBranch(self.branch.set_bound_location, 'http://d',
91
                                   ':bound')
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
92
3512.2.2 by Aaron Bentley
Add :push and :this
93
    def test_lookup_push(self):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
94
        self.assertAliasFromBranch(self.branch.set_push_location, 'http://e',
95
                                   ':push')
3512.2.2 by Aaron Bentley
Add :push and :this
96
97
    def test_lookup_this(self):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
98
        self.assertEqual(self.branch.base, directories.dereference(':this'))
3512.2.2 by Aaron Bentley
Add :push and :this
99
3625.1.1 by Michael Hudson
Allow appending path segments to the :<name> style aliases.
100
    def test_extra_path(self):
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
101
        self.assertEqual(urlutils.join(self.branch.base, 'arg'),
3625.1.2 by Michael Hudson
import urlutils and write urlutils.join rather than join
102
                         directories.dereference(':this/arg'))
3625.1.1 by Michael Hudson
Allow appending path segments to the :<name> style aliases.
103
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
104
    def test_lookup_badname(self):
6734.1.15 by Jelmer Vernooij
Move errors for breezy.directory_service.
105
        e = self.assertRaises(InvalidLocationAlias,
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
106
                              directories.dereference, ':booga')
107
        self.assertEqual('":booga" is not a valid location alias.',
108
                         str(e))
109
110
    def test_lookup_badvalue(self):
6734.1.15 by Jelmer Vernooij
Move errors for breezy.directory_service.
111
        e = self.assertRaises(UnsetLocationAlias,
3512.2.1 by Aaron Bentley
Add support for branch-associated locations
112
                              directories.dereference, ':parent')
113
        self.assertEqual('No parent location assigned.', str(e))
6319.2.1 by Jelmer Vernooij
Allow registering custom location aliases.
114
115
    def test_register_location_alias(self):
116
        self.addCleanup(AliasDirectory.branch_aliases.remove, "booga")
117
        AliasDirectory.branch_aliases.register("booga",
118
            lambda b: "UHH?", help="Nobody knows")
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
119
        self.assertEqual("UHH?", directories.dereference(":booga"))
6511.3.2 by Jelmer Vernooij
Tests.
120
121
122
class TestColocatedDirectory(TestCaseWithTransport):
123
124
    def test_lookup_non_default(self):
125
        default = self.make_branch('.')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
126
        non_default = default.controldir.create_branch(name='nondefault')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
127
        self.assertEqual(non_default.base, directories.dereference('co:nondefault'))
6511.3.2 by Jelmer Vernooij
Tests.
128
129
    def test_lookup_default(self):
130
        default = self.make_branch('.')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
131
        non_default = default.controldir.create_branch(name='nondefault')
132
        self.assertEqual(urlutils.join_segment_parameters(default.controldir.user_url,
6511.3.2 by Jelmer Vernooij
Tests.
133
            {"branch": ""}), directories.dereference('co:'))
134
135
    def test_no_such_branch(self):
136
        # No error is raised in this case, that is up to the code that actually
137
        # opens the branch.
138
        default = self.make_branch('.')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
139
        self.assertEqual(urlutils.join_segment_parameters(default.controldir.user_url,
6511.3.2 by Jelmer Vernooij
Tests.
140
            {"branch": "foo"}), directories.dereference('co:foo'))