piknik

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit 17b973a1f04f38b7358ba67a3b48a3ec5bfc5c3c
parent b63d2d271bc5fca3626053914efb5678d4f7a4e2
Author: lash <dev@holbrook.no>
Date:   Tue, 15 Nov 2022 05:44:42 +0000

Add ownership

Diffstat:
Mpiknik/error.py | 8++++++++
Mpiknik/identity.py | 6+++++-
Mpiknik/issue.py | 23+++++++++++++++++++++++
Atest_requirements.txt | 0
Mtests/test_assign.py | 38++++++++++++++++++++++++++++++++++++++
Mtests/test_issue.py | 17-----------------
6 files changed, 74 insertions(+), 18 deletions(-)

diff --git a/piknik/error.py b/piknik/error.py @@ -4,3 +4,11 @@ class DeadIssue(Exception): class AlreadyAssignedError(Exception): pass + + +class NoAssignmentsError(Exception): + pass + + +class UnknownIdentityError(Exception): + pass diff --git a/piknik/identity.py b/piknik/identity.py @@ -10,9 +10,13 @@ class Identity: def id(self): return self.__id.hex() + + def __eq__(self, other): + return other.id() == self.id() + def uri(self): h = hashlib.sha256() - h.update(self.id) + h.update(self.__id) z = h.digest() return 'sha256:' + z.hex() diff --git a/piknik/issue.py b/piknik/issue.py @@ -16,6 +16,7 @@ class Issue: self.title = title self.assigned = [] self.assigned_time = [] + self.owner_idx = 0 @staticmethod @@ -41,6 +42,28 @@ class Issue: def get_assigned(self): return list(zip(self.assigned, self.assigned_time)) + + + def owner(self): + try: + return self.assigned[self.owner_idx] + except Keyerror: + pass + + raise NoAssignmentsError() + + + def set_owner(self, identity): + r = self.owner() + if identity == r: + return False + + for i, v in enumerate(self.assigned): + if v == identity: + self.owner_idx = i + return True + + raise UnknownIdentityError(identity) def __str__(self): diff --git a/test_requirements.txt b/test_requirements.txt diff --git a/tests/test_assign.py b/tests/test_assign.py @@ -25,6 +25,15 @@ class TestAssign(unittest.TestCase): self.assertEqual(r, check) + def test_identity_equality(self): + one = Identity(self.alice) + two = Identity(self.alice) + self.assertTrue(one == two) + + three = Identity(self.bob) + self.assertFalse(one == three) + + def test_identity_load(self): o = Issue('foo') alice = Identity(self.alice) @@ -38,5 +47,34 @@ class TestAssign(unittest.TestCase): self.assertGreater(r[1][1], r[0][1]) + def test_assigned_from_str(self): + o = Issue('foo') + alice = Identity(self.alice) + bob = Identity(self.bob) + o.assign(alice) + o.assign(bob) + v = str(o) + r = Issue.from_str(v) + self.assertTrue(o == r) + + check = r.get_assigned() + self.assertEqual(len(check), 2) + + + def test_set_owner(self): + o = Issue('foo') + alice = Identity(self.alice) + bob = Identity(self.bob) + o.assign(alice) + o.assign(bob) + + r = o.owner() + self.assertEqual(r, alice) + + o.set_owner(bob) + r = o.owner() + self.assertEqual(r, bob) + + if __name__ == '__main__': unittest.main() diff --git a/tests/test_issue.py b/tests/test_issue.py @@ -27,22 +27,5 @@ class TestIssue(unittest.TestCase): self.assertTrue(o == r) - - def test_assigned_from_str(self): - o = Issue('foo') - alice_fp = 'F3FAF668E82EF5124D5187BAEF26F4682343F692' - alice = Identity(alice_fp) - bob_fp = 'F645E047EE5BC4E2824C94DB42DC91CFA8ABA02B' - bob = Identity(bob_fp) - o.assign(alice) - o.assign(bob) - v = str(o) - r = Issue.from_str(v) - self.assertTrue(o == r) - - check = r.get_assigned() - self.assertEqual(len(check), 2) - - if __name__ == '__main__': unittest.main()