def update(self, client):
     c = ClientRepository.update(self, client)
     self._saveFile()
     return c
class Test_Client(unittest.TestCase):
    def setUp(self):

        self.__id = 3
        self.__name = "Corina"
        self.__client = Client(self.__id, self.__name)

        self.__meanid = -5
        self.__meanname = ""
        self.__meanclient = Client(self.__meanid, self.__meanname)

        self.__validator = ClientValidator()

        self.__repo = ClientRepository()
        self.__newname = "Korina"
        self.__updateclient = Client(self.__id, self.__newname)

    def tearDown(self):
        unittest.TestCase.tearDown(self)

    def test_model(self):
        self.assertEqual(self.__client.get_id(), self.__id)
        self.assertEqual(self.__client.get_name(), self.__name)
        self.__client.del_name()
        self.__client.set_name("Korina")
        self.assertEqual(self.__client.get_name(), "Korina")

    def test_validator(self):

        try:
            self.__validator.valid_client(self.__client)
            assert True
        except ValidError as ve:
            assert False

        with self.assertRaises(ValidError):
            self.__validator.valid_client(self.__meanclient)

    def test_repo(self):

        self.assertEqual(len(self.__repo), 0)
        self.__repo.add(self.__client)
        self.assertEqual(len(self.__repo), 1)

        with self.assertRaises(RepoError):
            self.__repo.add(self.__client)

        c = Client(5, "Adrian")
        with self.assertRaises(RepoError):
            self.__repo.remove(c)

        try:
            self.__repo.remove(self.__client)
            assert True
        except RepoError as re:
            assert False

        self.__repo.add(self.__client)
        with self.assertRaises(RepoError):
            self.__repo.update(c)

        try:
            self.__repo.update(self.__updateclient)
            assert True
        except RepoError as re:
            assert False

        try:
            assert self.__repo.list() == "ID \t Name \n3 \t Korina\n"
        except RepoError as re:
            assert False

        self.__repo.remove(self.__updateclient)
        with self.assertRaises(RepoError):
            assert self.__repo.list() == "ID \t Name \n"
        self.__repo.add(self.__client)
        self.assertEqual(self.__repo.find(3), self.__client)
        self.assertEqual(self.__repo.find(999), None)
        self.assertEqual(self.__repo.exists_client(self.__client), True)
        self.assertEqual(len(self.__repo.search_id(3)), 1)
        self.assertEqual(len(self.__repo.search_name("rina")), 1)