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
 | 
|
| 
1474
by Robert Collins
 Merge from Aaron Bentley.  | 
20  | 
from bzrlib.util.configobj.configobj import ConfigObj, ConfigObjError  | 
| 
1442.1.2
by Robert Collins
 create a config module - there is enough config logic to make this worthwhile, and start testing config processing.  | 
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  | 
||
| 
1474
by Robert Collins
 Merge from Aaron Bentley.  | 
73  | 
class InstrumentedConfigObj(object):  | 
74  | 
"""A config obj look-enough-alike to record calls made to it."""  | 
|
75  | 
||
76  | 
def __init__(self, input):  | 
|
77  | 
self._calls = [('__init__', input)]  | 
|
| 
1442.1.2
by Robert Collins
 create a config module - there is enough config logic to make this worthwhile, and start testing config processing.  | 
78  | 
|
79  | 
||
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
80  | 
class FakeBranch(object):  | 
81  | 
||
82  | 
def __init__(self):  | 
|
83  | 
self.base = "http://example.com/branches/demo"  | 
|
84  | 
self.email = 'Robert Collins <robertc@example.net>\n'  | 
|
85  | 
||
86  | 
def controlfile(self, filename, mode):  | 
|
87  | 
if filename != 'email':  | 
|
88  | 
raise NotImplementedError  | 
|
89  | 
if self.email is not None:  | 
|
90  | 
return StringIO(self.email)  | 
|
91  | 
raise errors.NoSuchFile  | 
|
92  | 
||
93  | 
||
94  | 
class InstrumentedConfig(config.Config):  | 
|
95  | 
"""An instrumented config that supplies stubs for template methods."""  | 
|
96  | 
||
97  | 
def __init__(self):  | 
|
98  | 
super(InstrumentedConfig, self).__init__()  | 
|
99  | 
self._calls = []  | 
|
| 
1442.1.15
by Robert Collins
 make getting the signature checking policy a template method  | 
100  | 
self._signatures = config.CHECK_NEVER  | 
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
101  | 
|
102  | 
def _get_user_id(self):  | 
|
103  | 
self._calls.append('_get_user_id')  | 
|
104  | 
return "Robert Collins <robert.collins@example.org>"  | 
|
105  | 
||
| 
1442.1.15
by Robert Collins
 make getting the signature checking policy a template method  | 
106  | 
def _get_signature_checking(self):  | 
107  | 
self._calls.append('_get_signature_checking')  | 
|
108  | 
return self._signatures  | 
|
109  | 
||
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
110  | 
|
111  | 
class TestConfig(TestCase):  | 
|
112  | 
||
113  | 
def test_constructs(self):  | 
|
114  | 
config.Config()  | 
|
115  | 
||
116  | 
def test_no_default_editor(self):  | 
|
117  | 
self.assertRaises(NotImplementedError, config.Config().get_editor)  | 
|
118  | 
||
119  | 
def test_user_email(self):  | 
|
120  | 
my_config = InstrumentedConfig()  | 
|
121  | 
self.assertEqual('robert.collins@example.org', my_config.user_email())  | 
|
122  | 
self.assertEqual(['_get_user_id'], my_config._calls)  | 
|
123  | 
||
124  | 
def test_username(self):  | 
|
125  | 
my_config = InstrumentedConfig()  | 
|
126  | 
self.assertEqual('Robert Collins <robert.collins@example.org>',  | 
|
127  | 
my_config.username())  | 
|
128  | 
self.assertEqual(['_get_user_id'], my_config._calls)  | 
|
| 
1442.1.14
by Robert Collins
 Create a default signature checking policy of CHECK_IF_POSSIBLE  | 
129  | 
|
130  | 
def test_signatures_default(self):  | 
|
131  | 
my_config = config.Config()  | 
|
132  | 
self.assertEqual(config.CHECK_IF_POSSIBLE,  | 
|
133  | 
my_config.signature_checking())  | 
|
134  | 
||
| 
1442.1.15
by Robert Collins
 make getting the signature checking policy a template method  | 
