test_assign.py (2607B)
1 # standard imports 2 import unittest 3 import logging 4 import json 5 6 # local imports 7 from piknik import Issue 8 from piknik.identity import Identity 9 from piknik.error import UnknownIdentityError 10 11 logging.basicConfig(level=logging.DEBUG) 12 logg = logging.getLogger() 13 14 15 class TestAssign(unittest.TestCase): 16 17 def setUp(self): 18 self.alice = 'F3FAF668E82EF5124D5187BAEF26F4682343F692' 19 self.bob = 'F645E047EE5BC4E2824C94DB42DC91CFA8ABA02B' 20 21 22 def test_identity_pointer(self): 23 check = "sha256:65ea9b0609341322903823660bf45326f473d903ee7d327dff442f46d68eacd9" 24 p = Identity(self.alice) 25 r = p.uri() 26 self.assertEqual(r, check) 27 28 29 def test_identity_load(self): 30 o = Issue('foo') 31 alice = Identity(self.alice) 32 o.assign(alice) 33 bob = Identity(self.bob) 34 o.assign(bob) 35 r = o.get_assigned() 36 self.assertEqual(len(r), 2) 37 self.assertEqual(r[0][0], alice) 38 self.assertEqual(r[1][0], bob) 39 self.assertGreater(r[1][1], r[0][1]) 40 41 42 def test_identity_assigned_from_str(self): 43 o = Issue('foo') 44 alice = Identity(self.alice) 45 bob = Identity(self.bob) 46 o.assign(alice) 47 o.assign(bob) 48 v = str(o) 49 r = Issue.from_str(v) 50 self.assertTrue(o == r) 51 52 check = r.get_assigned() 53 self.assertEqual(len(check), 2) 54 55 56 def test_identity_set_owner(self): 57 o = Issue('foo') 58 alice = Identity(self.alice) 59 bob = Identity(self.bob) 60 o.assign(alice) 61 o.assign(bob) 62 63 r = o.owner() 64 self.assertEqual(r, alice) 65 66 o.set_owner(bob) 67 r = o.owner() 68 self.assertEqual(r, bob) 69 70 71 def test_identity_unassign(self): 72 o = Issue('foo') 73 alice = Identity(self.alice) 74 bob = Identity(self.bob) 75 o.assign(alice) 76 o.assign(bob) 77 78 o.unassign(alice) 79 r = o.get_assigned() 80 self.assertEqual(len(r), 1) 81 82 r = o.owner() 83 self.assertEqual(r, bob) 84 85 with self.assertRaises(UnknownIdentityError): 86 o.unassign(alice) 87 88 o.unassign(bob) 89 with self.assertRaises(UnknownIdentityError): 90 o.owner() 91 92 93 def test_issue_identity_equality(self): 94 alice = Identity(self.alice) 95 bob = Identity(self.bob) 96 97 one = Issue('foo') 98 two = Issue('foo', issue_id=one.id) 99 100 one.assign(alice) 101 two.assign(alice) 102 self.assertTrue(one == two) 103 104 two.assign(bob) 105 self.assertFalse(one == two) 106 107 108 if __name__ == '__main__': 109 unittest.main()