~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Martin Pool
  • Date: 2006-06-20 07:55:43 UTC
  • mfrom: (1798 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060620075543-b10f6575d4a4fa32
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
 
43
43
sample_always_signatures = ("[DEFAULT]\n"
44
 
                            "check_signatures=require\n")
 
44
                            "check_signatures=ignore\n"
 
45
                            "create_signatures=always")
45
46
 
46
47
 
47
48
sample_ignore_signatures = ("[DEFAULT]\n"
48
 
                            "check_signatures=ignore\n")
 
49
                            "check_signatures=require\n"
 
50
                            "create_signatures=never")
49
51
 
50
52
 
51
53
sample_maybe_signatures = ("[DEFAULT]\n"
52
 
                            "check_signatures=check-available\n")
 
54
                            "check_signatures=ignore\n"
 
55
                            "create_signatures=when-required")
53
56
 
54
57
 
55
58
sample_branches_text = ("[http://www.example.com]\n"
172
175
 
173
176
    def test_signatures_default(self):
174
177
        my_config = config.Config()
 
178
        self.assertFalse(my_config.signature_needed())
175
179
        self.assertEqual(config.CHECK_IF_POSSIBLE,
176
180
                         my_config.signature_checking())
 
181
        self.assertEqual(config.SIGN_WHEN_REQUIRED,
 
182
                         my_config.signing_policy())
177
183
 
178
184
    def test_signatures_template_method(self):
179
185
        my_config = InstrumentedConfig()
248
254
            self.assertEqual(config.branches_config_filename(),
249
255
                             '/home/bogus/.bazaar/branches.conf')
250
256
 
 
257
    def test_locations_config_filename(self):
 
258
        if sys.platform == 'win32':
 
259
            self.assertEqual(config.locations_config_filename(), 
 
260
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/locations.conf')
 
261
        else:
 
262
            self.assertEqual(config.locations_config_filename(),
 
263
                             '/home/bogus/.bazaar/locations.conf')
 
264
 
251
265
class TestIniConfig(TestCase):
252
266
 
253
267
    def test_contructs(self):
326
340
        config_file = StringIO(sample_always_signatures)
327
341
        my_config = config.GlobalConfig()
328
342
        my_config._parser = my_config._get_parser(file=config_file)
329
 
        self.assertEqual(config.CHECK_ALWAYS,
 
343
        self.assertEqual(config.CHECK_NEVER,
330
344
                         my_config.signature_checking())
 
345
        self.assertEqual(config.SIGN_ALWAYS,
 
346
                         my_config.signing_policy())
331
347
        self.assertEqual(True, my_config.signature_needed())
332
348
 
333
349
    def test_signatures_if_possible(self):
334
350
        config_file = StringIO(sample_maybe_signatures)
335
351
        my_config = config.GlobalConfig()
336
352
        my_config._parser = my_config._get_parser(file=config_file)
337
 
        self.assertEqual(config.CHECK_IF_POSSIBLE,
 
353
        self.assertEqual(config.CHECK_NEVER,
338
354
                         my_config.signature_checking())
 
355
        self.assertEqual(config.SIGN_WHEN_REQUIRED,
 
356
                         my_config.signing_policy())
339
357
        self.assertEqual(False, my_config.signature_needed())
340
358
 
341
359
    def test_signatures_ignore(self):
342
360
        config_file = StringIO(sample_ignore_signatures)
343
361
        my_config = config.GlobalConfig()
344
362
        my_config._parser = my_config._get_parser(file=config_file)
345
 
        self.assertEqual(config.CHECK_NEVER,
 
363
        self.assertEqual(config.CHECK_ALWAYS,
346
364
                         my_config.signature_checking())
 
365
        self.assertEqual(config.SIGN_NEVER,
 
366
                         my_config.signing_policy())
347
367
        self.assertEqual(False, my_config.signature_needed())
348
368
 
349
369
    def _get_sample_config(self):
410
430
        # replace the class that is constructured, to check its parameters
411
431
        oldparserclass = config.ConfigObj
412
432
        config.ConfigObj = InstrumentedConfigObj
413
 
        my_config = config.LocationConfig('http://www.example.com')
414
433
        try:
 
434
            my_config = config.LocationConfig('http://www.example.com')
415
435
            parser = my_config._get_parser()
416
436
        finally:
417
437
            config.ConfigObj = oldparserclass
418
438
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
419
439
        self.assertEqual(parser._calls,
420
 
                         [('__init__', config.branches_config_filename(),
 
440
                         [('__init__', config.locations_config_filename(),
421
441
                           'utf-8')])
 
442
        os.mkdir(config.config_dir())
 
443
        f = file(config.branches_config_filename(), 'wb')
 
444
        f.write('')
 
445
        f.close()
 
446
        oldparserclass = config.ConfigObj
 
447
        config.ConfigObj = InstrumentedConfigObj
 
448
        try:
 
449
            my_config = config.LocationConfig('http://www.example.com')
 
450
            parser = my_config._get_parser()
 
451
        finally:
 
452
            config.ConfigObj = oldparserclass
422
453
 
423
454
    def test_get_global_config(self):
424
455
        my_config = config.LocationConfig('http://example.com')
495
526
    def test_signatures_not_set(self):
496
527
        self.get_location_config('http://www.example.com',
497
528
                                 global_config=sample_ignore_signatures)
498
 
        self.assertEqual(config.CHECK_NEVER,
 
529
        self.assertEqual(config.CHECK_ALWAYS,
499
530
                         self.my_config.signature_checking())
 
531
        self.assertEqual(config.SIGN_NEVER,
 
532
                         self.my_config.signing_policy())
500
533
 
501
534
    def test_signatures_never(self):
502
535
        self.get_location_config('/a/c')
609
642
        config_file = StringIO(sample_always_signatures)
610
643
        (my_config._get_location_config().
611
644
            _get_global_config()._get_parser(config_file))
612
 
        self.assertEqual(config.CHECK_ALWAYS, my_config.signature_checking())
 
645
        self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
 
646
        self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
 
647
        self.assertTrue(my_config.signature_needed())
613
648
 
614
649
    def test_gpg_signing_command(self):
615
650
        branch = FakeBranch()