test_store.py (2992B)
1 # standard imports 2 import unittest 3 import logging 4 import tempfile 5 import shutil 6 # external imports 7 import shep 8 9 # local imports 10 from piknik import ( 11 Basket, 12 Issue, 13 ) 14 from piknik.error import DeadIssue 15 from piknik.store import FileStoreFactory 16 from piknik.identity import Identity 17 18 # tests imports 19 from tests.common import debug_out 20 from tests.common import TestStates 21 from tests.common import pgp_setup 22 23 24 logging.basicConfig(level=logging.DEBUG) 25 logg = logging.getLogger() 26 27 28 def debug_out(self, k, v): 29 logg.debug('TRACE: {} {}'.format(k, v)) 30 31 32 class TestStore(unittest.TestCase): 33 34 def setUp(self): 35 self.d = tempfile.mkdtemp() 36 logg.debug('tempdir is {}'.format(self.d)) 37 self.store_factory = FileStoreFactory(self.d) 38 self.b = Basket(self.store_factory) 39 40 41 def tearDown(self): 42 shutil.rmtree(self.d) 43 pass 44 45 46 # TODO: assert 47 def test_basic(self): 48 o = Issue('foo') 49 v = self.b.add(o) 50 51 52 # TODO: assert 53 def test_load(self): 54 o = Issue('foo') 55 va = self.b.add(o) 56 57 o = Issue('bar') 58 vb = self.b.add(o) 59 60 self.b.advance(va) 61 62 b = Basket(self.store_factory) 63 r = b.get(va) 64 65 66 def test_load_tag(self): 67 o = Issue('foo') 68 va = self.b.add(o) 69 self.b.tag(va, 'inky') 70 self.b.tag(va, 'pinky') 71 72 b = Basket(self.store_factory) 73 r = b.tags(va) 74 self.assertIn('INKY', r) 75 self.assertIn('PINKY', r) 76 77 self.b.untag(va, 'inky') 78 b = Basket(self.store_factory) 79 r = b.tags(va) 80 self.assertNotIn('INKY', r) 81 self.assertIn('PINKY', r) 82 83 84 # TODO: assert 85 def test_msg_putget(self): 86 o = Issue('foo') 87 issue_id = self.b.add(o) 88 m = self.b.msg(issue_id, 's:bar') 89 90 91 # TODO: assert 92 def test_msg_resume(self): 93 o = Issue('foo') 94 v = self.b.add(o) 95 m = self.b.msg(v, 's:bar') 96 97 b = Basket(self.store_factory) 98 m = b.msg(v, 's:baz') 99 100 101 def test_msg_sig_verify_resume(self): 102 (crypto, gpg, gpg_dir) = pgp_setup() 103 b = Basket(self.store_factory, message_wrapper=crypto.sign) 104 o = Issue('foo') 105 v = b.add(o) 106 r = b.msg(v, 's:foo', 's:bar') 107 108 b = Basket(self.store_factory, message_wrapper=crypto.sign) 109 m = b.get_msg(v) 110 111 112 def test_store_assignments(self): 113 o = Issue('foo') 114 vb = self.b.add(o) 115 116 alice = b'inky'.hex() 117 bob = b'pinky'.hex() 118 119 self.b.assign(vb, alice) 120 self.b.assign(vb, bob) 121 self.b.owner(vb, bob) 122 r = self.b.get(vb) 123 check = Identity(bob) 124 self.assertTrue(r.owner() == check) 125 126 self.b.unassign(vb, alice) 127 128 r = self.b.get(vb) 129 check = Identity(bob) 130 self.assertEqual(r.owner(), check) 131 check_assigned = r.get_assigned() 132 self.assertTrue(r.owner() == check) 133 134 135 if __name__ == '__main__': 136 unittest.main()