class DisciplineRepositoryTestCase(unittest.TestCase): ''' unit test for DisciplineRepository ''' def setUp(self): self.repo = DisciplineRepository() d1 = Discipline("maths", "Andrea") d2 = Discipline("physics", "Columban") self.repo.add(d1) self.repo.add(d2) def testAdd(self): d = Discipline("chemistry", "Baiazid") self.repo.add(d) self.assertEqual(len(self.repo), 3) self.assertRaises(DisciplineException, self.repo.add, d) def testFindByName(self): d = self.repo.findByName("maths") self.assertEqual(d, Discipline("maths", "Andrea")) d = self.repo.findByName("js") self.assertEqual(d, None) self.assertTrue(d == None) def testUpdate(self): upD = Discipline("physics", "Huber") self.repo.update("physics", "Huber") d = self.repo.findByName("physics") self.assertEqual(d, upD) def testRemove(self): self.repo.remove("maths") self.assertEqual(len(self.repo), 1) self.assertRaises(DisciplineException, self.repo.remove, "chemistry")
def testGradeController(): graRepo = GradeRepository() disRepo = DisciplineRepository() stuRepo = StudentRepository() undoCtrl = UndoController() ctrl = GradeController(graRepo, disRepo, stuRepo, undoCtrl) assert len(ctrl) == 0 try: ctrl.addStudentToDiscipline("maths", 1) assert False except (DisciplineException, StudentException): assert True try: ctrl.updateGrade("maths", 1, 0) assert False except (DisciplineException, StudentException): assert True try: ctrl.removeStudentFromDiscipline("maths", 1) assert False except (DisciplineException, StudentException): assert True d1 = Discipline("maths", "Andrea") disRepo.add(d1) assert disRepo.findByName("maths") == d1 s1 = Student(1, "Harap-Alb") stuRepo.add(s1) assert stuRepo.findByID(1) == s1 ctrl.addStudentToDiscipline("maths", 1) assert len(ctrl) == 1 try: ctrl.addStudentToDiscipline("maths", 1) assert False except GradeException: assert True try: ctrl.updateGrade("maths", 8, 10) assert False except (GradeException, DisciplineException, StudentException): assert True ctrl.updateGrade("maths", 1, 10) assert len(ctrl) == 1 ctrl.removeStudentFromDiscipline("maths", 1) assert len(ctrl) == 0 try: ctrl.removeStudentFromDiscipline("maths", 1) assert False except GradeException: assert True