def test_read_without_loading(self): config = CBASConfig() expected = CBASConfig() mock_ctx = Mock() mock_ctx.ensure_object.return_value = config value = "ANY_PATH" received = config.read(mock_ctx, None, value) self.assertEqual(expected, received)
def test_load_config(self): config = CBASConfig() received = config.load_config('ANY_PATH') expected = {'nospecial': 'ANY_VALUE_ONE', 'with_hyphen': 'ANY_VALUE_TWO', 'with_many_hyphens': 'ANY_VALUE_THREE', 'with_underscore': 'ANY_VALUE_FOUR', 'with_under_scores': 'ANY_VALUE_FIVE', } self.assertEqual(expected, received)
def test_load_config(self): config = CBASConfig() received = config.load_config('ANY_PATH') expected = { 'nospecial': 'ANY_VALUE_ONE', 'with_hyphen': 'ANY_VALUE_TWO', 'with_many_hyphens': 'ANY_VALUE_THREE', 'with_underscore': 'ANY_VALUE_FOUR', 'with_under_scores': 'ANY_VALUE_FIVE', } self.assertEqual(expected, received)
def test_inject(self): config = CBASConfig() to_inject = { 'username': '******', 'auth_host': 'ANY_AUTH', 'password_provider': 'ANY_PROVIDER', # exclude jump_host to make sure it remains None } config.inject(to_inject) self.assertEqual(config.username, 'ANY_USER') self.assertEqual(config.auth_host, 'ANY_AUTH') self.assertEqual(config.password_provider, 'ANY_PROVIDER') self.assertEqual(config.jump_host, None)
def test_default_initialization(self): config = CBASConfig() self.assertEqual(config.username, 'ANY_USER') self.assertEqual(config.auth_host, None) self.assertEqual(config.password_provider, 'prompt') self.assertEqual(config.jump_host, None) self.assertEqual(config.ssh_key_file, '~/.ssh/id_rsa.pub')
def test_str_defaults(self): received = CBASConfig() expected = { 'username': '******', 'auth_host': None, 'password_provider': 'prompt', 'jump_host': None, 'ssh_key_file': '~/.ssh/id_rsa.pub' } self.assertEqual(expected, received)
def test_success_for_complete_config(self): complete_config = CBASConfig() complete_config.auth_host = 'ANY_AUTH' complete_config.jump_host = 'ANY_HOST' self.assertTrue(complete_config.is_complete)
def test_failed_for_invalid_options(self): config = CBASConfig() loaded_option = {'invalid_option': 'invalid_value'} self.assertRaises(UnexpectedConfigValues, config.validate_options, loaded_option)
def test_failed_for_incomplete_config(self): incomplete = CBASConfig() self.assertRaises(MissingConfigValues, incomplete.is_complete)
def test_success_for_valid_options(self): config = CBASConfig() loaded_option = {'username': '******'} self.assertTrue(config.validate_options, loaded_option)