Commit 3c7ef04b authored by Bram Schoenmakers's avatar Bram Schoenmakers

Make DoCommandTest a bit more elaborate.

parent f5d8302b
...@@ -12,19 +12,23 @@ def _no_prompt(self): ...@@ -12,19 +12,23 @@ def _no_prompt(self):
class DoCommandTest(CommandTest.CommandTest): class DoCommandTest(CommandTest.CommandTest):
def setUp(self): def setUp(self):
self.todolist = TodoList.TodoList([]) todos = [
"Foo id:1",
"Bar p:1",
"Baz p:1",
"Recurring! rec:1d",
"x 2014-10-18 Already complete",
]
self.todolist = TodoList.TodoList(todos)
self.today = date.today().isoformat() self.today = date.today().isoformat()
self.todolist.add("Foo id:1")
self.todolist.add("Bar p:1")
self.todolist.add("Baz p:1")
self.todolist.add("Recurring! rec:1d")
self.todolist.add("x 2014-10-18 Already complete")
def test_do1(self): def test_do1(self):
command = DoCommand.DoCommand(["3"], self.todolist, self.out, self.error, _no_prompt) command = DoCommand.DoCommand(["3"], self.todolist, self.out, self.error, _no_prompt)
command.execute() command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(3).is_completed())
self.assertEquals(self.output, "x %s Baz p:1\n" % self.today) self.assertEquals(self.output, "x %s Baz p:1\n" % self.today)
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
...@@ -34,6 +38,11 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -34,6 +38,11 @@ class DoCommandTest(CommandTest.CommandTest):
result = " 2 Bar p:1\n 3 Baz p:1\nx %s Bar p:1\nx %s Baz p:1\nx %s Foo id:1\n" % (self.today, self.today, self.today) result = " 2 Bar p:1\n 3 Baz p:1\nx %s Bar p:1\nx %s Baz p:1\nx %s Foo id:1\n" % (self.today, self.today, self.today)
for number in [1, 2, 3]:
self.assertTrue(self.todolist.todo(number).is_completed())
self.assertTrue(self.todolist.is_dirty())
self.assertFalse(self.todolist.todo(4).is_completed())
self.assertEquals(self.output, result) self.assertEquals(self.output, result)
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
...@@ -43,25 +52,36 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -43,25 +52,36 @@ class DoCommandTest(CommandTest.CommandTest):
result = " 2 Bar p:1\n 3 Baz p:1\nx %s Foo id:1\n" % self.today result = " 2 Bar p:1\n 3 Baz p:1\nx %s Foo id:1\n" % self.today
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(1).is_completed())
self.assertFalse(self.todolist.todo(2).is_completed())
self.assertFalse(self.todolist.todo(3).is_completed())
self.assertEquals(self.output, result) self.assertEquals(self.output, result)
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
def test_recurrence(self): def test_recurrence(self):
command = DoCommand.DoCommand(["4"], self.todolist, self.out, self.error) command = DoCommand.DoCommand(["4"], self.todolist, self.out, self.error)
self.assertFalse(self.todolist.todo(4).has_tag('due'))
command.execute() command.execute()
todo = self.todolist.todo(6)
result = " 6 2014-10-18 Recurring! rec:1d due:2014-10-19\nx 2014-10-18 Recurring! rec:1d\n" result = " 6 2014-10-18 Recurring! rec:1d due:2014-10-19\nx 2014-10-18 Recurring! rec:1d\n"
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, result) self.assertEquals(self.output, result)
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
self.assertEquals(self.todolist.count(), 6) self.assertEquals(self.todolist.count(), 6)
self.assertTrue(self.todolist.todo(4).is_completed()) self.assertTrue(self.todolist.todo(4).is_completed())
self.assertFalse(self.todolist.todo(6).is_completed()) self.assertFalse(todo.is_completed())
self.assertTrue(todo.has_tag('due'))
def test_invalid1(self): def test_invalid1(self):
command = DoCommand.DoCommand(["99"], self.todolist, self.out, self.error) command = DoCommand.DoCommand(["99"], self.todolist, self.out, self.error)
command.execute() command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid todo number given.\n") self.assertEquals(self.errors, "Invalid todo number given.\n")
...@@ -69,6 +89,7 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -69,6 +89,7 @@ class DoCommandTest(CommandTest.CommandTest):
command = DoCommand.DoCommand(["A"], self.todolist, self.out, self.error) command = DoCommand.DoCommand(["A"], self.todolist, self.out, self.error)
command.execute() command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n") self.assertEquals(self.errors, command.usage() + "\n")
...@@ -76,6 +97,7 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -76,6 +97,7 @@ class DoCommandTest(CommandTest.CommandTest):
command = DoCommand.DoCommand(["5"], self.todolist, self.out, self.error) command = DoCommand.DoCommand(["5"], self.todolist, self.out, self.error)
command.execute() command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEquals(self.errors, "Todo has already been completed.\n") self.assertEquals(self.errors, "Todo has already been completed.\n")
...@@ -83,5 +105,6 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -83,5 +105,6 @@ class DoCommandTest(CommandTest.CommandTest):
command = DoCommand.DoCommand([""], self.todolist, self.out, self.error) command = DoCommand.DoCommand([""], self.todolist, self.out, self.error)
command.execute() command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n") self.assertEquals(self.errors, command.usage() + "\n")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment