write tests matching requirements

This commit is contained in:
Fred 2015-09-24 21:21:23 +02:00
parent 2c68fd9a6d
commit ded4a60408
2 changed files with 106 additions and 31 deletions

View File

@ -16,28 +16,26 @@ class Context(models.Model):
return self.name
class Task(models.Model):
PRIORITIES = (
('A', 'Highest'),
('B', 'Medium'),
('C', 'Low')
)
description = models.CharField(max_length=2000)
projects = models.ManyToManyField('Project')
contexts = models.ManyToManyField('Context')
priority = models.CharField(max_length=1, choices=PRIORITIES, null=True)
priority = models.CharField(max_length=1, null=True)
assignee = models.ForeignKey(User)
def getPriority(self):
return self.description[1] if len(self.description) and self.description.startswith('(') else None
def __str__(self):
return self.description
def __buildvars(self, char):
"""
Returns all occurences in the `self.description` field that matches
Returns all occurences in the `self.description` field that matches
the `char` param associated before a single word.
Example:
self.description = "blabla @truc @machin #chose"
self.description = "blabla @truc @machin #chose"
print(self.__buildvars('@'))
>>>> ['truc', 'machin']
"""
@ -45,6 +43,6 @@ class Task(models.Model):
def buildProjects(self):
return self.__buildvars('+')
def buildContexts(self):
return self.__buildvars('@')
return self.__buildvars('@')

View File

@ -1,29 +1,106 @@
from datetime import datetime
from django.test import TestCase
from potatoe.models import Task
class TaskTestCase(TestCase):
def setUp(self):
pass
def setUp(self):
pass
def test_build_task_projects(self):
""" Fetch projects list from the task description """
t = Task()
t.description = "(A) Todo rps blablab +RPS +SharePoint"
projects = t.buildProjects()
def test_build_task_projects(self):
""" Fetch projects list from the task description """
t = Task()
t.description = "(A) Todo rps blablab +RPS +SharePoint"
projects = t.buildProjects()
self.assertIn('RPS', projects)
self.assertIn('SharePoint', projects)
self.assertIn('RPS', projects)
self.assertIn('SharePoint', projects)
def test_build_task_contextes(self):
""" Fetch contexts list from the task description """
t = Task()
t.description = "(B) Todo bidule @brol @machin +RPS"
def test_build_task_contexts(self):
""" Fetch contexts list from the task description """
t = Task()
t.description = "(B) Todo bidule @brol @machin +RPS"
contexts = t.buildContexts()
contexts = t.buildContexts()
self.assertIn('brol', contexts)
self.assertIn('machin', contexts)
self.assertIn('brol', contexts)
self.assertIn('machin', contexts)
def test_contexts_and_projects(self):
"""
Rule 3: Contexts and Projects may appear anywhere in the line after priority/prepended date.
"""
pass
def test_priorities(self):
"""
Rule 1: If priority exists, it ALWAYS appears first.
The priority is an uppercase character from A-Z enclosed in parentheses and followed by a space.
"""
t = Task()
t.description = "Really gotta call Mom (A) @phone @someday"
self.assertIsNone(t.getPriority())
t.description = "(b) Get back to the boss"
self.assertIsNone(t.getPriority())
t.description = "(B)->Submit TPS report"
self.assertIsNone(t.getPriority())
def test_dates(self):
"""
Rule 2: A tasks creation date may optionally appear directly after priority and a space.
If there is no priority, the creation date appears first. If the creation date exists, it should be in the format YYYY-MM-DD.
"""
t = Task()
t.description = "2011-03-02 Document +TodoTxt task format"
self.assertEqual(t.getDate(), datetime(2011, 3, 2))
t.description = "(A) 2011-03-02 Call Mom"
self.assertEqual(t.getdate(), datetime(2011, 3, 2))
t.description = "(A) Call Mom 2011-03-02"
self.assertIsNone(t.getdate(), None)
def tearDown(self):
pass
class TestCompleteTasks(TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_complete_without_date(self):
t = Task()
t.description = "Some task @machin @brol #chose"
t.complete()
self.assertTrue(t.description.startswith('x'))
t.description = "xylophone lesson"
self.assertFalse(t.isComplete())
t.description = "X 2012-01-01 Make resolutions"
self.assertFalse(t.isComplete())
t.description = "(A) x Find ticket prices"
self.assertFalse(t.isComplete())
def test_complete_with_date(self):
t = Task()
t.description = "Some task @machin @brol #chose"
t.complete(True)
self.assertTrue(t.description.startswith('x 2015-09-24'))
def tearDown(self):
pass