135  | 
def test_signatures_template_method(self):  | 
136  | 
my_config = InstrumentedConfig()  | 
|
137  | 
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())  | 
|
138  | 
self.assertEqual(['_get_signature_checking'], my_config._calls)  | 
|
139  | 
||
140  | 
def test_signatures_template_method_none(self):  | 
|
141  | 
my_config = InstrumentedConfig()  | 
|
142  | 
my_config._signatures = None  | 
|
143  | 
self.assertEqual(config.CHECK_IF_POSSIBLE,  | 
|
144  | 
my_config.signature_checking())  | 
|
145  | 
self.assertEqual(['_get_signature_checking'], my_config._calls)  | 
|
146  | 
||
| 
1442.1.56
by Robert Collins
 gpg_signing_command configuration item  | 
147  | 
def test_gpg_signing_command_default(self):  | 
148  | 
my_config = config.Config()  | 
|
149  | 
self.assertEqual('gpg', my_config.gpg_signing_command())  | 
|
150  | 
||
| 
1442.1.69
by Robert Collins
 config.Config has a 'get_user_option' call that accepts an option name.  | 
151  | 
def test_get_user_option_default(self):  | 
152  | 
my_config = config.Config()  | 
|
153  | 
self.assertEqual(None, my_config.get_user_option('no_option'))  | 
|
154  | 
||
| 
1472
by Robert Collins
 post commit hook, first pass implementation  | 
155  | 
def test_post_commit_default(self):  | 
156  | 
my_config = config.Config()  | 
|
157  | 
self.assertEqual(None, my_config.post_commit())  | 
|
158  | 
||
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
159  | 
|
| 
1442.1.1
by Robert Collins
 move config_dir into bzrlib.config  | 
160  | 
class TestConfigPath(TestCase):  | 
161  | 
||
| 
1442.1.2
by Robert Collins
 create a config module - there is enough config logic to make this worthwhile, and start testing config processing.  | 
162  | 
def setUp(self):  | 
163  | 
super(TestConfigPath, self).setUp()  | 
|
164  | 
self.oldenv = os.environ.get('HOME', None)  | 
|
165  | 
os.environ['HOME'] = '/home/bogus'  | 
|
166  | 
||
167  | 
def tearDown(self):  | 
|
168  | 
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  | 
169  | 
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.  | 
170  | 
|
| 
1442.1.1
by Robert Collins
 move config_dir into bzrlib.config  | 
171  | 
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.  | 
172  | 
self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')  | 
173  | 
||
174  | 
def test_config_filename(self):  | 
|
175  | 
self.assertEqual(config.config_filename(),  | 
|
176  | 
'/home/bogus/.bazaar/bazaar.conf')  | 
|
177  | 
||
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
178  | 
def test_branches_config_filename(self):  | 
179  | 
self.assertEqual(config.branches_config_filename(),  | 
|
180  | 
'/home/bogus/.bazaar/branches.conf')  | 
|
181  | 
||
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
182  | 
class TestIniConfig(TestCase):  | 
183  | 
||
184  | 
def test_contructs(self):  | 
|
185  | 
my_config = config.IniBasedConfig("nothing")  | 
|
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
186  | 
|
| 
1442.1.2
by Robert Collins
 create a config module - there is enough config logic to make this worthwhile, and start testing config processing.  | 
187  | 
def test_from_fp(self):  | 
188  | 
config_file = StringIO(sample_config_text)  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
189  | 
my_config = config.IniBasedConfig(None)  | 
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
190  | 
self.failUnless(  | 
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
191  | 
isinstance(my_config._get_parser(file=config_file),  | 
| 
1474
by Robert Collins
 Merge from Aaron Bentley.  | 
192  | 
ConfigObj))  | 
| 
1442.1.2
by Robert Collins
 create a config module - there is enough config logic to make this worthwhile, and start testing config processing.  | 
193  | 
|
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
194  | 
def test_cached(self):  | 
195  | 
config_file = StringIO(sample_config_text)  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
196  | 
my_config = config.IniBasedConfig(None)  | 
197  | 
parser = my_config._get_parser(file=config_file)  | 
|
198  | 
self.failUnless(my_config._get_parser() is parser)  | 
|
199  | 
||
200  | 
||
201  | 
class TestGetConfig(TestCase):  | 
|
202  | 
||
203  | 
def test_constructs(self):  | 
|
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
204  | 
my_config = config.GlobalConfig()  | 
205  | 
||
| 
1442.1.2
by Robert Collins
 create a config module - there is enough config logic to make this worthwhile, and start testing config processing.  | 
