def test_search(self): repo = Repository() undo_service = UndoService() client_service = ClientService(repo, undo_service) client_service.add_client(1, "Popescu Alin") client_service.add_client(2, "Ionescu Maria") client_service.add_client(3, "Trifan Ion") client_service.add_client(4, "Muresan Alina") # by id match = client_service.search_by_id(1) self.assertEqual(match.id, 1) # by name match = client_service.search_by_name("alin") self.assertEqual(match[0].name, "Popescu Alin") self.assertEqual(match[1].name, "Muresan Alina")
def test_most_active_clients(self): repoR = Repository() repoC = Repository() repoM = Repository() undo_service = UndoService() service_client = ClientService(repoC, undo_service) service_client.init_list_clients() service_movie = MovieService(repoM, undo_service) service_movie.init_list_movies() service = RentalService(repoR, repoC, repoM, undo_service) service.init_list_rentals() statistics = StatisticsService(repoC, repoM, repoR) most_active_clients = statistics.most_active_clients() most_active_clients = sorted(most_active_clients, key=lambda rental: rental.days, reverse=True) self.assertEqual(len(most_active_clients), 6) rental_days = most_active_clients[0] owner = service_client.search_by_id(1) self.assertEqual(rental_days.owner, owner) self.assertEqual(rental_days.days, 71)