commit bed5ca74a47318926623d21ffb35de9ce909ac97
parent 17b973a1f04f38b7358ba67a3b48a3ec5bfc5c3c
Author: lash <dev@holbrook.no>
Date: Tue, 15 Nov 2022 05:54:01 +0000
Enable issue unassign
Diffstat:
3 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/piknik/error.py b/piknik/error.py
@@ -6,9 +6,5 @@ class AlreadyAssignedError(Exception):
pass
-class NoAssignmentsError(Exception):
- pass
-
-
class UnknownIdentityError(Exception):
pass
diff --git a/piknik/issue.py b/piknik/issue.py
@@ -5,6 +5,8 @@ import datetime
# local imports
from piknik.identity import Identity
+from piknik.error import UnknownIdentityError
+from piknik.error import AlreadyAssignedError
class Issue:
@@ -44,13 +46,23 @@ class Issue:
return list(zip(self.assigned, self.assigned_time))
+ def unassign(self, identity):
+ for i, v in enumerate(self.assigned):
+ if v == identity:
+ self.assigned.remove(v)
+ if i == self.owner_idx:
+ self.owner_idx = 0
+ return True
+ raise UnknownIdentityError(identity)
+
+
def owner(self):
try:
return self.assigned[self.owner_idx]
- except Keyerror:
+ except IndexError:
pass
- raise NoAssignmentsError()
+ raise UnknownIdentityError
def set_owner(self, identity):
diff --git a/tests/test_assign.py b/tests/test_assign.py
@@ -6,6 +6,7 @@ import json
# local imports
from piknik import Issue
from piknik.identity import Identity
+from piknik.error import UnknownIdentityError
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@@ -47,7 +48,7 @@ class TestAssign(unittest.TestCase):
self.assertGreater(r[1][1], r[0][1])
- def test_assigned_from_str(self):
+ def test_identity_assigned_from_str(self):
o = Issue('foo')
alice = Identity(self.alice)
bob = Identity(self.bob)
@@ -61,7 +62,7 @@ class TestAssign(unittest.TestCase):
self.assertEqual(len(check), 2)
- def test_set_owner(self):
+ def test_identity_set_owner(self):
o = Issue('foo')
alice = Identity(self.alice)
bob = Identity(self.bob)
@@ -76,5 +77,27 @@ class TestAssign(unittest.TestCase):
self.assertEqual(r, bob)
+ def test_identity_unassign(self):
+ o = Issue('foo')
+ alice = Identity(self.alice)
+ bob = Identity(self.bob)
+ o.assign(alice)
+ o.assign(bob)
+
+ o.unassign(alice)
+ r = o.get_assigned()
+ self.assertEqual(len(r), 1)
+
+ r = o.owner()
+ self.assertEqual(r, bob)
+
+ with self.assertRaises(UnknownIdentityError):
+ o.unassign(alice)
+
+ o.unassign(bob)
+ with self.assertRaises(UnknownIdentityError):
+ o.owner()
+
+
if __name__ == '__main__':
unittest.main()