def remove(self, name): ''' removes a discipline in the DisciplineRepository Input: name - string Output: removes the removed discipline from the file ''' dis = DisciplineRepository.remove(self, name) self._storeToFile() return dis
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")