common.py (1303B)
1 # standard imports 2 import logging 3 import tempfile 4 5 # external imports 6 import shep 7 import gnupg 8 9 logg = logging.getLogger() 10 11 12 def debug_out(self, k, v): 13 logg.debug('TRACE: {} {}'.format(k, v)) 14 15 16 class TestMsgStore: 17 18 def __init__(self): 19 self.store = {} 20 21 def put(self, k, v): 22 self.store[k] = v 23 24 def get(self, k): 25 try: 26 return self.store[k] 27 except KeyError: 28 pass 29 raise FileNotFoundError(k) 30 31 32 def purge(self, k): 33 del self.store[k] 34 35 36 class TestStates: 37 38 def create_states(self, *args, **kwargs): 39 return shep.State(6, *args, event_callback=debug_out, **kwargs) 40 41 42 def create_tags(self, *args, **kwargs): 43 return shep.State(0, *args, event_callback=debug_out, check_alias=False, **kwargs) 44 45 46 def create_messages(self, *args): 47 return TestMsgStore() 48 49 50 def create_aliases(self, *args): 51 return TestMsgStore() 52 53 54 def pgp_setup(): 55 from piknik.crypto import PGPSigner 56 gpg_dir = tempfile.mkdtemp() 57 gpg = gnupg.GPG(gnupghome=gpg_dir) 58 gpg_input = gpg.gen_key_input(key_type='RSA', key_length=1024, passphrase='foo') 59 gpg_key = gpg.gen_key(gpg_input) 60 crypto = PGPSigner(gpg_dir, default_key=gpg_key.fingerprint, passphrase='foo') 61 return (crypto, gpg, gpg_dir,)