1
from testtools import TestCase
2
from u1todo import Task, TodoStore, INDEXES, DONE
3
from u1db.backends import inmemory
6
class TodoStoreTestCase(TestCase):
9
super(TodoStoreTestCase, self).setUp()
10
self.db = inmemory.InMemoryDatabase("u1todo")
12
def test_initialize_db(self):
13
"""Creates indexes."""
15
self.assertEqual(INDEXES, dict(self.db.list_indexes()))
17
def test_indexes_are_added(self):
18
"""New indexes are added when a new store is created."""
20
INDEXES['foo'] = ['bar']
21
self.assertNotIn('foo', dict(self.db.list_indexes()))
23
self.assertIn('foo', dict(self.db.list_indexes()))
25
def test_indexes_are_updated(self):
26
"""Indexes are updated when a new store is created."""
28
new_expression = ['newtags']
29
INDEXES['tags'] = new_expression
31
new_expression, dict(self.db.list_indexes())['tags'])
33
self.assertEqual(new_expression, dict(self.db.list_indexes())['tags'])
35
def test_tag_task(self):
36
store = TodoStore(self.db)
39
store.tag_task(task, [tag])
40
self.assertEqual([tag], task.tags)
43
class TaskTestCase(TestCase):
47
super(TaskTestCase, self).setUp()
48
self.db = inmemory.InMemoryDatabase("u1todo")
51
"""Initializing a task generates a doc_id."""
53
self.assertIsNotNone(task.doc_id)
55
def test_set_title(self):
56
"""Changing the title is persistent."""
60
new_task = Task(self.db, doc_id=task.doc_id)
61
self.assertEqual(title, new_task.title)
63
def test_set_done(self):
65
self.assertFalse(task.done)
67
self.assertTrue(task.done)
69
def test_set_done_persists(self):
71
self.assertFalse(task.done)
73
new_task = Task(self.db, doc_id=task.doc_id)
74
self.assertTrue(new_task.done)
77
"""Tags property returns a tuple."""
79
self.assertEqual([], task.tags)
83
task.tags = ["foo", "bar"]
84
self.assertEqual(["foo", "bar"], task.tags)
86
def set_tags_persists(self):
87
"""Tags are saved to the database."""
89
task.tags = ("foo", "bar")
90
new_task = Task(self.db, doc_id=task.doc_id)
91
self.assertEqual(["foo", "bar"], new_task.tags)
93
def test_add_tag(self):
94
"""Tag is added to task's tags."""
97
self.assertEqual(["foo"], task.tags)
99
def test_add_tag_persists(self):
100
"""Tag is saved to the database."""
103
new_task = Task(self.db, doc_id=task.doc_id)
104
self.assertEqual(["foo"], new_task.tags)
106
def test_remove_tag(self):
107
"""Tag is removed from task's tags."""
111
self.assertEqual(["foo", "bar"], task.tags)
112
task.remove_tag("foo")
113
self.assertEqual(["bar"], task.tags)