bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
1 |
# Copyright (C) 2005 by Canonical Ltd
|
2 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
"""Tests for finding and reading the bzr config file[s]."""
|
|
19 |
# import system imports here
|
|
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
20 |
from ConfigParser import ConfigParser |
21 |
from cStringIO import StringIO |
|
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
22 |
import os |
23 |
import sys |
|
24 |
||
25 |
#import bzrlib specific imports here
|
|
26 |
import bzrlib.config as config |
|
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
27 |
import bzrlib.errors as errors |
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
28 |
from bzrlib.selftest import TestCase, TestCaseInTempDir |
29 |
||
30 |
||
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
31 |
sample_config_text = ("[DEFAULT]\n" |
32 |
"email=Robert Collins <robertc@example.com>\n" |
|
33 |
"editor=vim\n" |
|
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
34 |
"gpg_signing_command=gnome-gpg\n" |
35 |
"user_global_option=something\n") |
|
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
36 |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
37 |
|
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
38 |
sample_always_signatures = ("[DEFAULT]\n" |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
39 |
"check_signatures=require\n") |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
40 |
|
41 |
||
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
42 |
sample_ignore_signatures = ("[DEFAULT]\n" |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
43 |
"check_signatures=ignore\n") |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
44 |
|
45 |
||
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
46 |
sample_maybe_signatures = ("[DEFAULT]\n" |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
47 |
"check_signatures=check-available\n") |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
48 |
|
49 |
||
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
50 |
sample_branches_text = ("[http://www.example.com]\n" |
51 |
"# Top level policy\n" |
|
52 |
"email=Robert Collins <robertc@example.org>\n" |
|
53 |
"[http://www.example.com/useglobal]\n" |
|
54 |
"# different project, forces global lookup\n" |
|
55 |
"recurse=false\n" |
|
56 |
"[/b/]\n" |
|
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
57 |
"check_signatures=require\n" |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
58 |
"# test trailing / matching with no children\n" |
59 |
"[/a/]\n" |
|
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
60 |
"check_signatures=check-available\n" |
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
61 |
"gpg_signing_command=false\n" |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
62 |
"user_local_option=local\n" |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
63 |
"# test trailing / matching\n" |
64 |
"[/a/*]\n" |
|
65 |
"#subdirs will match but not the parent\n" |
|
66 |
"recurse=False\n" |
|
67 |
"[/a/c]\n" |
|
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
68 |
"check_signatures=ignore\n" |
|
1472
by Robert Collins
post commit hook, first pass implementation |
69 |
"post_commit=bzrlib.selftest.testconfig.post_commit\n" |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
70 |
"#testing explicit beats globs\n") |
71 |
||
72 |
||
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
73 |
class InstrumentedConfigParser(object): |
74 |
"""A config parser look-enough-alike to record calls made to it.""" |
|
75 |
||
76 |
def __init__(self): |
|
77 |
self._calls = [] |
|
78 |
||
79 |
def read(self, filenames): |
|
80 |
self._calls.append(('read', filenames)) |
|
81 |
||
82 |
||
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
83 |
class FakeBranch(object): |
84 |
||
85 |
def __init__(self): |
|
86 |
self.base = "http://example.com/branches/demo" |
|
87 |
self.email = 'Robert Collins <robertc@example.net>\n' |
|
88 |
||
89 |
def controlfile(self, filename, mode): |
|
90 |
if filename != 'email': |
|
91 |
raise NotImplementedError |
|
92 |
if self.email is not None: |
|
93 |
return StringIO(self.email) |
|
94 |
raise errors.NoSuchFile |
|
95 |
||
96 |
||
97 |
class InstrumentedConfig(config.Config): |
|
98 |
"""An instrumented config that supplies stubs for template methods.""" |
|
99 |
||
100 |
def __init__(self): |
|
101 |
super(InstrumentedConfig, self).__init__() |
|
102 |
self._calls = [] |
|
|
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
103 |
self._signatures = config.CHECK_NEVER |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
104 |
|
105 |
def _get_user_id(self): |
|
106 |
self._calls.append('_get_user_id') |
|
107 |
return "Robert Collins <robert.collins@example.org>" |
|
108 |
||
|
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
109 |
def _get_signature_checking(self): |
110 |
self._calls.append('_get_signature_checking') |
|
111 |
return self._signatures |
|
112 |
||
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
113 |
|
114 |
class TestConfig(TestCase): |
|
115 |
||
116 |
def test_constructs(self): |
|
117 |
config.Config() |
|
118 |
||
119 |
def test_no_default_editor(self): |
|
120 |
self.assertRaises(NotImplementedError, config.Config().get_editor) |
|
121 |
||
122 |
def test_user_email(self): |
|
123 |
my_config = InstrumentedConfig() |
|
124 |
self.assertEqual('robert.collins@example.org', my_config.user_email()) |
|
125 |
self.assertEqual(['_get_user_id'], my_config._calls) |
|
126 |
||
127 |
def test_username(self): |
|
128 |
my_config = InstrumentedConfig() |
|
129 |
self.assertEqual('Robert Collins <robert.collins@example.org>', |
|
130 |
my_config.username()) |
|
131 |
self.assertEqual(['_get_user_id'], my_config._calls) |
|
|
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
132 |
|
133 |
def test_signatures_default(self): |
|
134 |
my_config = config.Config() |
|
135 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
|
136 |
my_config.signature_checking()) |
|
137 |
||
|
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
138 |
def test_signatures_template_method(self): |
139 |
my_config = InstrumentedConfig() |
|
140 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
|
141 |
self.assertEqual(['_get_signature_checking'], my_config._calls) |
|
142 |
||
143 |
def test_signatures_template_method_none(self): |
|
144 |
my_config = InstrumentedConfig() |
|
145 |
my_config._signatures = None |
|
146 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
|
147 |
my_config.signature_checking()) |
|
148 |
self.assertEqual(['_get_signature_checking'], my_config._calls) |
|
149 |
||
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
150 |
def test_gpg_signing_command_default(self): |
151 |
my_config = config.Config() |
|
152 |
self.assertEqual('gpg', my_config.gpg_signing_command()) |
|
153 |
||
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
154 |
def test_get_user_option_default(self): |
155 |
my_config = config.Config() |
|
156 |
self.assertEqual(None, my_config.get_user_option('no_option')) |
|
157 |
||
|
1472
by Robert Collins
post commit hook, first pass implementation |
158 |
def test_post_commit_default(self): |
159 |
my_config = config.Config() |
|
160 |
self.assertEqual(None, my_config.post_commit()) |
|
161 |
||
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
162 |
|
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
163 |
class TestConfigPath(TestCase): |
164 |
||
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
165 |
def setUp(self): |
166 |
super(TestConfigPath, self).setUp() |
|
167 |
self.oldenv = os.environ.get('HOME', None) |
|
168 |
os.environ['HOME'] = '/home/bogus' |
|
169 |
||
170 |
def tearDown(self): |
|
171 |
os.environ['HOME'] = self.oldenv |
|
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
172 |
super(TestConfigPath, self).tearDown() |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
173 |
|
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
174 |
def test_config_dir(self): |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
175 |
self.assertEqual(config.config_dir(), '/home/bogus/.bazaar') |
176 |
||
177 |
def test_config_filename(self): |
|
178 |
self.assertEqual(config.config_filename(), |
|
179 |
'/home/bogus/.bazaar/bazaar.conf') |
|
180 |
||
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
181 |
def test_branches_config_filename(self): |
182 |
self.assertEqual(config.branches_config_filename(), |
|
183 |
'/home/bogus/.bazaar/branches.conf') |
|
184 |
||
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
185 |
class TestIniConfig(TestCase): |
186 |
||
187 |
def test_contructs(self): |
|
188 |
my_config = config.IniBasedConfig("nothing") |
|
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
189 |
|
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
190 |
def test_from_fp(self): |
191 |
config_file = StringIO(sample_config_text) |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
192 |
my_config = config.IniBasedConfig(None) |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
193 |
self.failUnless( |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
194 |
isinstance(my_config._get_parser(file=config_file), |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
195 |
ConfigParser)) |
196 |
||
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
197 |
def test_cached(self): |
198 |
config_file = StringIO(sample_config_text) |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
199 |
my_config = config.IniBasedConfig(None) |
200 |
parser = my_config._get_parser(file=config_file) |
|
201 |
self.failUnless(my_config._get_parser() is parser) |
|
202 |
||
203 |
||
204 |
class TestGetConfig(TestCase): |
|
205 |
||
206 |
def test_constructs(self): |
|
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
207 |
my_config = config.GlobalConfig() |
208 |
||
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
209 |
def test_calls_read_filenames(self): |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
210 |
# replace the class that is constructured, to check its parameters
|
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
211 |
oldparserclass = config.ConfigParser |
212 |
config.ConfigParser = InstrumentedConfigParser |
|
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
213 |
my_config = config.GlobalConfig() |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
214 |
try: |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
215 |
parser = my_config._get_parser() |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
216 |
finally: |
217 |
config.ConfigParser = oldparserclass |
|
218 |
self.failUnless(isinstance(parser, InstrumentedConfigParser)) |
|
219 |
self.assertEqual(parser._calls, [('read', [config.config_filename()])]) |
|
220 |
||
221 |
||
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
222 |
class TestBranchConfig(TestCaseInTempDir): |
223 |
||
224 |
def test_constructs(self): |
|
225 |
branch = FakeBranch() |
|
226 |
my_config = config.BranchConfig(branch) |
|
227 |
self.assertRaises(TypeError, config.BranchConfig) |
|
228 |
||
229 |
def test_get_location_config(self): |
|
230 |
branch = FakeBranch() |
|
231 |
my_config = config.BranchConfig(branch) |
|
232 |
location_config = my_config._get_location_config() |
|
233 |
self.assertEqual(branch.base, location_config.location) |
|
234 |
self.failUnless(location_config is my_config._get_location_config()) |
|
235 |
||
236 |
||
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
237 |
class TestGlobalConfigItems(TestCase): |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
238 |
|
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
239 |
def test_user_id(self): |
240 |
config_file = StringIO(sample_config_text) |
|
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
241 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
242 |
my_config._parser = my_config._get_parser(file=config_file) |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
243 |
self.assertEqual("Robert Collins <robertc@example.com>", |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
244 |
my_config._get_user_id()) |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
245 |
|
246 |
def test_absent_user_id(self): |
|
247 |
config_file = StringIO("") |
|
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
248 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
249 |
my_config._parser = my_config._get_parser(file=config_file) |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
250 |
self.assertEqual(None, my_config._get_user_id()) |
251 |
||
252 |
def test_configured_editor(self): |
|
253 |
config_file = StringIO(sample_config_text) |
|
254 |
my_config = config.GlobalConfig() |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
255 |
my_config._parser = my_config._get_parser(file=config_file) |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
256 |
self.assertEqual("vim", my_config.get_editor()) |
257 |
||
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
258 |
def test_signatures_always(self): |
259 |
config_file = StringIO(sample_always_signatures) |
|
260 |
my_config = config.GlobalConfig() |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
261 |
my_config._parser = my_config._get_parser(file=config_file) |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
262 |
self.assertEqual(config.CHECK_ALWAYS, |
263 |
my_config.signature_checking()) |
|
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
264 |
self.assertEqual(True, my_config.signature_needed()) |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
265 |
|
266 |
def test_signatures_if_possible(self): |
|
267 |
config_file = StringIO(sample_maybe_signatures) |
|
268 |
my_config = config.GlobalConfig() |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
269 |
my_config._parser = my_config._get_parser(file=config_file) |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
270 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
271 |
my_config.signature_checking()) |
|
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
272 |
self.assertEqual(False, my_config.signature_needed()) |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
273 |
|
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
274 |
def test_signatures_ignore(self): |
275 |
config_file = StringIO(sample_ignore_signatures) |
|
276 |
my_config = config.GlobalConfig() |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
277 |
my_config._parser = my_config._get_parser(file=config_file) |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
278 |
self.assertEqual(config.CHECK_NEVER, |
279 |
my_config.signature_checking()) |
|
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
280 |
self.assertEqual(False, my_config.signature_needed()) |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
281 |
|
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
282 |
def _get_sample_config(self): |
283 |
config_file = StringIO(sample_config_text) |
|
284 |
my_config = config.GlobalConfig() |
|
285 |
my_config._parser = my_config._get_parser(file=config_file) |
|
286 |
return my_config |
|
287 |
||
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
288 |
def test_gpg_signing_command(self): |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
289 |
my_config = self._get_sample_config() |
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
290 |
self.assertEqual("gnome-gpg", my_config.gpg_signing_command()) |
291 |
self.assertEqual(False, my_config.signature_needed()) |
|
292 |
||
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
293 |
def _get_empty_config(self): |
294 |
config_file = StringIO("") |
|
295 |
my_config = config.GlobalConfig() |
|
296 |
my_config._parser = my_config._get_parser(file=config_file) |
|
297 |
return my_config |
|
298 |
||
|
1442.1.59
by Robert Collins
Add re-sign command to generate a digital signature on a single revision. |
299 |
def test_gpg_signing_command_unset(self): |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
300 |
my_config = self._get_empty_config() |
|
1442.1.59
by Robert Collins
Add re-sign command to generate a digital signature on a single revision. |
301 |
self.assertEqual("gpg", my_config.gpg_signing_command()) |
302 |
||
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
303 |
def test_get_user_option_default(self): |
304 |
my_config = self._get_empty_config() |
|
305 |
self.assertEqual(None, my_config.get_user_option('no_option')) |
|
306 |
||
307 |
def test_get_user_option_global(self): |
|
308 |
my_config = self._get_sample_config() |
|
309 |
self.assertEqual("something", |
|
310 |
my_config.get_user_option('user_global_option')) |
|
|
1472
by Robert Collins
post commit hook, first pass implementation |
311 |
|
312 |
def test_post_commit_default(self): |
|
313 |
my_config = self._get_sample_config() |
|
314 |
self.assertEqual(None, my_config.post_commit()) |
|
315 |
||
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
316 |
|
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
317 |
|
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
318 |
class TestLocationConfig(TestCase): |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
319 |
|
320 |
def test_constructs(self): |
|
321 |
my_config = config.LocationConfig('http://example.com') |
|
322 |
self.assertRaises(TypeError, config.LocationConfig) |
|
323 |
||
324 |
def test_branch_calls_read_filenames(self): |
|
325 |
# replace the class that is constructured, to check its parameters
|
|
326 |
oldparserclass = config.ConfigParser |
|
327 |
config.ConfigParser = InstrumentedConfigParser |
|
328 |
my_config = config.LocationConfig('http://www.example.com') |
|
329 |
try: |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
330 |
parser = my_config._get_parser() |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
331 |
finally: |
332 |
config.ConfigParser = oldparserclass |
|
333 |
self.failUnless(isinstance(parser, InstrumentedConfigParser)) |
|
334 |
self.assertEqual(parser._calls, [('read', [config.branches_config_filename()])]) |
|
335 |
||
336 |
def test_get_global_config(self): |
|
337 |
my_config = config.LocationConfig('http://example.com') |
|
338 |
global_config = my_config._get_global_config() |
|
339 |
self.failUnless(isinstance(global_config, config.GlobalConfig)) |
|
340 |
self.failUnless(global_config is my_config._get_global_config()) |
|
341 |
||
342 |
def test__get_section_no_match(self): |
|
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
343 |
self.get_location_config('/') |
344 |
self.assertEqual(None, self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
345 |
|
346 |
def test__get_section_exact(self): |
|
|
1442.1.9
by Robert Collins
exact section test passes |
347 |
self.get_location_config('http://www.example.com') |
348 |
self.assertEqual('http://www.example.com', |
|
349 |
self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
350 |
|
351 |
def test__get_section_suffix_does_not(self): |
|
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
352 |
self.get_location_config('http://www.example.com-com') |
353 |
self.assertEqual(None, self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
354 |
|
355 |
def test__get_section_subdir_recursive(self): |
|
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
356 |
self.get_location_config('http://www.example.com/com') |
357 |
self.assertEqual('http://www.example.com', |
|
358 |
self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
359 |
|
360 |
def test__get_section_subdir_matches(self): |
|
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
361 |
self.get_location_config('http://www.example.com/useglobal') |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
362 |
self.assertEqual('http://www.example.com/useglobal', |
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
363 |
self.my_config._get_section()) |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
364 |
|
365 |
def test__get_section_subdir_nonrecursive(self): |
|
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
366 |
self.get_location_config( |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
367 |
'http://www.example.com/useglobal/childbranch') |
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
368 |
self.assertEqual('http://www.example.com', |
369 |
self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
370 |
|
371 |
def test__get_section_subdir_trailing_slash(self): |
|
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
372 |
self.get_location_config('/b') |
373 |
self.assertEqual('/b/', self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
374 |
|
375 |
def test__get_section_subdir_child(self): |
|
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
376 |
self.get_location_config('/a/foo') |
377 |
self.assertEqual('/a/*', self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
378 |
|
379 |
def test__get_section_subdir_child_child(self): |
|
|
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
380 |
self.get_location_config('/a/foo/bar') |
381 |
self.assertEqual('/a/', self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
382 |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
383 |
def test__get_section_trailing_slash_with_children(self): |
384 |
self.get_location_config('/a/') |
|
385 |
self.assertEqual('/a/', self.my_config._get_section()) |
|
386 |
||
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
387 |
def test__get_section_explicit_over_glob(self): |
|
1442.1.10
by Robert Collins
explicit over glob test passes |
388 |
self.get_location_config('/a/c') |
389 |
self.assertEqual('/a/c', self.my_config._get_section()) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
390 |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
391 |
def get_location_config(self, location, global_config=None): |
392 |
if global_config is None: |
|
393 |
global_file = StringIO(sample_config_text) |
|
394 |
else: |
|
395 |
global_file = StringIO(global_config) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
396 |
branches_file = StringIO(sample_branches_text) |
397 |
self.my_config = config.LocationConfig(location) |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
398 |
self.my_config._get_parser(branches_file) |
399 |
self.my_config._get_global_config()._get_parser(global_file) |
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
400 |
|
401 |
def test_location_without_username(self): |
|
402 |
self.get_location_config('http://www.example.com/useglobal') |
|
403 |
self.assertEqual('Robert Collins <robertc@example.com>', |
|
404 |
self.my_config.username()) |
|
405 |
||
406 |
def test_location_not_listed(self): |
|
407 |
self.get_location_config('/home/robertc/sources') |
|
408 |
self.assertEqual('Robert Collins <robertc@example.com>', |
|
409 |
self.my_config.username()) |
|
410 |
||
|
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
411 |
def test_overriding_location(self): |
412 |
self.get_location_config('http://www.example.com/foo') |
|
413 |
self.assertEqual('Robert Collins <robertc@example.org>', |
|
414 |
self.my_config.username()) |
|
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
415 |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
416 |
def test_signatures_not_set(self): |
417 |
self.get_location_config('http://www.example.com', |
|
418 |
global_config=sample_ignore_signatures) |
|
419 |
self.assertEqual(config.CHECK_NEVER, |
|
420 |
self.my_config.signature_checking()) |
|
421 |
||
422 |
def test_signatures_never(self): |
|
423 |
self.get_location_config('/a/c') |
|
424 |
self.assertEqual(config.CHECK_NEVER, |
|
425 |
self.my_config.signature_checking()) |
|
426 |
||
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
427 |
def test_signatures_when_available(self): |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
428 |
self.get_location_config('/a/', global_config=sample_ignore_signatures) |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
429 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
430 |
self.my_config.signature_checking()) |
|
|
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
431 |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
432 |
def test_signatures_always(self): |
433 |
self.get_location_config('/b') |
|
434 |
self.assertEqual(config.CHECK_ALWAYS, |
|
435 |
self.my_config.signature_checking()) |
|
436 |
||
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
437 |
def test_gpg_signing_command(self): |
438 |
self.get_location_config('/b') |
|
439 |
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command()) |
|
440 |
||
441 |
def test_gpg_signing_command_missing(self): |
|
442 |
self.get_location_config('/a') |
|
443 |
self.assertEqual("false", self.my_config.gpg_signing_command()) |
|
444 |
||
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
445 |
def test_get_user_option_global(self): |
446 |
self.get_location_config('/a') |
|
447 |
self.assertEqual('something', |
|
448 |
self.my_config.get_user_option('user_global_option')) |
|
449 |
||
450 |
def test_get_user_option_local(self): |
|
451 |
self.get_location_config('/a') |
|
452 |
self.assertEqual('local', |
|
453 |
self.my_config.get_user_option('user_local_option')) |
|
|
1472
by Robert Collins
post commit hook, first pass implementation |
454 |
|
455 |
def test_post_commit_default(self): |
|
456 |
self.get_location_config('/a/c') |
|
457 |
self.assertEqual('bzrlib.selftest.testconfig.post_commit', |
|
458 |
self.my_config.post_commit()) |
|
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
459 |
|
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
460 |
|
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
461 |
class TestBranchConfigItems(TestCase): |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
462 |
|
463 |
def test_user_id(self): |
|
464 |
branch = FakeBranch() |
|
465 |
my_config = config.BranchConfig(branch) |
|
466 |
self.assertEqual("Robert Collins <robertc@example.net>", |
|
467 |
my_config._get_user_id()) |
|
468 |
branch.email = "John" |
|
469 |
self.assertEqual("John", my_config._get_user_id()) |
|
470 |
||
471 |
def test_not_set_in_branch(self): |
|
472 |
branch = FakeBranch() |
|
473 |
my_config = config.BranchConfig(branch) |
|
474 |
branch.email = None |
|
475 |
config_file = StringIO(sample_config_text) |
|
476 |
(my_config._get_location_config(). |
|
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
477 |
_get_global_config()._get_parser(config_file)) |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
478 |
self.assertEqual("Robert Collins <robertc@example.com>", |
479 |
my_config._get_user_id()) |
|
480 |
branch.email = "John" |
|
481 |
self.assertEqual("John", my_config._get_user_id()) |
|
482 |
||
483 |
def test_BZREMAIL_OVERRIDES(self): |
|
484 |
os.environ['BZREMAIL'] = "Robert Collins <robertc@example.org>" |
|
485 |
branch = FakeBranch() |
|
486 |
my_config = config.BranchConfig(branch) |
|
487 |
self.assertEqual("Robert Collins <robertc@example.org>", |
|
488 |
my_config.username()) |
|
489 |
||
|
1442.1.19
by Robert Collins
BranchConfigs inherit signature_checking policy from their LocationConfig. |
490 |
def test_signatures_forced(self): |
491 |
branch = FakeBranch() |
|
492 |
my_config = config.BranchConfig(branch) |
|
493 |
config_file = StringIO(sample_always_signatures) |
|
494 |
(my_config._get_location_config(). |
|
495 |
_get_global_config()._get_parser(config_file)) |
|
496 |
self.assertEqual(config.CHECK_ALWAYS, my_config.signature_checking()) |
|
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
497 |
|
498 |
def test_gpg_signing_command(self): |
|
499 |
branch = FakeBranch() |
|
500 |
my_config = config.BranchConfig(branch) |
|
501 |
config_file = StringIO(sample_config_text) |
|
502 |
(my_config._get_location_config(). |
|
503 |
_get_global_config()._get_parser(config_file)) |
|
504 |
self.assertEqual('gnome-gpg', my_config.gpg_signing_command()) |
|
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
505 |
|
506 |
def test_get_user_option_global(self): |
|
507 |
branch = FakeBranch() |
|
508 |
my_config = config.BranchConfig(branch) |
|
509 |
config_file = StringIO(sample_config_text) |
|
510 |
(my_config._get_location_config(). |
|
511 |
_get_global_config()._get_parser(config_file)) |
|
512 |
self.assertEqual('something', |
|
513 |
my_config.get_user_option('user_global_option')) |
|
|
1472
by Robert Collins
post commit hook, first pass implementation |
514 |
|
515 |
def test_post_commit_default(self): |
|
516 |
branch = FakeBranch() |
|
517 |
branch.base='/a/c' |
|
518 |
my_config = config.BranchConfig(branch) |
|
519 |
config_file = StringIO(sample_config_text) |
|
520 |
(my_config._get_location_config(). |
|
521 |
_get_global_config()._get_parser(config_file)) |
|
522 |
branch_file = StringIO(sample_branches_text) |
|
523 |
my_config._get_location_config()._get_parser(branch_file) |
|
524 |
self.assertEqual('bzrlib.selftest.testconfig.post_commit', |
|
525 |
my_config.post_commit()) |