From: Rob Golding Date: Sun, 3 Nov 2013 20:52:25 +0000 (+0000) Subject: Implement tasks.completed() and add more tests X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/30a5525b762a066b56e6f981c8d79193740419fe?ds=inline;hp=3959dcce625dfbc4ede92e73c491ca0c753e3a4f Implement tasks.completed() and add more tests --- diff --git a/tasklib/task.py b/tasklib/task.py index 182fead..9a02f35 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -8,6 +8,7 @@ import subprocess DATE_FORMAT = '%Y%m%dT%H%M%SZ' REPR_OUTPUT_SIZE = 10 PENDING = 'pending' +COMPLETED = 'completed' logger = logging.getLogger(__name__) @@ -195,6 +196,9 @@ class TaskQuerySet(object): def pending(self): return self.filter(status=PENDING) + def completed(self): + return self.filter(status=COMPLETED) + def filter(self, *args, **kwargs): """ Returns a new TaskQuerySet with the given filters added. diff --git a/tasklib/tests.py b/tasklib/tests.py index 5344d71..94294dc 100644 --- a/tasklib/tests.py +++ b/tasklib/tests.py @@ -25,3 +25,14 @@ class TaskFilterTest(TasklibTest): self.assertEqual(len(self.tw.tasks.all()), 1) self.assertEqual(self.tw.tasks.all()[0]['description'], 'test task') self.assertEqual(self.tw.tasks.all()[0]['status'], 'pending') + + def test_pending_non_empty(self): + self.tw.execute_command(['add', 'test task']) + self.assertEqual(len(self.tw.tasks.pending()), 1) + self.assertEqual(self.tw.tasks.pending()[0]['description'], + 'test task') + self.assertEqual(self.tw.tasks.pending()[0]['status'], 'pending') + + def test_completed_empty(self): + self.tw.execute_command(['add', 'test task']) + self.assertEqual(len(self.tw.tasks.completed()), 0)