Пример #1
0
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
Пример #2
0
 def update_client(self, index, new_client):
     self.__read_all_from_file()
     ClientRepository.update_client(self, index, new_client)
     self.__write_all_to_file()
 def update_client(self, index, book):
     self.__read_all_from_database()
     ClientRepository.update_client(self, index, book)
     self.__update_to_database(index, book)