Commit 95ec6525 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Prevent adding the same dependency twice.

parent 25162351
...@@ -156,17 +156,18 @@ class TodoList(object): ...@@ -156,17 +156,18 @@ class TodoList(object):
return '%d' % new_id return '%d' % new_id
from_todo = self.todo(p_number1) if not self._depgraph.has_edge(p_number1, p_number2):
to_todo = self.todo(p_number2) from_todo = self.todo(p_number1)
to_todo = self.todo(p_number2)
dep_id = None
if from_todo.has_tag('id'): dep_id = None
dep_id = from_todo.tag_value('id') if from_todo.has_tag('id'):
else: dep_id = from_todo.tag_value('id')
dep_id = find_next_id() else:
dep_id = find_next_id()
to_todo.add_tag('p', dep_id)
self._depgraph.add_edge(p_number1, p_number2, int(dep_id)) to_todo.add_tag('p', dep_id)
self._depgraph.add_edge(p_number1, p_number2, int(dep_id))
def remove_dependency(self, p_number1, p_number2): def remove_dependency(self, p_number1, p_number2):
""" Removes a dependency between two todos. """ """ Removes a dependency between two todos. """
......
...@@ -174,3 +174,9 @@ class TodoListDependencyTester(unittest.TestCase): ...@@ -174,3 +174,9 @@ class TodoListDependencyTester(unittest.TestCase):
children = self.todolist.children(1) children = self.todolist.children(1)
self.assertEqual([todo.source() for todo in children], \ self.assertEqual([todo.source() for todo in children], \
['Bar p:1']) ['Bar p:1'])
def test_add_double_dep(self):
self.todolist.add_dependency(1, 2)
self.assertEqual(self.todolist.todo(1).source(), 'Foo id:1')
self.assertEqual(self.todolist.todo(2).source(), 'Bar p:1')
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