def test_search(self): from Service.ClientService import ClientService self._ClientService = ClientService() self.assertEqual(self._ClientService.search('1', '2'), [Client('20', 'Mommy')]) self.assertEqual(self._ClientService.search('2', 'M'), [Client('17', 'Michael'), Client('20', 'Mommy')])
def update_client_element(self,clientid,name): """ this function update a client element a client element is created if it is a good one then it is updated otherwise an error is displayed """ client=Client(clientid,name) self.__validClient.validate_client(client) client3=Client(clientid,None) client2=self.__repoClient.search(client3) self.__repoClient.update(client)
def test_Client_class(self): c = Client('1', 'George') with self.assertRaises(DomainError): Client(None, 'Hagi') with self.assertRaises(DomainError): Client('12', None) self.assertEqual(c.clientId, '1') self.assertEqual(c.name, 'George') self.assertEqual(str(c), 'ID = 1, name = George') c1 = Client('20', 'Geo') c2 = Client('1', 'George') self.assertEqual(c == c1, False) self.assertEqual(c == c2, True)
def add_rent(self, rentid, movieid, clientid, rented_date, due_date, returned_date): rent = Rent(rentid, movieid, clientid, rented_date, due_date, returned_date) clientidd = Client(clientid, None) self.__repoClient.search(clientidd) movieid = Movie(movieid, None, None, None) self.__repoMovie.search(movieid) clients = [] l = self.__repoRent.get_all() for i in range(len(l)): if l[i].get_clientid() == rent.get_clientid(): clients.append(l[i]) movies = [] l = self.__repoRent.get_all() for i in range(len(l)): if l[i].get_movieid() == rent.get_movieid(): movies.append(l[i]) self.__validRent.validate_rent(rent, movies, clients) self.__repoRent.add(rent) rent = copy.deepcopy(rent) action = UndoAction(self.__repoRent.remove, self.__repoRent.add, rent, None) self.__undoActions.push(action) self.__redoActions.clear()
def random_client(self, x): n = ["Vlad", "Georgiana", "Ana", "Calin", "Andrei", "Izabella"] for i in range(x): client_id = random.randint(1, 1000) name = n[random.randint(0, int(len(n)) - 1)] client = Client(client_id, name) self.__repoClient.add(client)
def remove_client_element(self,clientid): """ this function create a client element then the client element is verificated if it is a good one then it is removed from the list otherwise an error is displayed """ client=Client(clientid,None) client=self.__repoClient.remove(client)
def add_client_element(self,clientid,name): """ this function create a client element then the cleint element is verificated if it is a good one then it is added to list otherwise an error is displayed """ client=Client(clientid,name) self.__validClient.validate_client(client) self.__repoClient.add(client)
def test_create_client(self): client_id = 22 name = "Dan" client = Client(client_id, name) assert (client.get_clientid() == 22) assert (client.get_name() == "Dan") client.set_clientid(21) assert (client.get_clientid() == 21) client.set_name("Flavius") assert (client.get_name() == "Flavius") self.__client = client
def test_repo_client(self): repo = Repo_movie() assert (repo.number_of_elements() == 0) self.__client = Client(22, "Dan") repo.add(self.__client) assert (repo.number_of_elements() == 1) keyClient = Client(self.__client.get_clientid(), None) foundClient = repo.search(keyClient) assert (foundClient.get_name() == self.__client.get_name()) self.__clientSameid = Client(22, "Alex") try: repo.add(self.__clientSameid) assert (False) except RepoError as re: assert (str(re) == "Existing id!\n") self.__clientDifferentid = Client(10, "Alex") try: repo.search(self.__clientDifferentid) assert (False) except RepoError as re: assert (str(re) == "Inexisting id!\n")
def test_validator_client(self): validatorClient = Validator_client() validatorClient.validate_client(self.__client) self.__clientid = Client(-23, "Dan") self.__clientname = Client(23, "") self.__client = Client(-23, "") try: validatorClient.validate_client(self.__clientid) assert (False) except ValidError as val: assert (str(val) == "Invalid id!\n") try: validatorClient.validate_client(self.__clientname) assert (False) except ValidError as val: assert (str(val) == "Invalid name!\n") try: validatorClient.validate_client(self.__client) assert (False) except ValidError as val: assert (str(val) == "Invalid id!\nInvalid name!\n")
def remove_client_element(self, clientid): """ this function create a client element then the client element is verificated if it is a good one then it is removed from the list otherwise an error is displayed """ client = Client(clientid, None) client = self.__repoClient.remove(client) action = UndoAction(self.__repoClient.add, self.__repoClient.remove, client, None) self.__undoActions.push(action) self.__redoActions.clear()
def add_client_element(self, clientid, name): """ this function create a client element then the cleint element is verificated if it is a good one then it is added to list otherwise an error is displayed """ client = Client(clientid, name) self.__validClient.validate_client(client) self.__repoClient.add(client) action = UndoAction(self.__repoClient.remove, self.__repoClient.add, client, None) self.__undoActions.push(action) self.__redoActions.clear()
def test_functions_undo_redo(self): self.bookS = BookService() self.clientS = ClientService() self.rentalS = RentalService() self.undo_list = [] self.redo_list = [] self._service = Service(self.bookS, self.clientS, self.rentalS) book = Book('121', 'Nope', 'John') client = Client('223', 'Poppy') self._service.book_add(book) self.assertEqual(len(self.bookS.display()), 11) self._service.book_remove(book) self.assertEqual(len(self.bookS.display()), 10) self._service.client_add(client) self.assertEqual(len(self.clientS.display()), 11) self._service.client_remove(client) self.assertEqual(len(self.clientS.display()), 10) rental = Rental('212', '121', '223', ['14', '1', '2018'], ['29', '5', '2019']) rentals = [ Rental('212', '121', '223', ['14', '1', '2018'], ['29', '5', '2019']), Rental('002', '121', '223', ['18', '3', '2014'], ['29', '7', '2019']) ] self._service.rental_add(rental) self.assertEqual(len(self.rentalS.display()), 11) self._service.rental_remove(rental) self.assertEqual(len(self.rentalS.display()), 10) self._service.add_books_rentals(book, rentals) self.assertEqual(len(self.bookS.display()), 11) self.assertEqual(len(self.rentalS.display()), 12) self._service.remove_books_rentals(book, rentals) self.assertEqual(len(self.bookS.display()), 10) self.assertEqual(len(self.rentalS.display()), 10) self._service.add_client_rentals(client, rentals) self.assertEqual(len(self.clientS.display()), 11) self.assertEqual(len(self.rentalS.display()), 12) self._service.remove_client_rentals(client, rentals) self.assertEqual(len(self.clientS.display()), 10) self.assertEqual(len(self.rentalS.display()), 10) b1 = ['121', 'Nope', 'John'] c1 = ['223', 'Poppy'] b = ['121', 'Mommy', 'Lilly'] c = ['223', 'Mark'] self.assertEqual(self._service.book_update_undo(b1, b), b) self.assertEqual(self._service.book_update_redo(b1, b), b1) self.assertEqual(self._service.client_update_undo(c1, c), c) self.assertEqual(self._service.client_update_redo(c1, c), c1)
def testClient(self): self.assertTrue(self.c == Client(1, "Marcel Pavel")) self.assertTrue(self.c.__str__() == "ID: 1 Name = Marcel Pavel") self.assertTrue(self.c.id == 1) self.assertTrue(self.c.name == "Marcel Pavel") self.assertTrue(self.c.__eq__(self.c1))
def initialize(self): self.c = Client(1, "Marcel Pavel") self.c1 = Client(1, "Marcel Pavel")
def test_add(self): from Service.ClientService import ClientService self._ClientService = ClientService() self._ClientService.add('121', 'Johnny') self.assertEqual(self._ClientService.display()[-1], Client('121', 'Johnny'))
def search_client_by_id(self, clientid): client = Client(clientid, None) return self.__repoClient.search(client)
def test_update(self): from Service.ClientService import ClientService self._ClientService = ClientService() self._ClientService.update('11', 'Lilly') self.assertEqual(self._ClientService.display()[0], Client('11', 'Lilly'))