Commit 159ee189 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix deletion of todo items by textual ID.

* When using textual IDs, TodoListBase.number() wouldn't return an
  integer, making deletion fail (which expected an int).
* When updating the todo - UID map, erase it first. Otherwise deleted
* items will be still in there.
parent c7b66a4c
......@@ -15,8 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import CommandTest
from topydo.lib.Config import config
from topydo.lib.DeleteCommand import DeleteCommand
from topydo.lib.TodoList import TodoList
from topydo.lib.TodoListBase import InvalidTodoException
class DeleteCommandTest(CommandTest.CommandTest):
def setUp(self):
......@@ -98,6 +100,16 @@ class DeleteCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
def test_del9(self):
""" Test deletion with textual IDs. """
config("test/data/todolist-uid.conf")
command = DeleteCommand(["b0n"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(str(self.todolist), "Foo")
self.assertRaises(InvalidTodoException, self.todolist.todo, 'b0n')
def test_empty(self):
command = DeleteCommand([], self.todolist, self.out, self.error)
command.execute()
......
......@@ -90,7 +90,7 @@ class TodoList(TodoListBase):
def delete(self, p_todo):
""" Deletes a todo item from the list. """
number = self.number(p_todo)
number = self._todos.index(p_todo)
for child in self.children(p_todo):
self.remove_dependency(p_todo, child)
......@@ -98,7 +98,8 @@ class TodoList(TodoListBase):
for parent in self.parents(p_todo):
self.remove_dependency(parent, p_todo)
del self._todos[number - 1]
del self._todos[number]
self._update_todo_ids()
self.dirty = True
......
......@@ -153,8 +153,9 @@ class TodoListBase(object):
def delete(self, p_todo):
""" Deletes a todo item from the list. """
number = self.number(p_todo)
del self._todos[number - 1]
number = self._todos.index(p_todo)
del self._todos[number]
self._update_todo_ids()
self.dirty = True
def erase(self):
......@@ -249,6 +250,9 @@ class TodoListBase(object):
# the idea is to have a hash that is independent of the position of the
# todo. Use the text (without tags) of the todo to keep the id as stable
# as possible (not influenced by priorities or due dates, etc.)
self._todo_id_map = {}
self._id_todo_map = {}
uids = hash_list_values(self._todos, lambda t: hash(t.text()))
for (todo, uid) in uids:
......
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