~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_directory_service.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 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 (
25
 
    AliasDirectory,
26
 
    DirectoryServiceRegistry,
27
 
    directories,
28
 
    )
 
24
from bzrlib.directory_service import DirectoryServiceRegistry, directories
29
25
from bzrlib.tests import TestCase, TestCaseWithTransport
30
26
 
31
27
 
42
38
class TestDirectoryLookup(TestCase):
43
39
 
44
40
    def setUp(self):
45
 
        super(TestDirectoryLookup, self).setUp()
 
41
        TestCase.setUp(self)
46
42
        self.registry = DirectoryServiceRegistry()
47
43
        self.registry.register('foo:', FooService, 'Map foo URLs to http urls')
48
44
 
65
61
 
66
62
class TestAliasDirectory(TestCaseWithTransport):
67
63
 
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
 
 
76
64
    def test_lookup_parent(self):
77
 
        self.assertAliasFromBranch(self.branch.set_parent, 'http://a',
78
 
                                  ':parent')
 
65
        branch = self.make_branch('.')
 
66
        branch.set_parent('http://a')
 
67
        self.assertEqual('http://a', directories.dereference(':parent'))
79
68
 
80
69
    def test_lookup_submit(self):
81
 
        self.assertAliasFromBranch(self.branch.set_submit_branch, 'http://b',
82
 
                                   ':submit')
 
70
        branch = self.make_branch('.')
 
71
        branch.set_submit_branch('http://b')
 
72
        self.assertEqual('http://b', directories.dereference(':submit'))
83
73
 
84
74
    def test_lookup_public(self):
85
 
        self.assertAliasFromBranch(self.branch.set_public_branch, 'http://c',
86
 
                                   ':public')
 
75
        branch = self.make_branch('.')
 
76
        branch.set_public_branch('http://c')
 
77
        self.assertEqual('http://c', directories.dereference(':public'))
87
78
 
88
79
    def test_lookup_bound(self):
89
 
        self.assertAliasFromBranch(self.branch.set_bound_location, 'http://d',
90
 
                                   ':bound')
 
80
        branch = self.make_branch('.')
 
81
        branch.set_bound_location('http://d')
 
82
        self.assertEqual('http://d', directories.dereference(':bound'))
91
83
 
92
84
    def test_lookup_push(self):
93
 
        self.assertAliasFromBranch(self.branch.set_push_location, 'http://e',
94
 
                                   ':push')
 
85
        branch = self.make_branch('.')
 
86
        branch.set_push_location('http://e')
 
87
        self.assertEqual('http://e', directories.dereference(':push'))
95
88
 
96
89
    def test_lookup_this(self):
97
 
        self.assertEqual(self.branch.base, directories.dereference(':this'))
 
90
        branch = self.make_branch('.')
 
91
        self.assertEqual(branch.base, directories.dereference(':this'))
98
92
 
99
93
    def test_extra_path(self):
100
 
        self.assertEqual(urlutils.join(self.branch.base, 'arg'),
 
94
        branch = self.make_branch('.')
 
95
        self.assertEqual(urlutils.join(branch.base, 'arg'),
101
96
                         directories.dereference(':this/arg'))
102
97
 
103
98
    def test_lookup_badname(self):
 
99
        branch = self.make_branch('.')
104
100
        e = self.assertRaises(errors.InvalidLocationAlias,
105
101
                              directories.dereference, ':booga')
106
102
        self.assertEqual('":booga" is not a valid location alias.',
107
103
                         str(e))
108
104
 
109
105
    def test_lookup_badvalue(self):
 
106
        branch = self.make_branch('.')
110
107
        e = self.assertRaises(errors.UnsetLocationAlias,
111
108
                              directories.dereference, ':parent')
112
109
        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'))