def test_decrypt__when_not_decrypted__decrypt_secrets(self): config = UltraConfig([], decrypter=self.encrypter) config['blah'] = 'something' config['SECRETS'] = ['blah'] config.decrypted = False config.decrypt() self.assertEqual('blah', config['blah'])
def test__when_config_key_set__no_warning(self): config = UltraConfig([]) config['SUPER_SECRET'] = 'asv' config['SECRETS'] = ['SUPER_SECRET'] with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') decrypt(config, lambda value: 'blah') self.assertEqual(len(w), 0) self.assertEqual(config['SUPER_SECRET'], 'blah')
def test__when_secrets_config_key_set__use_secrets_config_key(self): config = UltraConfig([]) config['SUPER_SECRET'] = 'asv' config['MY_SECRETS'] = ['SUPER_SECRET'] config['SECRETS'] = ['OTHER_SECRET'] config['OTHER_SECRET'] = 'not-secret' decrypt(config, lambda value: 'blah', secrets_config_key='MY_SECRETS') self.assertEqual(config['SUPER_SECRET'], 'blah') self.assertEqual(config['OTHER_SECRET'], 'not-secret')
def test_required_items__when_found(self): config = UltraConfig([], required=['required']) config['REQUIRED'] = True resp = config.validate() self.assertIsNone(resp)
def test_required_items__when_missing__raises_ValueError(self): config = UltraConfig([], required=['required']) self.assertRaises(ValueError, config.validate)
def test_get_encrypted__when_not_encrypted__return(self): config = UltraConfig([], decrypter=self.encrypter) config.decrypted = True config['blah'] = 'something' resp = config.get_encrypted('blah') self.assertEqual('something', resp)
def test_set_encrypted__ensure_secrets_config_key_extended(self): config = UltraConfig([], encrypter=self.encrypter) config.set_encrypted('blah', 'blah') self.assertListEqual(['blah'], config[config.secrets_config_key])
def test_set_encrypted__when_not_encrypted__set_raw_value(self): config = UltraConfig([], encrypter=self.encrypter) config.decrypted = True config.set_encrypted('blah', 'something') self.assertEqual('something', config['blah'])
def test_set_encrypted__when_encrypted__encrypt_and_set(self): config = UltraConfig([], encrypter=self.encrypter) config.set_encrypted('blah', 'something') self.assertEqual('blah', config['blah'])
def test_decrypt__when_already_decrypted__raise_value_error(self): config = UltraConfig([]) config.decrypted = True self.assertRaises(ValueError, config.decrypt)
def test__when_secrets_list_set__use_secrets_list(self): config = UltraConfig([]) config['SUPER_SECRET'] = 'asv' decrypt(config, lambda value: 'blah', secrets_config_key=None, secrets_list=['SUPER_SECRET']) self.assertEqual(config['SUPER_SECRET'], 'blah')
def test__when_config_key_none__no_warning(self): config = UltraConfig([]) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') decrypt(config, lambda value: 'blah', secrets_config_key=None) self.assertEqual(len(w), 0)
def test_set_encrypted__when_key_already_in_secrets__no_duplicates(self): config = UltraConfig([], encrypter=self.encrypter) config[config.secrets_config_key] = ['blah'] config.set_encrypted('blah', 'blah') self.assertListEqual(['blah'], config[config.secrets_config_key])
def test_load(self): config = UltraConfig([[lambda: dict(x=1, y=2)], [lambda: dict(x=3)]]) config.load() self.assertEqual(config['x'], 3) self.assertEqual(config['y'], 2)
def test_encrypt__when_already_encrypted__raise_value_error(self): config = UltraConfig([]) config.decrypted = False self.assertRaises(ValueError, config.encrypt)
def test_ensure_warning_raised_when_secrets_key_empty(self): config = UltraConfig([]) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') decrypt(config, lambda value: 'blah') self.assertEqual(len(w), 1)