commit 58a4cb2b1522a12b7cc957efb64617b70326f2ce
parent bed5ca74a47318926623d21ffb35de9ce909ac97
Author: lash <dev@holbrook.no>
Date: Tue, 15 Nov 2022 06:34:23 +0000
Integrate assignments with store
Diffstat:
5 files changed, 76 insertions(+), 10 deletions(-)
diff --git a/piknik/basket.py b/piknik/basket.py
@@ -8,10 +8,10 @@ import shep
from .error import DeadIssue
from .issue import Issue
from .msg import IssueMessage
+from .identity import Identity
logg = logging.getLogger(__name__)
-
class Basket:
def __init__(self, state_factory, message_wrapper=None, message_verifier=None):
@@ -53,6 +53,7 @@ class Basket:
def get(self, issue_id):
r = self.state.get(issue_id)
+ print('get content {}'.format(r))
o = Issue.from_str(r)
return o
@@ -159,6 +160,33 @@ class Basket:
return self.__get_msg(issue_id)
+ def assign(self, issue_id, identity):
+ r = self.state.get(issue_id)
+ o = Issue.from_str(r)
+ v = Identity(identity)
+ r = o.assign(v)
+ self.state.replace(issue_id, contents=str(o))
+ return r
+
+
+ def owner(self, issue_id, identity):
+ r = self.state.get(issue_id)
+ o = Issue.from_str(r)
+ v = Identity(identity)
+ r = o.set_owner(v)
+ self.state.replace(issue_id, contents=str(o))
+ return r
+
+
+ def unassign(self, issue_id, identity):
+ r = self.state.get(issue_id)
+ o = Issue.from_str(r)
+ v = Identity(identity)
+ r = o.unassign(v)
+ self.state.replace(issue_id, contents=str(o))
+ return r
+
+
def msg(self, issue_id, *args):
m = self.__get_msg(issue_id)
m.add(*args, wrapper=self.__msg_wrap)
diff --git a/piknik/issue.py b/piknik/issue.py
@@ -26,6 +26,7 @@ class Issue:
r = json.loads(s)
o = Issue(title=r['title'], issue_id=r['id'])
for k in r['assigned'].keys():
+ print('processing {}'.format(k))
p = Identity(k)
o.assigned.append(p)
t = datetime.datetime.utcfromtimestamp(r['assigned'][k])
@@ -95,4 +96,10 @@ class Issue:
return False
if o.title != self.title:
return False
+ if len(self.assigned) != len(o.assigned):
+ return False
+ for i, v in enumerate(self.assigned):
+ if o.assigned[i] != v:
+ return False
+
return True
diff --git a/piknik/runnable/mod.py b/piknik/runnable/mod.py
@@ -16,6 +16,7 @@ argp.add_argument('-t', '--tag', type=str, action='append', default=[], help='Ad
argp.add_argument('-u', '--untag', type=str, action='append', default=[], help='Remove tag from issue')
argp.add_argument('-f', '--file', type=str, action='append', help='Add message file part')
argp.add_argument('-m', '--message', type=str, action='append', default=[], help='Add message text part')
+argp.add_argument('-a', '--assign', type=str, action='append', default=[], help='Assign given identity to issue')
argp.add_argument('issue_id', type=str, help='Issue id to modify')
arg = argp.parse_args(sys.argv[1:])
@@ -43,6 +44,10 @@ def main():
for v in arg.untag:
basket.untag(arg.issue_id, v)
+ for v in arg.assign:
+ basket.assign(arg.issue_id, v)
+
+
if __name__ == '__main__':
main()
diff --git a/tests/test_assign.py b/tests/test_assign.py
@@ -26,15 +26,6 @@ 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)
@@ -99,5 +90,20 @@ class TestAssign(unittest.TestCase):
o.owner()
+ def test_issue_identity_equality(self):
+ alice = Identity(self.alice)
+ bob = Identity(self.bob)
+
+ one = Issue('foo')
+ two = Issue('foo', issue_id=one.id)
+
+ one.assign(alice)
+ two.assign(alice)
+ self.assertTrue(one == two)
+
+ two.assign(bob)
+ self.assertFalse(one == two)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_store.py b/tests/test_store.py
@@ -13,6 +13,7 @@ from piknik import (
)
from piknik.error import DeadIssue
from piknik.store import FileStoreFactory
+from piknik.identity import Identity
# tests imports
from tests.common import debug_out
@@ -109,5 +110,24 @@ class TestStore(unittest.TestCase):
m = b.get_msg(v)
+ def test_store_assignments(self):
+ o = Issue('foo')
+ vb = self.b.add(o)
+
+ alice = b'inky'.hex()
+ bob = b'pinky'.hex()
+
+ self.b.assign(vb, alice)
+ self.b.assign(vb, bob)
+ self.b.owner(vb, bob)
+ self.b.unassign(vb, alice)
+
+ r = self.b.get(vb)
+ check = Identity(bob)
+ self.assertEqual(r.owner(), check)
+ check_assigned = r.get_assigned()
+ self.assertEqual(check_assigned[0][0], check)
+
+
if __name__ == '__main__':
unittest.main()