206  | 
def test_calls_read_filenames(self):  | 
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
207  | 
        # replace the class that is constructured, to check its parameters
 | 
| 
1474
by Robert Collins
 Merge from Aaron Bentley.  | 
208  | 
oldparserclass = config.ConfigObj  | 
209  | 
config.ConfigObj = InstrumentedConfigObj  | 
|
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
210  | 
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.  | 
211  | 
try:  | 
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
212  | 
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.  | 
213  | 
finally:  | 
| 
1474
by Robert Collins
 Merge from Aaron Bentley.  | 
214  | 
config.ConfigObj = oldparserclass  | 
215  | 
self.failUnless(isinstance(parser, InstrumentedConfigObj))  | 
|
216  | 
self.assertEqual(parser._calls, [('__init__', config.config_filename())])  | 
|
| 
1442.1.2
by Robert Collins
 create a config module - there is enough config logic to make this worthwhile, and start testing config processing.  | 
217  | 
|
218  | 
||
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
219  | 
class TestBranchConfig(TestCaseInTempDir):  | 
220  | 
||
221  | 
def test_constructs(self):  | 
|
222  | 
branch = FakeBranch()  | 
|
223  | 
my_config = config.BranchConfig(branch)  | 
|
224  | 
self.assertRaises(TypeError, config.BranchConfig)  | 
|
225  | 
||
226  | 
def test_get_location_config(self):  | 
|
227  | 
branch = FakeBranch()  | 
|
228  | 
my_config = config.BranchConfig(branch)  | 
|
229  | 
location_config = my_config._get_location_config()  | 
|
230  | 
self.assertEqual(branch.base, location_config.location)  | 
|
231  | 
self.failUnless(location_config is my_config._get_location_config())  | 
|
232  | 
||
233  | 
||
| 
1442.1.55
by Robert Collins
 move environment preservation up to the root test case, making it available to all tests  | 
234  | 
class TestGlobalConfigItems(TestCase):  | 
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
235  | 
|
| 
1442.1.2
by Robert Collins
 create a config module - there is enough config logic to make this worthwhile, and start testing config processing.  | 
236  | 
def test_user_id(self):  | 
237  | 
config_file = StringIO(sample_config_text)  | 
|
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
238  | 
my_config = config.GlobalConfig()  | 
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
239  | 
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.  | 
240  | 
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  | 
241  | 
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.  | 
242  | 
|
243  | 
def test_absent_user_id(self):  | 
|
244  | 
config_file = StringIO("")  | 
|
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
245  | 
my_config = config.GlobalConfig()  | 
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
246  | 
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  | 
247  | 
self.assertEqual(None, my_config._get_user_id())  | 
248  | 
||
249  | 
def test_configured_editor(self):  | 
|
250  | 
config_file = StringIO(sample_config_text)  | 
|
251  | 
my_config = config.GlobalConfig()  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
252  | 
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  | 
253  | 
self.assertEqual("vim", my_config.get_editor())  | 
254  | 
||
| 
1442.1.17
by Robert Collins
 allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking  | 
255  | 
def test_signatures_always(self):  | 
256  | 
config_file = StringIO(sample_always_signatures)  | 
|
257  | 
my_config = config.GlobalConfig()  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
258  | 
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  | 
259  | 
self.assertEqual(config.CHECK_ALWAYS,  | 
260  | 
my_config.signature_checking())  | 
|
| 
1442.1.21
by Robert Collins
 create signature_needed() call for commit to trigger creating signatures  | 
261  | 
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  | 
262  | 
|
263  | 
def test_signatures_if_possible(self):  | 
|
264  | 
config_file = StringIO(sample_maybe_signatures)  | 
|
265  | 
my_config = config.GlobalConfig()  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
266  | 
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  | 
267  | 
self.assertEqual(config.CHECK_IF_POSSIBLE,  | 
268  | 
my_config.signature_checking())  | 
|
| 
1442.1.21
by Robert Collins
 create signature_needed() call for commit to trigger creating signatures  | 
269  | 
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  | 
270  | 
|
| 
1442.1.16
by Robert Collins
 allow global overriding of signature policy to never check  | 
