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'])
示例#2
0
 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'])
示例#3
0
 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')
示例#4
0
 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')
示例#5
0
 def test_required_items__when_found(self):
     config = UltraConfig([], required=['required'])
     config['REQUIRED'] = True
     resp = config.validate()
     self.assertIsNone(resp)
示例#6
0
 def test_required_items__when_missing__raises_ValueError(self):
     config = UltraConfig([], required=['required'])
     self.assertRaises(ValueError, config.validate)
 def test_required_items__when_found(self):
     config = UltraConfig([], required=['required'])
     config['REQUIRED'] = True
     resp = config.validate()
     self.assertIsNone(resp)
 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])
示例#10
0
 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'])
示例#11
0
 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'])
示例#12
0
 def test_decrypt__when_already_decrypted__raise_value_error(self):
     config = UltraConfig([])
     config.decrypted = True
     self.assertRaises(ValueError, config.decrypt)
示例#13
0
 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')
示例#14
0
 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_encrypted__encrypt_and_set(self):
     config = UltraConfig([], encrypter=self.encrypter)
     config.set_encrypted('blah', 'something')
     self.assertEqual('blah', config['blah'])
示例#16
0
 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'])
示例#18
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_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])
示例#20
0
 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_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)
示例#22
0
 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)
示例#24
0
 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)