~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

Update to bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
147
147
            self.base = "http://example.com/branches/demo"
148
148
        else:
149
149
            self.base = base
150
 
        self.control_files = FakeControlFiles(user_id=user_id)
 
150
        self._transport = self.control_files = \
 
151
            FakeControlFilesAndTransport(user_id=user_id)
151
152
 
152
153
    def lock_write(self):
153
154
        pass
156
157
        pass
157
158
 
158
159
 
159
 
class FakeControlFiles(object):
 
160
class FakeControlFilesAndTransport(object):
160
161
 
161
162
    def __init__(self, user_id=None):
162
163
        self.files = {}
587
588
        my_config = self._get_sample_config()
588
589
        self.assertEqual('help', my_config.get_alias('h'))
589
590
 
 
591
    def test_get_aliases(self):
 
592
        my_config = self._get_sample_config()
 
593
        aliases = my_config.get_aliases()
 
594
        self.assertEqual(2, len(aliases))
 
595
        sorted_keys = sorted(aliases)
 
596
        self.assertEqual('help', aliases[sorted_keys[0]])
 
597
        self.assertEqual(sample_long_alias, aliases[sorted_keys[1]])
 
598
 
590
599
    def test_get_no_alias(self):
591
600
        my_config = self._get_sample_config()
592
601
        self.assertEqual(None, my_config.get_alias('foo'))
596
605
        self.assertEqual(sample_long_alias, my_config.get_alias('ll'))
597
606
 
598
607
 
 
608
class TestGlobalConfigSavingOptions(tests.TestCaseInTempDir):
 
609
 
 
610
    def test_empty(self):
 
611
        my_config = config.GlobalConfig()
 
612
        self.assertEqual(0, len(my_config.get_aliases()))
 
613
 
 
614
    def test_set_alias(self):
 
615
        my_config = config.GlobalConfig()
 
616
        alias_value = 'commit --strict'
 
617
        my_config.set_alias('commit', alias_value)
 
618
        new_config = config.GlobalConfig()
 
619
        self.assertEqual(alias_value, new_config.get_alias('commit'))
 
620
 
 
621
    def test_remove_alias(self):
 
622
        my_config = config.GlobalConfig()
 
623
        my_config.set_alias('commit', 'commit --strict')
 
624
        # Now remove the alias again.
 
625
        my_config.unset_alias('commit')
 
626
        new_config = config.GlobalConfig()
 
627
        self.assertIs(None, new_config.get_alias('commit'))
 
628
 
 
629
 
599
630
class TestLocationConfig(tests.TestCaseInTempDir):
600
631
 
601
632
    def test_constructs(self):
1412
1443
            'SMTP %(user)s@%(host)s:%(port)d password: ',
1413
1444
            'smtp', port=10025)
1414
1445
 
 
1446
    def test_ssh_password_emits_warning(self):
 
1447
        conf = config.AuthenticationConfig(_file=StringIO(
 
1448
                """
 
1449
[ssh with password]
 
1450
scheme=ssh
 
1451
host=bar.org
 
1452
user=jim
 
1453
password=jimpass
 
1454
"""))
 
1455
        entered_password = 'typed-by-hand'
 
1456
        stdout = tests.StringIOWrapper()
 
1457
        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
 
1458
                                            stdout=stdout)
 
1459
 
 
1460
        # Since the password defined in the authentication config is ignored,
 
1461
        # the user is prompted
 
1462
        self.assertEquals(entered_password,
 
1463
                          conf.get_password('ssh', 'bar.org', user='jim'))
 
1464
        self.assertContainsRe(
 
1465
            self._get_log(keep_log_file=True),
 
1466
            'password ignored in section \[ssh with password\]')
 
1467
 
 
1468
    def test_ssh_without_password_doesnt_emit_warning(self):
 
1469
        conf = config.AuthenticationConfig(_file=StringIO(
 
1470
                """
 
1471
[ssh with password]
 
1472
scheme=ssh
 
1473
host=bar.org
 
1474
user=jim
 
1475
"""))
 
1476
        entered_password = 'typed-by-hand'
 
1477
        stdout = tests.StringIOWrapper()
 
1478
        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
 
1479
                                            stdout=stdout)
 
1480
 
 
1481
        # Since the password defined in the authentication config is ignored,
 
1482
        # the user is prompted
 
1483
        self.assertEquals(entered_password,
 
1484
                          conf.get_password('ssh', 'bar.org', user='jim'))
 
1485
        # No warning shoud be emitted since there is no password. We are only
 
1486
        # providing "user".
 
1487
        self.assertNotContainsRe(
 
1488
            self._get_log(keep_log_file=True),
 
1489
            'password ignored in section \[ssh with password\]')
 
1490
 
1415
1491
 
1416
1492
# FIXME: Once we have a way to declare authentication to all test servers, we
1417
1493
# can implement generic tests.