def setUp(self): self.db = MockDB() # datetime objects representing dates in the future today = datetime.datetime.today() three_days = today + datetime.timedelta(days=3) seven_days = today + datetime.timedelta(days=7) # fake task one self.hw = Homework('Science Paper', three_days) self.exam = Exam('Science Test', seven_days) # save tasks to mock db self.db.save(self.exam) self.db.save(self.hw)
class TestTaskClass(unittest.TestCase): def setUp(self): self.db = MockDB() # datetime objects representing dates in the future today = datetime.datetime.today() three_days = today + datetime.timedelta(days=3) seven_days = today + datetime.timedelta(days=7) # fake task one self.hw = Homework('Science Paper', three_days) self.exam = Exam('Science Test', seven_days) # save tasks to mock db self.db.save(self.exam) self.db.save(self.hw) def tearDown(self): self.db = None self.exam = None self.hw = None def test_hw(self): self.assertEqual(self.hw.base_score, 3) def test_exam(self): self.assertEqual(self.exam.base_score, 5) def test_get_days_remaining(self): expected_delta = self.exam.due_date.day - self.exam.start_date.day actual_delta = self.exam._get_days_remaining() self.assertEqual(expected_delta, actual_delta) def test_add_days_to_due_date(self): self.assertEqual(self.exam._get_days_remaining(), 7) self.exam.add_days_to_due_date(2) self.assertEqual(self.exam._get_days_remaining(), 9) def test_get_score(self): # before we add any days, first day score = self.exam.get_score() self.assertEqual(score, 8) # extend self.exam.add_days_to_due_date(2) score_after = self.exam.get_score() self.assertEqual(score_after, 6) # add 2 more days ( now 11 days out ) self.exam.add_days_to_due_date(2) score_after = self.exam.get_score() self.assertEqual(score_after, 5) pass