~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

Merge up bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
159
159
class FakeControlFiles(object):
160
160
 
161
161
    def __init__(self, user_id=None):
162
 
        self.email = user_id
163
162
        self.files = {}
 
163
        if user_id:
 
164
            self.files['email'] = user_id
164
165
        self._transport = self
165
166
 
166
167
    def get_utf8(self, filename):
167
 
        if filename != 'email':
168
 
            raise NotImplementedError
169
 
        if self.email is not None:
170
 
            return StringIO(self.email)
171
 
        raise errors.NoSuchFile(filename)
 
168
        # from LockableFiles
 
169
        raise AssertionError("get_utf8 should no longer be used")
172
170
 
173
171
    def get(self, filename):
 
172
        # from Transport
174
173
        try:
175
174
            return StringIO(self.files[filename])
176
175
        except KeyError:
177
176
            raise errors.NoSuchFile(filename)
178
177
 
 
178
    def get_bytes(self, filename):
 
179
        # from Transport
 
180
        try:
 
181
            return self.files[filename]
 
182
        except KeyError:
 
183
            raise errors.NoSuchFile(filename)
 
184
 
179
185
    def put(self, filename, fileobj):
180
186
        self.files[filename] = fileobj.read()
181
187
 
965
971
        my_config = config.BranchConfig(branch)
966
972
        self.assertEqual("Robert Collins <robertc@example.net>",
967
973
                         my_config.username())
968
 
        branch.control_files.email = "John"
 
974
        my_config.branch.control_files.files['email'] = "John"
969
975
        my_config.set_user_option('email',
970
976
                                  "Robert Collins <robertc@example.org>")
971
977
        self.assertEqual("John", my_config.username())
972
 
        branch.control_files.email = None
 
978
        del my_config.branch.control_files.files['email']
973
979
        self.assertEqual("Robert Collins <robertc@example.org>",
974
980
                         my_config.username())
975
981
 
976
982
    def test_not_set_in_branch(self):
977
983
        my_config = self.get_branch_config(sample_config_text)
978
 
        my_config.branch.control_files.email = None
979
984
        self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
980
985
                         my_config._get_user_id())
981
 
        my_config.branch.control_files.email = "John"
 
986
        my_config.branch.control_files.files['email'] = "John"
982
987
        self.assertEqual("John", my_config._get_user_id())
983
988
 
984
989
    def test_BZR_EMAIL_OVERRIDES(self):
1190
1195
        self.assertEquals({}, conf._get_config())
1191
1196
        self._got_user_passwd(None, None, conf, 'http', 'foo.net')
1192
1197
 
1193
 
    def test_broken_config(self):
 
1198
    def test_missing_auth_section_header(self):
 
1199
        conf = config.AuthenticationConfig(_file=StringIO('foo = bar'))
 
1200
        self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')
 
1201
 
 
1202
    def test_auth_section_header_not_closed(self):
1194
1203
        conf = config.AuthenticationConfig(_file=StringIO('[DEF'))
1195
1204
        self.assertRaises(errors.ParseConfigError, conf._get_config)
1196
1205
 
 
1206
    def test_auth_value_not_boolean(self):
1197
1207
        conf = config.AuthenticationConfig(_file=StringIO(
1198
1208
                """[broken]
1199
1209
scheme=ftp
1201
1211
verify_certificates=askme # Error: Not a boolean
1202
1212
"""))
1203
1213
        self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')
 
1214
 
 
1215
    def test_auth_value_not_int(self):
1204
1216
        conf = config.AuthenticationConfig(_file=StringIO(
1205
1217
                """[broken]
1206
1218
scheme=ftp
1325
1337
        self._got_user_passwd(None, None,
1326
1338
                              conf, 'http', 'bar.org', user='georges')
1327
1339
 
 
1340
    def test_credentials_for_user_without_password(self):
 
1341
        conf = config.AuthenticationConfig(_file=StringIO(
 
1342
                """
 
1343
[without password]
 
1344
scheme=http
 
1345
host=bar.org
 
1346
user=jim
 
1347
"""))
 
1348
        # Get user but no password
 
1349
        self._got_user_passwd('jim', None,
 
1350
                              conf, 'http', 'bar.org')
 
1351
 
1328
1352
    def test_verify_certificates(self):
1329
1353
        conf = config.AuthenticationConfig(_file=StringIO(
1330
1354
                """