Exemple #1
0
 def test_undo(self):
     """make sure undo works"""
     task = Task("foo bar", autodate=True)
     task.priority = 'a'
     task.do()
     task.do(False)
     self.assertEqual(task.finish, None)
     self.assertEqual(task.done, False)
     self.assertEqual(task.create, date.today())
     self.assertEqual(task.priority, "(A)")
class TestChecklistItemCommon(TestCase):
    """use mocks to handle a simple recurring item, rather than conflating actual ones"""
    def setUp(self):
        self.test_id = "testitem"
        self.test_text = "a test checklist item"
        self.ended = Task(task=self.test_text)
        self.ended.tags={"checklist":"%s_complete" % (self.test_id,)}
        self.ended.do()
        self.half_ended_insane = Task(task=self.test_text)
        self.half_ended_insane.tags={"checklist":"%s_complete" % (self.test_id,)}
        self.half_ended = Task(task=self.test_text)
        self.half_ended.tags={"checklist":"%s" % (self.test_id,)}
        self.half_ended.do()
        self.active = Task(task=self.test_text)
        self.active.tags={"checklist":self.test_id}

    def test_task_ended(self):
        """Base: make sure the task_ended method works"""
        self.assertTrue(ChecklistItem.task_ended(self.ended))
        self.assertFalse(ChecklistItem.task_ended(self.half_ended_insane))
        self.assertFalse(ChecklistItem.task_ended(self.half_ended))
        self.assertFalse(ChecklistItem.task_ended(self.active))

    def test_process_no_history(self):
        """Base: ensure no history is OK"""
        # must have simple schedule next because not implemented...
        class TI(SchedulePasses, ChecklistItem): pass
        i = TI(id=self.test_id, text=self.test_text)
        t = i.process(None)
        self.assertEqual(t.tags['checklist'], self.test_id)
        self.assertEqual(t.task, self.test_text)
        self.assertEqual(t.create, date.today())

    def test_latest_task_active(self):
        """Base: don't do anything if item isn't past-due"""
        class TestItem(PastDueFails, SchedulePasses, ChecklistItem):
            pass
        i = TestItem(id=self.test_id, text=self.test_text)
        self.assertEqual(i.process(self.active), None)

    def test_ended_scheduling(self):
        """Base: test scheduling secanrios with properly ended task"""
        class TestItem(PastDuePasses, SchedulePasses, ChecklistItem):
            pass
        i = TestItem(id=self.test_id, text=self.test_text)
        t = i.process(self.ended)
        self.assertEqual(t.tags['checklist'], self.test_id)
        self.assertEqual(t.task, self.test_text)
        self.assertEqual(t.create, date.today())

        class TestItem(PastDuePasses, ScheduleFails, ChecklistItem):
            pass
        i = TestItem(id=self.test_id, text=self.test_text)
        t = i.process(self.ended)
        self.assertEqual(t,None)

    def test_finish_in_process(self):
        """Base: test that process ends things appropriately"""
        class TestItem(PastDuePasses, SchedulePasses, ChecklistItem):
            pass
        i = TestItem(id=self.test_id, text=self.test_text)
        t = i.process(self.half_ended)
        # assume task_ended works for now... it is tested other places...
        self.assertTrue(i.task_ended(self.half_ended))
        id, status = self.half_ended.tags["checklist"].partition("_")[::2]
        self.assertEquals(status, "complete")
        t = i.process(self.active)
        self.assertTrue(i.task_ended(self.active))
        id, status = self.active.tags["checklist"].partition("_")[::2]
        self.assertEquals(status, "incomplete")
        t = i.process(self.half_ended_insane)
        self.assertTrue(i.task_ended(self.half_ended_insane))
        id, status = self.half_ended_insane.tags["checklist"].partition("_")[::2]
        self.assertEquals(status, "incomplete")
Exemple #3
0
 def test_do(self):
     """make sure do function works"""
     task = Task("foo bar")
     task.do()
     self.assertEqual(task.finish, date.today())
     self.assertEqual(task.done, True)