All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
7 from .task import TaskWarrior, Task
10 class TasklibTest(unittest.TestCase):
13 self.tmp = tempfile.mkdtemp(dir='.')
14 self.tw = TaskWarrior(data_location=self.tmp)
17 shutil.rmtree(self.tmp)
20 class TaskFilterTest(TasklibTest):
22 def test_all_empty(self):
23 self.assertEqual(len(self.tw.tasks.all()), 0)
25 def test_all_non_empty(self):
26 Task(self.tw, description="test task").save()
27 self.assertEqual(len(self.tw.tasks.all()), 1)
28 self.assertEqual(self.tw.tasks.all()[0]['description'], 'test task')
29 self.assertEqual(self.tw.tasks.all()[0]['status'], 'pending')
31 def test_pending_non_empty(self):
32 Task(self.tw, description="test task").save()
33 self.assertEqual(len(self.tw.tasks.pending()), 1)
34 self.assertEqual(self.tw.tasks.pending()[0]['description'],
36 self.assertEqual(self.tw.tasks.pending()[0]['status'], 'pending')
38 def test_completed_empty(self):
39 Task(self.tw, description="test task").save()
40 self.assertEqual(len(self.tw.tasks.completed()), 0)
42 def test_completed_non_empty(self):
43 Task(self.tw, description="test task").save()
44 self.assertEqual(len(self.tw.tasks.completed()), 0)
45 self.tw.tasks.all()[0].done()
46 self.assertEqual(len(self.tw.tasks.completed()), 1)
48 def test_filtering_by_attribute(self):
49 Task(self.tw, description="no priority task").save()
50 Task(self.tw, priority="H", description="high priority task").save()
51 self.assertEqual(len(self.tw.tasks.all()), 2)
53 # Assert that the correct number of tasks is returned
54 self.assertEqual(len(self.tw.tasks.filter(priority="H")), 1)
56 # Assert that the correct tasks are returned
57 high_priority_task = self.tw.tasks.get(priority="H")
58 self.assertEqual(high_priority_task['description'], "high priority task")
60 def test_filtering_by_empty_attribute(self):
61 Task(self.tw, description="no priority task").save()
62 Task(self.tw, priority="H", description="high priority task").save()
63 self.assertEqual(len(self.tw.tasks.all()), 2)
65 # Assert that the correct number of tasks is returned
66 self.assertEqual(len(self.tw.tasks.filter(priority=None)), 1)
68 # Assert that the correct tasks are returned
69 no_priority_task = self.tw.tasks.get(priority=None)
70 self.assertEqual(no_priority_task['description'], "no priority task")
73 class AnnotationTest(TasklibTest):
76 super(AnnotationTest, self).setUp()
77 Task(self.tw, description="test task").save()
79 def test_adding_annotation(self):
80 task = self.tw.tasks.get()
81 task.add_annotation('test annotation')
82 self.assertEqual(len(task['annotations']), 1)
83 ann = task['annotations'][0]
84 self.assertEqual(ann['description'], 'test annotation')
86 def test_removing_annotation(self):
87 task = self.tw.tasks.get()
88 task.add_annotation('test annotation')
89 ann = task['annotations'][0]
91 self.assertEqual(len(task['annotations']), 0)
93 def test_removing_annotation_by_description(self):
94 task = self.tw.tasks.get()
95 task.add_annotation('test annotation')
96 task.remove_annotation('test annotation')
97 self.assertEqual(len(task['annotations']), 0)
99 def test_removing_annotation_by_obj(self):
100 task = self.tw.tasks.get()
101 task.add_annotation('test annotation')
102 ann = task['annotations'][0]
103 task.remove_annotation(ann)
104 self.assertEqual(len(task['annotations']), 0)
107 class UnicodeTest(TasklibTest):
109 def test_unicode_task(self):
110 Task(self.tw, description="†åßk").save()
113 def test_non_unicode_task(self):
114 Task(self.tw, description="test task").save()