From 21f0060899008fbdcaf59eef7fd79cb78ec3e0c4 Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Wed, 21 Aug 2019 21:02:05 +0200 Subject: [PATCH] Overhaul test - Update example JSONs - Test only for active time tracking - Test resulting intervals, not resulting output Signed-off-by: Thomas Lauf --- test/test_on-modify.timewarrior.t | 181 ++++++++++++++---------------- 1 file changed, 82 insertions(+), 99 deletions(-) diff --git a/test/test_on-modify.timewarrior.t b/test/test_on-modify.timewarrior.t index bf9a5a05..24c9317d 100755 --- a/test/test_on-modify.timewarrior.t +++ b/test/test_on-modify.timewarrior.t @@ -53,185 +53,168 @@ class TestOnModifyHookScript(TestCase): def test_hook_should_process_annotate(self): """on-modify hook should process 'task annotate'""" + self.t("start 10min ago Foo") + out, err = self.process.communicate(input="""\ -{ "description": "Foo", "entry": "20180316T231055Z", "modified": "20180316T231055Z", "status": "pending", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3" } -{ "description": "Foo", "entry": "20180316T231055Z", "modified": "20180316T231055Z", "status": "pending", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3", "annotations": [{ "entry": "20180316T231239Z", "description": "Bar" }]} +{"description":"Foo","entry":"20190820T201911Z","modified":"20190820T201911Z","start":"20190820T201911Z","status":"pending","uuid":"3495a755-c4c6-4106-aabe-c0d3d128b65a"} +{"description":"Foo","entry":"20190820T201911Z","modified":"20190820T201911Z","start":"20190820T201911Z","status":"pending","uuid":"3495a755-c4c6-4106-aabe-c0d3d128b65a","annotations":[{"entry":"20190820T201911Z","description":"Annotation"}]} """) - self.assertEqual('{"status": "pending", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3", "modified": "20180316T231055Z", "entry": "20180316T231055Z", "annotations": [{"entry": "20180316T231239Z", "description": "Bar"}], "description": "Foo"}\n', out) self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["Foo"], expectedAnnotation="Annotation") + def test_hook_should_process_append(self): """on-modify hook should process 'task append'""" + self.t("start 10min ago Foo") + out, err = self.process.communicate(input="""\ -{ "description": "FooBar", "entry": "20180316T231125Z", "modified": "20180316T231808Z", "status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094" } -{ "description": "FooBar Baz", "entry": "20180316T231125Z", "modified": "20180316T231808Z", "status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094" } +{"description":"Foo","entry":"20190820T201911Z","modified":"20190820T201911Z","start":"20190820T201911Z","status":"pending","uuid":"da603270-ce2b-4a5a-9273-c67c2d2d0067"} +{"description":"Foo Bar","entry":"20190820T201911Z","modified":"20190820T201911Z","start":"20190820T201911Z","status":"pending","uuid":"da603270-ce2b-4a5a-9273-c67c2d2d0067"} """) - self.assertEqual('{"status": "pending", "entry": "20180316T231125Z", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094", "description": "FooBar Baz", "modified": "20180316T231808Z"}\n', out) self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["Foo Bar"]) + def test_hook_should_process_delete(self): """on-modify hook should process 'task delete'""" + self.t("start 10min ago Foo") + out, err = self.process.communicate(input="""\ -{ "description": "Read Taskwarrior documents later", "entry": "20180316T225357Z", "modified": "20180316T225357Z", "status": "pending", "uuid": "3bfe7518-8644-4c3c-9788-940d782fefac" } -{ "description": "Read Taskwarrior documents later", "end": "20180316T230837Z", "entry": "20180316T225357Z", "modified": "20180316T225357Z", "status": "deleted", "uuid": "3bfe7518-8644-4c3c-9788-940d782fefac" } +{"description":"Foo","entry":"20190820T201911Z","modified":"20190820T201911Z","start":"20190820T201911Z","status":"pending","uuid":"25b66283-96e0-42b4-b835-8efd0ea1043c"} +{"description":"Foo","end":"20190820T201911Z","entry":"20190820T201911Z","modified":"20190820T201911Z","start":"20190820T201911Z","status":"deleted","uuid":"25b66283-96e0-42b4-b835-8efd0ea1043c"} """) - self.assertEqual('{"status": "deleted", "end": "20180316T230837Z", "uuid": "3bfe7518-8644-4c3c-9788-940d782fefac", "modified": "20180316T225357Z", "entry": "20180316T225357Z", "description": "Read Taskwarrior documents later"}\n', out) self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertClosedInterval(j[0], expectedTags=["Foo"]) + def test_hook_should_process_denotate(self): """on-modify hook should process 'task denotate'""" + self.t("start 10min ago Foo") + self.t("annotate @1 Annotation") + out, err = self.process.communicate(input="""\ -{ "description": "Foo", "entry": "20180316T231055Z", "modified": "20180316T231239Z", "status": "pending", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3", "annotations": [{ "entry": "20180316T231239Z", "description": "Bar" }]} -{ "description": "Foo", "entry": "20180316T231055Z", "modified": "20180316T231239Z", "status": "pending", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3" } +{"description":"Foo","entry":"20190820T201911Z","modified":"20190820T201911Z","start":"20190820T201911Z","status":"pending","uuid":"8811cc93-a495-4fa6-993e-2b96cffc48e0","annotations":[{"entry":"20190820T201911Z","description":"Annotation"}]} +{"description":"Foo","entry":"20190820T201911Z","modified":"20190820T201911Z","start":"20190820T201911Z","status":"pending","uuid":"8811cc93-a495-4fa6-993e-2b96cffc48e0"} """) - self.assertEqual('{"status": "pending", "entry": "20180316T231055Z", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3", "description": "Foo", "modified": "20180316T231239Z"}\n', out) self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["Foo"], expectedAnnotation="") + def test_hook_should_process_done(self): """on-modify hook should process 'task done'""" + self.t("start 10min ago Foo") + out, err = self.process.communicate(input="""\ -{ "description": "Pay bills", "entry": "20180316T225418Z", "modified": "20180316T225418Z", "priority": "H", "status": "pending", "uuid": "94699c4e-b1ae-4838-bc6b-c8476251f898" } -{ "description": "Pay bills", "end": "20180316T230221Z", "entry": "20180316T225418Z", "modified": "20180316T225418Z", "priority": "H", "status": "completed", "uuid": "94699c4e-b1ae-4838-bc6b-c8476251f898" } +{"description":"Foo","entry":"20190820T201912Z","modified":"20190820T201912Z","start":"20190820T201912Z","status":"pending","uuid":"c418b958-5c3c-4633-89a4-4a2f678d74d0"} +{"description":"Foo","end":"20190820T201912Z","entry":"20190820T201912Z","modified":"20190820T201912Z","status":"completed","uuid":"c418b958-5c3c-4633-89a4-4a2f678d74d0"} """) - self.assertEqual('{"status": "completed", "end": "20180316T230221Z", "description": "Pay bills", "modified": "20180316T225418Z", "priority": "H", "entry": "20180316T225418Z", "uuid": "94699c4e-b1ae-4838-bc6b-c8476251f898"}\n', out) self.assertEqual('', err) - def test_hook_should_process_edit(self): - """on-modify hook should process 'task edit'""" - out, err = self.process.communicate(input="""\ -{ "description": "Foo", "entry": "20180316T231125Z", "modified": "20180316T231055Z", "status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094" } -{ "description": "FooBar", "entry": "20180316T231125Z", "modified": "20180316T231055Z", "status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094" } -""") - - self.assertEqual('{"status": "pending", "entry": "20180316T231125Z", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094", "description": "FooBar", "modified": "20180316T231055Z"}\n', out) - self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertClosedInterval(j[0], expectedTags=["Foo"]) def test_hook_should_process_modify_desc(self): """on-modify hook should process 'task modify' for changing description""" + self.t("start 10min ago Foo") - self.t("start dummy") out, err = self.process.communicate(input="""\ -{"description":"dummy","entry":"20180317T092629Z","modified":"20180317T092629Z","start":"20180317T092629Z","status":"pending","uuid":"3422d76c-c087-4ecd-9c62-1246b078e534"} -{"description":"foo","entry":"20180317T092629Z","modified":"20180317T092629Z","start":"20180317T092629Z","status":"pending","uuid":"3422d76c-c087-4ecd-9c62-1246b078e534"} +{"description":"Foo","entry":"20190820T203416Z","modified":"20190820T203416Z","start":"20190820T203416Z","status":"pending","uuid":"189e6745-04e0-4b17-949f-900cf63ab8d9"} +{"description":"Bar","entry":"20190820T203416Z","modified":"20190820T203416Z","start":"20190820T203416Z","status":"pending","uuid":"189e6745-04e0-4b17-949f-900cf63ab8d9"} """) - self.assertRegexpMatches(out, """\ -Removed dummy from @1 -Note: 'foo' is a new tag. -Added foo to @1 -\{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "modified": "20180317T092629Z", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "foo"\} -""") self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["Bar"]) + def test_hook_should_process_modify_tags(self): """on-modify hook should process 'task modify' for changing tags""" + self.t("start 10min ago Foo Tag Bar") - self.t("start dummy tag1 tag2") out, err = self.process.communicate(input="""\ -{"description":"dummy","entry":"20180317T092629Z","modified":"20180317T092629Z","start":"20180317T092629Z","status":"pending","uuid":"3422d76c-c087-4ecd-9c62-1246b078e534","tags":["tag1","tag2"]} -{"description":"dummy","entry":"20180317T092629Z","modified":"20180317T092629Z","start":"20180317T092629Z","status":"pending","uuid":"3422d76c-c087-4ecd-9c62-1246b078e534","tags":["tag3","tag4"]} +{"description":"Foo","entry":"20190820T203620Z","modified":"20190820T203620Z","start":"20190820T203620Z","status":"pending","tags":["Tag","Bar"],"uuid":"6cab88f0-ac12-4a87-995a-0e7d39810c05"} +{"description":"Foo","entry":"20190820T203620Z","modified":"20190820T203620Z","start":"20190820T203620Z","status":"pending","tags":["Tag","Baz"],"uuid":"6cab88f0-ac12-4a87-995a-0e7d39810c05"} """) - self.assertRegexpMatches(out, """\ -Removed dummy tag1 tag2 from @1 -Note: 'dummy' is a new tag. -Note: 'tag3' is a new tag. -Note: 'tag4' is a new tag. -Added dummy tag3 tag4 to @1 -\{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "tags": \["tag3", "tag4"\], "modified": "20180317T092629Z", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "dummy"\} -""") self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["Foo", "Tag", "Baz"]) + def test_hook_should_process_modify_project(self): """on-modify hook should process 'task modify' for changing project""" + self.t("start Foo dummy") - self.t("start dummy proj1") out, err = self.process.communicate(input="""\ -{"description":"dummy","entry":"20180317T092629Z","modified":"20180317T092629Z","start":"20180317T092629Z","status":"pending","uuid":"3422d76c-c087-4ecd-9c62-1246b078e534","project":"proj1"} -{"description":"dummy","entry":"20180317T092629Z","modified":"20180317T092629Z","start":"20180317T092629Z","status":"pending","uuid":"3422d76c-c087-4ecd-9c62-1246b078e534","project":"proj2"} +{"description":"Foo","entry":"20190820T203842Z","modified":"20190820T203842Z","project":"dummy","start":"20190820T203842Z","status":"pending","uuid":"d95dc7a0-6189-4692-b58a-4ab60d539c8d"} +{"description":"Foo","entry":"20190820T203842Z","modified":"20190820T203842Z","project":"test","start":"20190820T203842Z","status":"pending","uuid":"d95dc7a0-6189-4692-b58a-4ab60d539c8d"} """) - self.assertRegexpMatches(out, """\ -Removed dummy proj1 from @1 -Note: 'dummy' is a new tag. -Note: 'proj2' is a new tag. -Added dummy proj2 to @1 -\{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "modified": "20180317T092629Z", "project": "proj2", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "dummy"\} -""") self.assertEqual('', err) - def test_hook_should_process_modify_not_tracked(self): - """on-modify hook should process 'task modify' for tasks which are not time-tracked""" - out, err = self.process.communicate(input="""\ -{"description":"dummy","entry":"20180317T092629Z","modified":"20180317T092629Z","status":"pending","uuid":"3422d76c-c087-4ecd-9c62-1246b078e534","project":"proj1"} -{"description":"dummy","entry":"20180317T092629Z","modified":"20180317T092629Z","status":"pending","uuid":"3422d76c-c087-4ecd-9c62-1246b078e534","project":"proj2"} -""") - - self.assertEqual('{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "modified": "20180317T092629Z", "project": "proj2", "entry": "20180317T092629Z", "description": "dummy"}\n', out) - self.assertEqual('', err) - - # This is needed to test the case for task which are time-tracked and modify is called for changes other than project/tag/description - def test_hook_should_process_modify_due_date(self): - """on-modify hook should process 'task modify' for time-tracked task for changing annotations""" - - self.t("start dummy") - out, err = self.process.communicate(input="""\ -{"status": "pending", "description": "dummy", "modified": "20180513T073915Z", "due": "20180514T000000Z", "start": "20180513T073915Z", "entry": "20180513T054634Z", "uuid": "09e9620e-8906-47ad-92c5-305894534aac"} -{"status": "pending", "description": "dummy", "modified": "20180513T073915Z", "due": "20180512T000000Z", "start": "20180513T073915Z", "entry": "20180513T054634Z", "uuid": "09e9620e-8906-47ad-92c5-305894534aac"} -""") - - self.assertEqual('{"status": "pending", "description": "dummy", "due": "20180512T000000Z", "modified": "20180513T073915Z", "start": "20180513T073915Z", "entry": "20180513T054634Z", "uuid": "09e9620e-8906-47ad-92c5-305894534aac"}\n', out) - - self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["Foo", "test"]) def test_hook_should_process_prepend(self): """on-modify hook should process 'task prepend'""" + self.t("start 10min ago Foo") + out, err = self.process.communicate(input="""\ -{ "description": "Foo", "entry": "20180316T231055Z", "modified": "20180316T231617Z", "status": "pending", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3" } -{ "description": "Hey Foo", "entry": "20180316T231055Z", "modified": "20180316T231617Z", "status": "pending", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3" } +{"description":"Foo","entry":"20190820T203842Z","modified":"20190820T203842Z","start":"20190820T203842Z","status":"pending","uuid":"02bc8839-b304-49f9-ac1a-29ac4850583f"} +{"description":"Prefix Foo","entry":"20190820T203842Z","modified":"20190820T203842Z","start":"20190820T203842Z","status":"pending","uuid":"02bc8839-b304-49f9-ac1a-29ac4850583f"} """) - self.assertEqual('{"status": "pending", "entry": "20180316T231055Z", "uuid": "d07b40c4-5df7-409f-bf98-930e550333b3", "description": "Hey Foo", "modified": "20180316T231617Z"}\n', out) self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["Prefix Foo"]) + def test_hook_should_process_start(self): """on-modify hook should process 'task start'""" out, err = self.process.communicate(input="""\ -{ "description": "FooBar", "due": "20180331T220000Z", "entry": "20180316T231125Z", "modified": "20180316T232513Z", "status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094" } -{ "description": "FooBar", "due": "20180331T220000Z", "entry": "20180316T231125Z", "modified": "20180316T232513Z", "start": "20180316T232651Z", "status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094" } +{"description":"Foo","entry":"20190820T203842Z","modified":"20190820T203842Z","status":"pending","uuid":"16af44c5-57d2-43bf-97ed-cf2e541d927f"} +{"description":"Foo","entry":"20190820T203842Z","modified":"20190820T203842Z","start":"20190820T203842Z","status":"pending","uuid":"16af44c5-57d2-43bf-97ed-cf2e541d927f"} """) - self.assertRegexpMatches(out, """\ -Tracking FooBar - Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} - Current (\d{2}:| )\d{2} - Total ?\d{1,2}:\d{2}:\d{2} -\{"status": "pending", "description": "FooBar", "modified": "20180316T232513Z", "due": "20180331T220000Z", "start": "20180316T232651Z", "entry": "20180316T231125Z", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094"\} -""") self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["Foo"]) + def test_hook_should_process_stop(self): """on-modify hook should process 'task stop'""" - self.t("start 10min ago") + self.t("start 10min ago Foo") + out, err = self.process.communicate(input="""\ -{ "description": "FooBar", "due": "20180331T220000Z", "entry": "20180316T231125Z", "modified": "20180316T232651Z", "start": "20180316T232651Z", "status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094" } -{ "description": "FooBar", "due": "20180331T220000Z", "entry": "20180316T231125Z", "modified": "20180316T232651Z", "status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094" } +{"description":"Foo","entry":"20190820T203842Z","modified":"20190820T203842Z","start":"20190820T203842Z","status":"pending","uuid":"13f83e99-f6a2-4857-9e00-bdeede064772"} +{"description":"Foo","entry":"20190820T203842Z","modified":"20190820T203842Z","status":"pending","uuid":"13f83e99-f6a2-4857-9e00-bdeede064772"} """) - self.assertRegexpMatches(out, """\ -Recorded - Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} - Ended (\d{2}:| )\d{2} - Total ?\d{1,2}:\d{2}:\d{2} -\{"status": "pending", "uuid": "e11d7d19-20a7-47bb-999e-6554a70ea094", "modified": "20180316T232651Z", "due": "20180331T220000Z", "entry": "20180316T231125Z", "description": "FooBar"\} -""") self.assertEqual('', err) + j = self.t.export() + self.assertEqual(len(j), 1) + self.assertClosedInterval(j[0], expectedTags=["Foo"]) + if __name__ == "__main__": from simpletap import TAPTestRunner