Commit 242c169e authored by Bram Schoenmakers's avatar Bram Schoenmakers

Recalculate text ID when the text changes.

This fixes a bug that occurred with the combination of text IDs and
appending projects of the parent todo item.

When adding the project to a child todo, the text ID was not updated,
and the standard output would show an outdated text ID. The next
invocation of topydo would show the correct ID.

Now the ID is consistent between adding and listing.
parent fd5c1164
......@@ -17,6 +17,7 @@
from datetime import date
from topydo.lib import AddCommand
from topydo.lib import ListCommand
import CommandTest
from topydo.lib.Config import config
from topydo.lib import TodoList
......@@ -170,6 +171,26 @@ class AddCommandTest(CommandTest.CommandTest):
self.assertEquals(self.todolist.todo('tpi').source(), "{} Foo p:1".format(self.today))
self.assertEquals(self.todolist.todo('b0n').source(), "{} Bar id:1".format(self.today))
def test_add_dep9(self):
"""
The text ID shown after adding and after an 'ls' must be equal."
By appending the parent's projects, the textual ID may change.
"""
config("test/data/todolist-uid-projects.conf")
# pass identitiy function to for writing output, we're not interested
# in this output
command = AddCommand.AddCommand(["Foo +Project"], self.todolist, lambda t: t, self.error)
command.execute()
command = AddCommand.AddCommand(["Bar before:eqk"], self.todolist, self.out, self.error)
command.execute()
command = ListCommand.ListCommand(["Bar"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "|5dh| {today} Bar p:1 +Project\n|5dh| {today} Bar p:1 +Project\n".format(today=self.today))
def test_add_reldate1(self):
command = AddCommand.AddCommand(["Foo due:today"], self.todolist, self.out, self.error)
command.execute()
......
......@@ -220,6 +220,15 @@ class TodoListTester(TopydoTest):
config("test/data/todolist-uid.conf")
self.assertRaises(InvalidTodoException, self.todolist.todo, 1)
def test_new_uid(self):
""" Make sure that item has new text ID after append. """
config("test/data/todolist-uid.conf")
todo = self.todolist.todo('6iu')
self.todolist.append(todo, "A")
self.assertNotEquals(self.todolist.number(todo), '6iu')
class TodoListDependencyTester(TopydoTest):
def setUp(self):
super(TodoListDependencyTester, self).setUp()
......
......@@ -175,6 +175,7 @@ class TodoListBase(object):
if len(p_string) > 0:
new_text = p_todo.source() + ' ' + p_string
p_todo.set_source_text(new_text)
self._update_todo_ids()
self.dirty = True
def projects(self):
......
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