271  | 
def test_signatures_ignore(self):  | 
272  | 
config_file = StringIO(sample_ignore_signatures)  | 
|
273  | 
my_config = config.GlobalConfig()  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
274  | 
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  | 
275  | 
self.assertEqual(config.CHECK_NEVER,  | 
276  | 
my_config.signature_checking())  | 
|
| 
1442.1.21
by Robert Collins
 create signature_needed() call for commit to trigger creating signatures  | 
277  | 
self.assertEqual(False, my_config.signature_needed())  | 
| 
1442.1.16
by Robert Collins
 allow global overriding of signature policy to never check  | 
278  | 
|
| 
1442.1.69
by Robert Collins
 config.Config has a 'get_user_option' call that accepts an option name.  | 
279  | 
def _get_sample_config(self):  | 
280  | 
config_file = StringIO(sample_config_text)  | 
|
281  | 
my_config = config.GlobalConfig()  | 
|
282  | 
my_config._parser = my_config._get_parser(file=config_file)  | 
|
283  | 
return my_config  | 
|
284  | 
||
| 
1442.1.56
by Robert Collins
 gpg_signing_command configuration item  | 
285  | 
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.  | 
286  | 
my_config = self._get_sample_config()  | 
| 
1442.1.56
by Robert Collins
 gpg_signing_command configuration item  | 
287  | 
self.assertEqual("gnome-gpg", my_config.gpg_signing_command())  | 
288  | 
self.assertEqual(False, my_config.signature_needed())  | 
|
289  | 
||
| 
1442.1.69
by Robert Collins
 config.Config has a 'get_user_option' call that accepts an option name.  | 
290  | 
def _get_empty_config(self):  | 
291  | 
config_file = StringIO("")  | 
|
292  | 
my_config = config.GlobalConfig()  | 
|
293  | 
my_config._parser = my_config._get_parser(file=config_file)  | 
|
294  | 
return my_config  | 
|
295  | 
||
| 
1442.1.59
by Robert Collins
 Add re-sign command to generate a digital signature on a single revision.  | 
296  | 
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.  | 
297  | 
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.  | 
298  | 
self.assertEqual("gpg", my_config.gpg_signing_command())  | 
299  | 
||
| 
1442.1.69
by Robert Collins
 config.Config has a 'get_user_option' call that accepts an option name.  | 
300  | 
def test_get_user_option_default(self):  | 
301  | 
my_config = self._get_empty_config()  | 
|
302  | 
self.assertEqual(None, my_config.get_user_option('no_option'))  | 
|
303  | 
||
304  | 
def test_get_user_option_global(self):  | 
|
305  | 
my_config = self._get_sample_config()  | 
|
306  | 
self.assertEqual("something",  | 
|
307  | 
my_config.get_user_option('user_global_option'))  | 
|
| 
1472
by Robert Collins
 post commit hook, first pass implementation  | 
308  | 
|
309  | 
def test_post_commit_default(self):  | 
|
310  | 
my_config = self._get_sample_config()  | 
|
311  | 
self.assertEqual(None, my_config.post_commit())  | 
|
312  | 
||
| 
1442.1.69
by Robert Collins
 config.Config has a 'get_user_option' call that accepts an option name.  | 
313  | 
|
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
314  | 
|
| 
1442.1.55
by Robert Collins
 move environment preservation up to the root test case, making it available to all tests  | 
315  | 
class TestLocationConfig(TestCase):  | 
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
316  | 
|
317  | 
def test_constructs(self):  | 
|
318  | 
my_config = config.LocationConfig('http://example.com')  | 
|
319  | 
self.assertRaises(TypeError, config.LocationConfig)  | 
|
320  | 
||
321  | 
def test_branch_calls_read_filenames(self):  | 
|
| 
1474
by Robert Collins
 Merge from Aaron Bentley.  | 
322  | 
        # This is testing the correct file names are provided.
 | 
323  | 
        # TODO: consolidate with the test for GlobalConfigs filename checks.
 | 
|
324  | 
        #
 | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
325  | 
        # replace the class that is constructured, to check its parameters
 | 
| 
1474
by Robert Collins
 Merge from Aaron Bentley.  | 
