class ClientRepositoryTest(unittest.TestCase): def setUp(self): self.client_repository = ClientRepository() client = Client(1, "Name1") self.client_repository.add_client(client) client = Client(2, "Name2") self.client_repository.add_client(client) def test_client_repository_add_client(self): client = Client(3, "Name3") self.client_repository.add_client(client) client = self.client_repository.get_all_clients() client = client[-1] assert client.id == 3 assert client.name == "Name3" def test_client_repository_remove_client(self): clients_list = self.client_repository.get_all_clients() client = clients_list[-1] assert client.id == 2 self.client_repository.remove_client_by_index(1) client = clients_list[-1] assert client.id == 1 def test_client_repository_update_client(self): clients_list = self.client_repository.get_all_clients() client = clients_list[-1] assert client.id == 2 assert client.name == "Name2" client = Client(10, "New Name") self.client_repository.update_client(1, client) clients_list = self.client_repository.get_all_clients() client = clients_list[-1] assert client.id == 10 assert client.name == "New Name" def test_client_repository_get_next_client_id(self): assert self.client_repository.get_next_client_id() == 1 self.client_repository.increment_last_client_id() assert self.client_repository.get_next_client_id() == 3 def test_client_repository_get_all_clients(self): clients_list = self.client_repository.get_all_clients() assert len(clients_list) == 2 def tearDown(self): del self.client_repository
def remove_client_by_index(self, index): self.__read_all_from_file() ClientRepository.remove_client_by_index(self, index) self.__write_all_to_file()
def remove_client_by_index(self, index): self.__read_all_from_database() client = self.get_all_clients()[index] ClientRepository.remove_client_by_index(self, index) self.__remove_from_database(client.id)