def update(self, name, newTeacher): ''' updates a discipline in the DisciplineRepository Input: name - string, newTeacher - string Output: updates the updated discipline in the file ''' DisciplineRepository.update(self, name, newTeacher) self._storeToFile()
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")