326  | 
oldparserclass = config.ConfigObj  | 
327  | 
config.ConfigObj = InstrumentedConfigObj  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
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:  | 
| 
1474
by Robert Collins
 Merge from Aaron Bentley.  | 
332  | 
config.ConfigObj = oldparserclass  | 
333  | 
self.failUnless(isinstance(parser, InstrumentedConfigObj))  | 
|
334  | 
self.assertEqual(parser._calls,  | 
|
335  | 
[('__init__', config.branches_config_filename())])  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
336  | 
|
337  | 
def test_get_global_config(self):  | 
|
338  | 
my_config = config.LocationConfig('http://example.com')  | 
|
339  | 
global_config = my_config._get_global_config()  | 
|
340  | 
self.failUnless(isinstance(global_config, config.GlobalConfig))  | 
|
341  | 
self.failUnless(global_config is my_config._get_global_config())  | 
|
342  | 
||
343  | 
def test__get_section_no_match(self):  | 
|
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
344  | 
self.get_location_config('/')  | 
345  | 
self.assertEqual(None, self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
346  | 
|
347  | 
def test__get_section_exact(self):  | 
|
| 
1442.1.9
by Robert Collins
 exact section test passes  | 
348  | 
self.get_location_config('http://www.example.com')  | 
349  | 
self.assertEqual('http://www.example.com',  | 
|
350  | 
self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
351  | 
|
352  | 
def test__get_section_suffix_does_not(self):  | 
|
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
353  | 
self.get_location_config('http://www.example.com-com')  | 
354  | 
self.assertEqual(None, self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
355  | 
|
356  | 
def test__get_section_subdir_recursive(self):  | 
|
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
357  | 
self.get_location_config('http://www.example.com/com')  | 
358  | 
self.assertEqual('http://www.example.com',  | 
|
359  | 
self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
360  | 
|
361  | 
def test__get_section_subdir_matches(self):  | 
|
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
362  | 
self.get_location_config('http://www.example.com/useglobal')  | 
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
363  | 
self.assertEqual('http://www.example.com/useglobal',  | 
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
364  | 
self.my_config._get_section())  | 
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
365  | 
|
366  | 
def test__get_section_subdir_nonrecursive(self):  | 
|
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
367  | 
self.get_location_config(  | 
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
368  | 
'http://www.example.com/useglobal/childbranch')  | 
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
369  | 
self.assertEqual('http://www.example.com',  | 
370  | 
self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
371  | 
|
372  | 
def test__get_section_subdir_trailing_slash(self):  | 
|
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
373  | 
self.get_location_config('/b')  | 
374  | 
self.assertEqual('/b/', self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
375  | 
|
376  | 
def test__get_section_subdir_child(self):  | 
|
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
377  | 
self.get_location_config('/a/foo')  | 
378  | 
self.assertEqual('/a/*', self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
379  | 
|
380  | 
def test__get_section_subdir_child_child(self):  | 
|
| 
1442.1.11
by Robert Collins
 LocationConfig lookups for non matching prefixes pass tests  | 
381  | 
self.get_location_config('/a/foo/bar')  | 
382  | 
self.assertEqual('/a/', self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
383  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
384  | 
def test__get_section_trailing_slash_with_children(self):  | 
385  | 
self.get_location_config('/a/')  | 
|
386  | 
self.assertEqual('/a/', self.my_config._get_section())  | 
|
387  | 
||
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
388  | 
def test__get_section_explicit_over_glob(self):  | 
| 
1442.1.10
by Robert Collins
 explicit over glob test passes  | 
389  | 
self.get_location_config('/a/c')  | 
390  | 
self.assertEqual('/a/c', self.my_config._get_section())  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
391  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
392  | 
def get_location_config(self, location, global_config=None):  | 
393  | 
if global_config is None:  | 
|
394  | 
global_file = StringIO(sample_config_text)  | 
|
395  | 
else:  | 
|
396  | 
global_file = StringIO(global_config)  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
397  | 
branches_file = StringIO(sample_branches_text)  | 
398  | 
self.my_config = config.LocationConfig(location)  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
399  | 
self.my_config._get_parser(branches_file)  | 
400  | 
self.my_config._get_global_config()._get_parser(global_file)  | 
|
| 
1442.1.8
by Robert Collins
 preparing some tests for LocationConfig  | 
401  | 
|
402  | 
def test_location_without_username(self):  | 
|
403  | 
self.get_location_config('http://www.example.com/useglobal')  | 
|
404  | 
self.assertEqual('Robert Collins <robertc@example.com>',  | 
|
405  | 
self.my_config.username())  | 
|
406  | 
||
407  | 
def test_location_not_listed(self):  | 
|
408  | 
self.get_location_config('/home/robertc/sources')  | 
|
409  | 
self.assertEqual('Robert Collins <robertc@example.com>',  | 
|
410  | 
self.my_config.username())  | 
|
411  | 
||
| 
1442.1.13
by Robert Collins
 branches.conf is now able to override the users email  | 
412  | 
def test_overriding_location(self):  | 
413  | 
self.get_location_config('http://www.example.com/foo')  | 
|
414  | 
self.assertEqual('Robert Collins <robertc@example.org>',  | 
|
415  | 
self.my_config.username())  | 
|
| 
1442.1.16
by Robert Collins
 allow global overriding of signature policy to never check  | 
416  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
417  | 
def test_signatures_not_set(self):  | 
418  | 
self.get_location_config('http://www.example.com',  | 
|
419  | 
global_config=sample_ignore_signatures)  | 
|
420  | 
self.assertEqual(config.CHECK_NEVER,  | 
|
421  | 
self.my_config.signature_checking())  | 
|
422  | 
||
423  | 
def test_signatures_never(self):  | 
|
424  | 
self.get_location_config('/a/c')  | 
|
425  | 
self.assertEqual(config.CHECK_NEVER,  | 
|
426  | 
self.my_config.signature_checking())  | 
|
427  | 
||
| 
1442.1.16
by Robert Collins
 allow global overriding of signature policy to never check  | 
428  | 
def test_signatures_when_available(self):  | 
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
429  | 
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  | 
430  | 
self.assertEqual(config.CHECK_IF_POSSIBLE,  | 
431  | 
self.my_config.signature_checking())  | 
|
| 
1442.1.13
by Robert Collins
 branches.conf is now able to override the users email  | 
432  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
433  | 
def test_signatures_always(self):  | 
434  | 
self.get_location_config('/b')  | 
|
435  | 
self.assertEqual(config.CHECK_ALWAYS,  | 
|
436  | 
self.my_config.signature_checking())  | 
|
437  | 
||
| 
1442.1.56
by Robert Collins
 gpg_signing_command configuration item  | 
438  | 
def test_gpg_signing_command(self):  | 
439  | 
self.get_location_config('/b')  | 
|
440  | 
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command())  | 
|
441  | 
||
442  | 
def test_gpg_signing_command_missing(self):  | 
|
443  | 
self.get_location_config('/a')  | 
|
444  | 
self.assertEqual("false", self.my_config.gpg_signing_command())  | 
|
445  | 
||
| 
1442.1.69
by Robert Collins
 config.Config has a 'get_user_option' call that accepts an option name.  | 
446  | 
def test_get_user_option_global(self):  | 
447  | 
self.get_location_config('/a')  | 
|
448  | 
self.assertEqual('something',  | 
|
449  | 
self.my_config.get_user_option('user_global_option'))  | 
|
450  | 
||
451  | 
def test_get_user_option_local(self):  | 
|
452  | 
self.get_location_config('/a')  | 
|
453  | 
self.assertEqual('local',  | 
|
454  | 
self.my_config.get_user_option('user_local_option'))  | 
|
| 
1472
by Robert Collins
 post commit hook, first pass implementation  | 
455  | 
|
456  | 
def test_post_commit_default(self):  | 
|
457  | 
self.get_location_config('/a/c')  | 
|
458  | 
self.assertEqual('bzrlib.selftest.testconfig.post_commit',  | 
|
459  | 
self.my_config.post_commit())  | 
|
| 
1442.1.69
by Robert Collins
 config.Config has a 'get_user_option' call that accepts an option name.  | 
460  | 
|
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
461  | 
|
| 
1442.1.55
by Robert Collins
 move environment preservation up to the root test case, making it available to all tests  | 
462  | 
class TestBranchConfigItems(TestCase):  | 
| 
1442.1.6
by Robert Collins
 first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs  | 
463  | 
|
464  | 
def test_user_id(self):  | 
|
465  | 
branch = FakeBranch()  | 
|
466  | 
my_config = config.BranchConfig(branch)  | 
|
467  | 
self.assertEqual("Robert Collins <robertc@example.net>",  | 
|
468  | 
my_config._get_user_id())  | 
|
469  | 
branch.email = "John"  | 
|
470  | 
self.assertEqual("John", my_config._get_user_id())  | 
|
471  | 
||
472  | 
def test_not_set_in_branch(self):  | 
|
473  | 
branch = FakeBranch()  | 
|
474  | 
my_config = config.BranchConfig(branch)  | 
|
475  | 
branch.email = None  | 
|
476  | 
config_file = StringIO(sample_config_text)  | 
|
477  | 
(my_config._get_location_config().  | 
|
| 
1442.1.18
by Robert Collins
 permit per branch location overriding of signature checking policy  | 
478  | 
_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  | 
479  | 
self.assertEqual("Robert Collins <robertc@example.com>",  | 
480  | 
my_config._get_user_id())  | 
|
481  | 
branch.email = "John"  | 
|
482  | 
self.assertEqual("John", my_config._get_user_id())  | 
|
483  | 
||
484  | 
def test_BZREMAIL_OVERRIDES(self):  | 
|
485  | 
os.environ['BZREMAIL'] = "Robert Collins <robertc@example.org>"  | 
|
486  | 
branch = FakeBranch()  | 
|
487  | 
my_config = config.BranchConfig(branch)  | 
|
488  | 
self.assertEqual("Robert Collins <robertc@example.org>",  | 
|
489  | 
my_config.username())  | 
|
490  | 
||
| 
1442.1.19
by Robert Collins
 BranchConfigs inherit signature_checking policy from their LocationConfig.  | 
491  | 
def test_signatures_forced(self):  | 
492  | 
branch = FakeBranch()  | 
|
493  | 
my_config = config.BranchConfig(branch)  | 
|
494  | 
config_file = StringIO(sample_always_signatures)  | 
|
495  | 
(my_config._get_location_config().  | 
|
496  | 
_get_global_config()._get_parser(config_file))  | 
|
497  | 
self.assertEqual(config.CHECK_ALWAYS, my_config.signature_checking())  | 
|
| 
1442.1.56
by Robert Collins
 gpg_signing_command configuration item  | 
498  | 
|
499  | 
def test_gpg_signing_command(self):  | 
|
500  | 
branch = FakeBranch()  | 
|
501  | 
my_config = config.BranchConfig(branch)  | 
|
502  | 
config_file = StringIO(sample_config_text)  | 
|
503  | 
(my_config._get_location_config().  | 
|
504  | 
_get_global_config()._get_parser(config_file))  | 
|
505  | 
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.  | 
506  | 
|
507  | 
def test_get_user_option_global(self):  | 
|
508  | 
branch = FakeBranch()  | 
|
509  | 
my_config = config.BranchConfig(branch)  | 
|
510  | 
config_file = StringIO(sample_config_text)  | 
|
511  | 
(my_config._get_location_config().  | 
|
512  | 
_get_global_config()._get_parser(config_file))  | 
|
513  | 
self.assertEqual('something',  | 
|
514  | 
my_config.get_user_option('user_global_option'))  | 
|
| 
1472
by Robert Collins
 post commit hook, first pass implementation  | 
515  | 
|
516  | 
def test_post_commit_default(self):  | 
|
517  | 
branch = FakeBranch()  | 
|
518  | 
branch.base='/a/c'  | 
|
519  | 
my_config = config.BranchConfig(branch)  | 
|
520  | 
config_file = StringIO(sample_config_text)  | 
|
521  | 
(my_config._get_location_config().  | 
|
522  | 
_get_global_config()._get_parser(config_file))  | 
|
523  | 
branch_file = StringIO(sample_branches_text)  | 
|
524  | 
my_config._get_location_config()._get_parser(branch_file)  | 
|
525  | 
self.assertEqual('bzrlib.selftest.testconfig.post_commit',  | 
|
526  | 
my_config.post_commit())  |