Wayne Werner avatar Wayne Werner committed e150d24

More tests passing!

Comments (0)

Files changed (2)

     type = Column(String)
     status = Column(String)
     assigned_to = Column(String, ForeignKey('users.id'))
-    contact = Column(String, ForeignKey('users.id'))
+    contact = Column(String)
     priority = Column(Integer)
     due = Column(DateTime)
     original_estimate = Column(Integer)
     user = session.query(User).filter_by(id=user_id).first()
     return user
 
-def add_task(desc=None, project=None, session=None):
+def add_task(desc=None, project=None, assigned_to=None, parent_id=None,
+             session=None):
     '''Add a task to Boog Slayer.'''
     if session is None:
         session = make_session()
 
-    proj = session.query(Project).filter_by(name=project).first()
-    if proj is None:
-        raise ValueError("No project with <{0}>".format(project))
+    if parent_id is not None:
+        parent_task = session.query(Task).filter_by(id=parent_id).first()
+        if parent_task is None:
+            raise ValueError("No task with id <{0}>".format(parent_id))
 
-    task = Task(desc=desc)
+    if assigned_to is not None:
+        user = session.query(User).filter_by(name=assigned_to).first()
+        if user is None:
+            raise ValueError("No user with <{0}>".format(user))
+
+    if project is not None:
+        proj = session.query(Project).filter_by(name=project).first()
+        if proj is None:
+            raise ValueError("No project with <{0}>".format(project))
+
+    task = Task(desc=desc,
+                project=project)
     session.add(task)
     session.commit()
     return task
         task = slayer.get_task(id)
         self.assertEqual(expected_desc, task.desc)
 
+    def test_whenAddTaskIsCalledWithProjectThatExistsItShouldBeSet(self):
+        expected_proj = 'Boog Slayer'
+        slayer.add_project(expected_proj)
+        id = slayer.add_task(project=expected_proj).id
+        task = slayer.get_task(id)
+        self.assertEqual(expected_proj, task.project)
+
     def test_whenAddTaskIsCalledWithProjectAndProjectDoesNotExistShouldRaiseValueError(self):
         expected_proj = 'Boog Slayer'
         with self.assertRaises(ValueError):
             slayer.add_task(project=expected_proj)
 
+    def test_whenAddTaskIsCalledWithUserAndUserDoesNotExistShouldRaiseValueError(self):
+        imaginary_user = 'some super cool id'
+        with self.assertRaises(ValueError):
+            slayer.add_task(assigned_to=imaginary_user)
+
+    def test_whenAddTaskIsCalledWithParentCaseThatDoesntExistItShouldRaiseValueError(self):
+        imaginary_task_id = 42
+        with self.assertRaises(ValueError):
+            slayer.add_task(parent_id=imaginary_task_id)
+
     def test_whenGetTaskIsCalledWithIdItShouldReturnTask(self):
         task_id = slayer.add_task(project='default').id
         task = slayer.get_task(task_id=task_id)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.