~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_directory_service.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
    transport,
22
22
    urlutils,
23
23
    )
24
 
from bzrlib.directory_service import DirectoryServiceRegistry, directories
 
24
from bzrlib.directory_service import (
 
25
    AliasDirectory,
 
26
    DirectoryServiceRegistry,
 
27
    directories,
 
28
    )
25
29
from bzrlib.tests import TestCase, TestCaseWithTransport
26
30
 
27
31
 
38
42
class TestDirectoryLookup(TestCase):
39
43
 
40
44
    def setUp(self):
41
 
        TestCase.setUp(self)
 
45
        super(TestDirectoryLookup, self).setUp()
42
46
        self.registry = DirectoryServiceRegistry()
43
47
        self.registry.register('foo:', FooService, 'Map foo URLs to http urls')
44
48
 
61
65
 
62
66
class TestAliasDirectory(TestCaseWithTransport):
63
67
 
 
68
    def setUp(self):
 
69
        super(TestAliasDirectory, self).setUp()
 
70
        self.branch = self.make_branch('.')
 
71
 
 
72
    def assertAliasFromBranch(self, setter, value, alias):
 
73
        setter(value)
 
74
        self.assertEqual(value, directories.dereference(alias))
 
75
 
64
76
    def test_lookup_parent(self):
65
 
        branch = self.make_branch('.')
66
 
        branch.set_parent('http://a')
67
 
        self.assertEqual('http://a', directories.dereference(':parent'))
 
77
        self.assertAliasFromBranch(self.branch.set_parent, 'http://a',
 
78
                                  ':parent')
68
79
 
69
80
    def test_lookup_submit(self):
70
 
        branch = self.make_branch('.')
71
 
        branch.set_submit_branch('http://b')
72
 
        self.assertEqual('http://b', directories.dereference(':submit'))
 
81
        self.assertAliasFromBranch(self.branch.set_submit_branch, 'http://b',
 
82
                                   ':submit')
73
83
 
74
84
    def test_lookup_public(self):
75
 
        branch = self.make_branch('.')
76
 
        branch.set_public_branch('http://c')
77
 
        self.assertEqual('http://c', directories.dereference(':public'))
 
85
        self.assertAliasFromBranch(self.branch.set_public_branch, 'http://c',
 
86
                                   ':public')
78
87
 
79
88
    def test_lookup_bound(self):
80
 
        branch = self.make_branch('.')
81
 
        branch.set_bound_location('http://d')
82
 
        self.assertEqual('http://d', directories.dereference(':bound'))
 
89
        self.assertAliasFromBranch(self.branch.set_bound_location, 'http://d',
 
90
                                   ':bound')
83
91
 
84
92
    def test_lookup_push(self):
85
 
        branch = self.make_branch('.')
86
 
        branch.set_push_location('http://e')
87
 
        self.assertEqual('http://e', directories.dereference(':push'))
 
93
        self.assertAliasFromBranch(self.branch.set_push_location, 'http://e',
 
94
                                   ':push')
88
95
 
89
96
    def test_lookup_this(self):
90
 
        branch = self.make_branch('.')
91
 
        self.assertEqual(branch.base, directories.dereference(':this'))
 
97
        self.assertEqual(self.branch.base, directories.dereference(':this'))
92
98
 
93
99
    def test_extra_path(self):
94
 
        branch = self.make_branch('.')
95
 
        self.assertEqual(urlutils.join(branch.base, 'arg'),
 
100
        self.assertEqual(urlutils.join(self.branch.base, 'arg'),
96
101
                         directories.dereference(':this/arg'))
97
102
 
98
103
    def test_lookup_badname(self):
99
 
        branch = self.make_branch('.')
100
104
        e = self.assertRaises(errors.InvalidLocationAlias,
101
105
                              directories.dereference, ':booga')
102
106
        self.assertEqual('":booga" is not a valid location alias.',
103
107
                         str(e))
104
108
 
105
109
    def test_lookup_badvalue(self):
106
 
        branch = self.make_branch('.')
107
110
        e = self.assertRaises(errors.UnsetLocationAlias,
108
111
                              directories.dereference, ':parent')
109
112
        self.assertEqual('No parent location assigned.', str(e))
 
113
 
 
114
    def test_register_location_alias(self):
 
115
        self.addCleanup(AliasDirectory.branch_aliases.remove, "booga")
 
116
        AliasDirectory.branch_aliases.register("booga",
 
117
            lambda b: "UHH?", help="Nobody knows")
 
118
        self.assertEqual("UHH?", directories.dereference(":booga"))
 
119
 
 
120
 
 
121
class TestColocatedDirectory(TestCaseWithTransport):
 
122
 
 
123
    def test_lookup_non_default(self):
 
124
        default = self.make_branch('.')
 
125
        non_default = default.bzrdir.create_branch(name='nondefault')
 
126
        self.assertEqual(non_default.base, directories.dereference('co:nondefault'))
 
127
 
 
128
    def test_lookup_default(self):
 
129
        default = self.make_branch('.')
 
130
        non_default = default.bzrdir.create_branch(name='nondefault')
 
131
        self.assertEqual(urlutils.join_segment_parameters(default.bzrdir.user_url,
 
132
            {"branch": ""}), directories.dereference('co:'))
 
133
 
 
134
    def test_no_such_branch(self):
 
135
        # No error is raised in this case, that is up to the code that actually
 
136
        # opens the branch.
 
137
        default = self.make_branch('.')
 
138
        self.assertEqual(urlutils.join_segment_parameters(default.bzrdir.user_url,
 
139
            {"branch": "foo"}), directories.dereference('co:foo'))