From 87a3426d8153f92aaee2edf36b2de62e48c4de0e Mon Sep 17 00:00:00 2001 From: Felix Schurk <75752337+felixschurk@users.noreply.github.com> Date: Fri, 15 Dec 2023 20:35:56 +0100 Subject: [PATCH] prevent tags from being separated inbetween (#34) Add workaround for the destructured tags from taskpirate This includes a detection of the type of the tags and then converting it back to a list. Unit tests for this behavior are also added. --- on_modify.py | 8 ++++- test/test_on-modify_unit.py | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/on_modify.py b/on_modify.py index 1fcafc0..b8663fd 100755 --- a/on_modify.py +++ b/on_modify.py @@ -51,7 +51,13 @@ def extract_tags_from(json_obj): tags.append(json_obj['project']) if 'tags' in json_obj: - tags.extend(json_obj['tags']) + if type(json_obj['tags']) is str: + # Usage of tasklib (e.g. in taskpirate) converts the tag list into a string + # If this is the case, convert it back into a list first + # See https://github.com/tbabej/taskpirate/issues/11 + tags.extend(json_obj['tags'].split(',')) + else: + tags.extend(json_obj['tags']) return tags diff --git a/test/test_on-modify_unit.py b/test/test_on-modify_unit.py index 99f9bea..a191211 100755 --- a/test/test_on-modify_unit.py +++ b/test/test_on-modify_unit.py @@ -367,3 +367,62 @@ def test_hook_should_process_stop(): ) verify(subprocess).call(['timew', 'stop', 'Foo', ':yes']) + +@pytest.mark.usefixtures("teardown") +def test_hook_should_process_start_issue34_with_multiple_tags(): + """on-modify hook should process 'task start' (issue #34) with multiple tags""" + + when(subprocess).call(...) + on_modify.main( + json.loads( + '''{ + "description": "Foo", + "entry": "20190820T203842Z", + "modified": "20190820T203842Z", + "status": "pending", + "tags": ["abc", "xyz"], + "uuid": "16af44c5-57d2-43bf-97ed-cf2e541d927f" + }'''), + json.loads( + '''{ + "description": "Foo", + "entry": "20190820T203842Z", + "modified": "20190820T203842Z", + "start": "20190820T203842Z", + "status": "pending", + "tags": "abc,xyz", + "uuid": "16af44c5-57d2-43bf-97ed-cf2e541d927f" + }''') + ) + + verify(subprocess).call(['timew', 'start', 'Foo', 'abc', 'xyz', ':yes']) + + +@pytest.mark.usefixtures("teardown") +def test_hook_should_process_start_issue34_with_single_tags(): + """on-modify hook should process 'task start' (issue #34) with single tags""" + + when(subprocess).call(...) + on_modify.main( + json.loads( + '''{ + "description": "Foo", + "entry": "20190820T203842Z", + "modified": "20190820T203842Z", + "status": "pending", + "tags": ["abc"], + "uuid": "16af44c5-57d2-43bf-97ed-cf2e541d927f" + }'''), + json.loads( + '''{ + "description": "Foo", + "entry": "20190820T203842Z", + "modified": "20190820T203842Z", + "start": "20190820T203842Z", + "status": "pending", + "tags": "abc", + "uuid": "16af44c5-57d2-43bf-97ed-cf2e541d927f" + }''') + ) + + verify(subprocess).call(['timew', 'start', 'Foo', 'abc', ':yes'])