587
588
my_config = self._get_sample_config()
588
589
self.assertEqual('help', my_config.get_alias('h'))
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]])
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'))
608
class TestGlobalConfigSavingOptions(tests.TestCaseInTempDir):
610
def test_empty(self):
611
my_config = config.GlobalConfig()
612
self.assertEqual(0, len(my_config.get_aliases()))
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'))
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'))
599
630
class TestLocationConfig(tests.TestCaseInTempDir):
601
632
def test_constructs(self):
1412
1443
'SMTP %(user)s@%(host)s:%(port)d password: ',
1413
1444
'smtp', port=10025)
1446
def test_ssh_password_emits_warning(self):
1447
conf = config.AuthenticationConfig(_file=StringIO(
1455
entered_password = 'typed-by-hand'
1456
stdout = tests.StringIOWrapper()
1457
ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
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\]')
1468
def test_ssh_without_password_doesnt_emit_warning(self):
1469
conf = config.AuthenticationConfig(_file=StringIO(
1476
entered_password = 'typed-by-hand'
1477
stdout = tests.StringIOWrapper()
1478
ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
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
1487
self.assertNotContainsRe(
1488
self._get_log(keep_log_file=True),
1489
'password ignored in section \[ssh with password\]')
1416
1492
# FIXME: Once we have a way to declare authentication to all test servers, we
1417
1493
# can implement generic tests.