test_enc.py (1300B)
1 #!/usr/bin/python 2 3 import os 4 import unittest 5 import logging 6 7 from confini import Config 8 from confini.error import DecryptError 9 from confini.crypt.pgp import PGPDecrypter 10 11 logging.basicConfig(level=logging.DEBUG) 12 logg = logging.getLogger() 13 14 script_dir = os.path.dirname(os.path.realpath(__file__)) 15 gnupg_dir = os.path.join(script_dir, 'gnupg') 16 17 class TestBasic(unittest.TestCase): 18 19 wd = os.path.dirname(__file__) 20 21 def setUp(self): 22 pass 23 24 def tearDown(self): 25 pass 26 27 def test_enc(self): 28 inidir = os.path.join(self.wd, 'files/crypt') 29 logg.debug('inidir {}'.format(inidir)) 30 c = Config(inidir) 31 decrypter = PGPDecrypter(base_dir=inidir) 32 c.add_decrypt(decrypter) 33 c.process() 34 with self.assertRaises(DecryptError): 35 c.get('FOO_BAZ') 36 os.environ['GNUPGHOME'] = gnupg_dir 37 c.get('FOO_BAZ') 38 39 40 def test_decrypt_with_non_string(self): 41 inidir = os.path.join(self.wd, 'files/crypt') 42 c = Config(inidir) 43 decrypter = PGPDecrypter() 44 c.add_decrypt(decrypter) 45 c.process() 46 override = { 47 'FOO_XYZZY': False, 48 } 49 c.dict_override(override, 'test') 50 c.get('FOO_XYZZY') 51 52 if __name__ == '__main__': 53 unittest.main()