def test_add_movieSameID_throwsException(self): movie = Movie(1, 'a', '', '') movie_sameID = Movie(1, 'b', '', '') repository = Repository() repository.add(movie) with self.assertRaises(RepositoryError): repository.add(movie_sameID)
def test_updateElement_with1emptyField_elementUpdated1fieldUnchanged(self): repository = Repository() movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') repository.add(movie) repository.update(movie, Movie(1, '', 'a', 'b')) expected_result = Movie(1, 'Frozen', 'a', 'b') self.assertTrue(repository.get_all()[0].identical(expected_result))
def test_updateElement_withAllFields_elementUpdated(self): repository = Repository() movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') repository.add(movie) movieUpdate = Movie(1, '-', '-', '-') repository.update(movie, movieUpdate) self.assertTrue(repository.get_all()[0].identical(movieUpdate))
def update_movie(self, movieId, title, description, genre): ''' Function that, for the movie of given Id, updates its fields with new values, if they are given by user ''' movie = self.repoMovies.search(Movie(movieId, '', '', '')) initial_movie = copy.deepcopy(movie) movie_update = Movie(movieId, title, description, genre) self.repoMovies.update(movie, movie_update) ''' For undo ''' operation = UpdateOperation(self.repoMovies, "Repository.update", initial_movie, movie_update) self.undoStack.push_op(operation) self.redoStack.clear()
def test_setters_movie_changedProperties(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') movie.set_title('Frozen 2') self.assertEqual(movie.get_title(), 'Frozen 2') movie.set_movieId(2) self.assertEqual(2, movie.get_id())
def rent_movie(self, rentalId, movieId, clientId, rentDate, dueDate): # it creates a rental - if movie and client exist # it validates and adds it to the repository for rentals # - the movie must not be already rented (and not returned) # - the client must not have any rented movies past their due date movie = self.repoMovies.search(Movie(movieId, '', '', '')) client = self.repoClients.search(Client(clientId, '')) rentDate = self.get_date(rentDate) dueDate = self.get_date(dueDate) returnDate = Date(0, 0, 0) if dueDate <= rentDate: raise TimelineError( 'Due date must be chronologically after rent-date') rental = Rental(rentalId, movie.get_id(), client.get_id(), rentDate, dueDate, returnDate) rentals = self.get_rentals() self.validRental.validate_rental(rental, rentals) self.repoRentals.add(rental) ''' For undo ''' operation = Operation(self.repoRentals, "Repository.add", "Repository.remove", rental) self.undoStack.push_op(operation) self.redoStack.clear()
def test_specialReplace_elUpdate1EmptyField_1remainsUnchanged(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__movieUpdate_emptyField = Movie(1, 'Frozen 3', '', 'Family') movie.special_replace(self.__movieUpdate_emptyField) self.assertEqual(movie.get_title(), 'Frozen 3') self.assertEqual(movie.get_description(), 'Ice queen with magical powers') self.assertEqual(movie.get_genre(), 'Family')
def test_ServiceAdd_validMovie_isAdded(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__valid_movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__movie_service.add_movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.assertEqual( self.__movie_service.get_movies()[ self.__movie_service.get_number() - 1], self.__valid_movie)
def initialize(self): undoStack = Stack() redoStack = Stack() self.__rental_validator = ValidRental() self.__movies_repository = Repository() self.__clients_repository = Repository() self.__rentals_repository = Repository() self.__service_rentals = ServiceRentals(self.__movies_repository, self.__clients_repository, self.__rentals_repository, self.__rental_validator, undoStack, redoStack) self.__movies_repository.add(Movie(1, 'Frozen', 'Ice', 'Animation')) self.__movies_repository.add( Movie(2, 'Harry Potter', 'Wizard', 'Adventure')) self.__clients_repository.add(Client(1, 'John Doe')) self.__clients_repository.add(Client(2, 'Jane Doe')) self.assertEqual(self.__service_rentals.get_number(), 0)
def test_specialReplace_elUpdateNonemptyFields_allFieldsReplaced(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__movieUpdate = Movie(1, 'Frozen 2', 'Story about sisters', 'Family') movie.special_replace(self.__movieUpdate) self.assertTrue(self.__movieUpdate.identical(movie))
def initialize(self): self.__valid_movie = ValidMovie() self.__valid_client = ValidClient() self.__movies_repository = Repository() self.__clients_repository = Repository() self.__rentals_repository = Repository() undoStack = Stack() redoStack = Stack() self.__service_movies = ServiceMovies(self.__movies_repository, self.__valid_movie, undoStack, redoStack, self.__rentals_repository) self.__service_clients = ServiceClients(self.__clients_repository, self.__valid_client, undoStack, redoStack, self.__rentals_repository) self.__movies_repository.add(Movie(1, 'Frozen', 'Ice', 'Animation')) self.__movies_repository.add( Movie(2, 'Harry Potter', 'Wizard', 'Adventure')) self.__clients_repository.add(Client(1, 'John Doe')) self.__clients_repository.add(Client(2, 'Jane Doe'))
def test_init_movie_getProperties(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__valid_movie = movie self.assertEqual(movie.get_id(), 1) self.assertEqual(movie.get_title(), 'Frozen') self.assertEqual(movie.get_description(), 'Ice queen with magical powers') self.assertEqual(movie.get_genre(), 'Animation')
def add_movie(self, movieId, title, description, genre): ''' Based on the parameters given (id/title/description/genre) - it creates an object 'movie' that belongs in 'Movie' class - it validates the movie - it adds it to the repository ''' movie = Movie(movieId, title, description, genre) self.validMovie.validate_movie(movie) self.repoMovies.add(movie) ''' For the undo''' operation = Operation(self.repoMovies, "Repository.add", "Repository.remove", movie) self.undoStack.push_op(operation) self.redoStack.clear()
def test_ServiceUpdate_movieWith1emptyField_thatFieldIsUnchanged(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__movie_service.add_movie(1, 'Harry Potter', 'Witchcraft', 'Adventure') self.__movie_service.update_movie(1, '', '-', '-') expected = Movie(1, 'Harry Potter', '-', '-') self.assertTrue( self.__movie_service.get_movies()[0].identical(expected))
def late_rentals(self): current_date = datetime.date.today() situation_late_rentals = [] rentals = self.get_rentals() for rental in rentals: if rental.get_returnDate() == Date(0, 0, 0) and rental.get_dueDate( ) <= Date(current_date.day, current_date.month, current_date.year): # it means the movie hasn't been returned, and the due date passed movie_id = rental.get_movieId() movie = self.repoMovies.search(Movie(movie_id, '', '', '')) name = movie.get_title() delay = rental.number_of_days_delayed() situation_late_rentals.append( LateRentals(movie_id, name, delay)) situation_late_rentals.sort(key=lambda x: x.get_delay(), reverse=True) return situation_late_rentals
def test_ServiceUpdate_movieWithAllFields_allFieldsUpdated(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__movie_service.add_movie(1, 'Harry Potter', 'Witchcraft', 'Adventure') self.__movie_service.update_movie(1, 'Harry Potter 2', 'Wizardry', 'Action') expected = Movie(1, 'Harry Potter 2', 'Wizardry', 'Action') self.assertTrue( self.__movie_service.get_movies()[0].identical(expected))
def most_rented(self): situation_movies_rented = {} rentals = self.get_rentals() # Make a dictionary with the movie Id as key, and a list of the number of days rented for each rental of that movie for rental in rentals: movie_id = rental.get_movieId() if movie_id not in situation_movies_rented: situation_movies_rented[movie_id] = 0 situation_movies_rented[movie_id] += rental.number_of_days_rented() result = [] for item in situation_movies_rented.items(): movie = self.repoMovies.search(Movie(item[0], '', '', '')) rented_days = item[1] result.append(MovieRentalDays(movie, rented_days)) result.sort(key=lambda x: x.get_days(), reverse=True) return result
def main() -> None: """"The main function that will recommend movies to the user based on their inputted preferences. """ user_preferences, user_input = main_runner() for i in range(len(user_preferences)): if user_preferences[i] == 'Genre': user_preferences[i] = 'genre' elif user_preferences[i] == 'Release Year': user_preferences[i] = 'release_year' elif user_preferences[i] == 'Language': user_preferences[i] = 'language' else: user_preferences[i] = 'duration' start_year = user_input['release_year'][0] stop_year = user_input['release_year'][1] year_range = set(range(start_year, stop_year)) genre = user_input['genres'] duration_str = user_input['duration'] if duration_str == 'Short(<60 min)': duration_tpl = (41, 60) elif duration_str == 'Medium (60-180 min)': duration_tpl = (60, 181) else: duration_tpl = (181, 809) duration_range = set(range(duration_tpl[0], duration_tpl[1])) language = user_input['language'] user = Movie('user', 'User', year_range, {genre}, duration_range, {language}, 5.0) graph = load_dataset('IMDb movies.csv', user) movies = graph.recommend_movies(user.movie_id, user_preferences) display_recommended_movies(movies)
def remove_movie(self, movieId): ''' Function that removes from the list the movie having the Id given from user ''' complex_operation = ComplexOperation() rentals = self.repoRentals.get_all() for rental in reversed(rentals): if rental.get_movieId() == movieId: self.repoRentals.remove(rental) simple_operation = Operation(self.repoRentals, "Repository.remove", "Repository.add", rental) complex_operation.add_action(simple_operation) movie = self.repoMovies.search(Movie(movieId, '', '', '')) self.repoMovies.remove(movie) operation = Operation(self.repoMovies, "Repository.remove", "Repository.add", movie) complex_operation.add_action(operation) self.undoStack.push_op(complex_operation) self.redoStack.clear()
class TestsFirstFunctionality(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) def test_init_movie_getProperties(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__valid_movie = movie self.assertEqual(movie.get_id(), 1) self.assertEqual(movie.get_title(), 'Frozen') self.assertEqual(movie.get_description(), 'Ice queen with magical powers') self.assertEqual(movie.get_genre(), 'Animation') def test_setters_movie_changedProperties(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') movie.set_title('Frozen 2') self.assertEqual(movie.get_title(), 'Frozen 2') movie.set_movieId(2) self.assertEqual(2, movie.get_id()) def test_str_validMovie_string(self): movie = Movie(1, 'a', 'b', 'c') self.assertEqual( str(movie), "Movie ID: 1" + "\n" + "Title: a" + "\n" + "Description: b" + "\n" + "Genre: c") def test_eq_moviesSameID_True(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__movie_sameID = Movie(1, 'Frozen 2', 'Ice queen with magical powers', 'Kids') self.assertEqual(movie, self.__movie_sameID) def test_specialReplace_elUpdateNonemptyFields_allFieldsReplaced(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__movieUpdate = Movie(1, 'Frozen 2', 'Story about sisters', 'Family') movie.special_replace(self.__movieUpdate) self.assertTrue(self.__movieUpdate.identical(movie)) def test_specialReplace_elUpdate1EmptyField_1remainsUnchanged(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__movieUpdate_emptyField = Movie(1, 'Frozen 3', '', 'Family') movie.special_replace(self.__movieUpdate_emptyField) self.assertEqual(movie.get_title(), 'Frozen 3') self.assertEqual(movie.get_description(), 'Ice queen with magical powers') self.assertEqual(movie.get_genre(), 'Family') def test_identical_identicalMovies_True(self): movie = Movie(1, 'Frozen 2', 'Ice queen with magical powers', 'Animation') self.__valid_movie = movie self.assertTrue(self.__valid_movie.identical(movie)) def test_identical_differentMovies_False(self): movie = Movie(1, 'Frozen', '-', 'Family') self.__valid_movie = Movie(1, 'Frozen 2', 'Ice queen with magical powers', 'Animation') self.assertFalse(self.__valid_movie.identical(movie)) def test_validate_validMovie_None(self): self.__valid_movie = Movie(1, 'a', 'a', 'a') validator = ValidMovie() validator.validate_movie(self.__valid_movie) def test_validate_invalidID_throwsException(self): validator = ValidMovie() self.__movie_invalidID = Movie(-2, 'Lion King', 'Hamlet for kids', 'Animation') with self.assertRaises(ValidationError): validator.validate_movie(self.__movie_invalidID) def test_validate_invalidTitle_throwsException(self): validator = ValidMovie() self.__movie_invalidTitle = Movie(1, '', 'No description', 'Horror') with self.assertRaises(ValidationError): validator.validate_movie(self.__movie_invalidTitle) def test_validate_invalidMovie_throwsException(self): validator = ValidMovie() self.__invalid_movie = Movie(-2, '', '-', 'Drama') with self.assertRaises(ValidationError): validator.validate_movie(self.__invalid_movie) def test_add_newMovie_movieIsAdded(self): movie = Movie(1, 'a', 'a', 'a') repo = Repository() repo.add(movie) self.assertEqual(repo.size(), 1) self.assertEqual(repo.get_all()[repo.size() - 1], movie) def test_add_movieSameID_throwsException(self): movie = Movie(1, 'a', '', '') movie_sameID = Movie(1, 'b', '', '') repository = Repository() repository.add(movie) with self.assertRaises(RepositoryError): repository.add(movie_sameID) def test_ServiceAdd_validMovie_isAdded(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__valid_movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__movie_service.add_movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.assertEqual( self.__movie_service.get_movies()[ self.__movie_service.get_number() - 1], self.__valid_movie) def test_ServiceAdd_invalidId_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) with self.assertRaises(ValidationError): self.__movie_service.add_movie(-1, '-', '-', '-') def test_ServiceAdd_invalidTitle_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) with self.assertRaises(ValidationError): self.__movie_service.add_movie(2, '', '-', '-') def test_ServiceAdd_invalidMovie_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) with self.assertRaises(ValidationError): self.__movie_service.add_movie(-1, '', '-', '-') def test_ServiceAdd_existingId_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__movie_service.add_movie(1, 'a', '', '') with self.assertRaises(RepositoryError): self.__movie_service.add_movie(1, '-', '-', '-') def test_remove_movie_isRemoved(self): repository = Repository() movie = Movie(1, '-', '-', '-') repository.add(movie) repository.remove(movie) self.assertEqual(repository.size(), 0) def test_ServiceRemove_existingMovie_isRemoved(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__movie_service.add_movie(1, '-', '-', '-') self.__movie_service.remove_movie(1) self.assertEqual(self.__movie_service.get_number(), 0) def test_ServiceRemove_inexistentMovie_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() rental_repository = Repository() self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, rental_repository) self.__movie_service.add_movie(1, '-', '-', '-') with self.assertRaises(RepositoryError): self.__movie_service.remove_movie(2) def test_updateElement_withAllFields_elementUpdated(self): repository = Repository() movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') repository.add(movie) movieUpdate = Movie(1, '-', '-', '-') repository.update(movie, movieUpdate) self.assertTrue(repository.get_all()[0].identical(movieUpdate)) def test_updateElement_with1emptyField_elementUpdated1fieldUnchanged(self): repository = Repository() movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') repository.add(movie) repository.update(movie, Movie(1, '', 'a', 'b')) expected_result = Movie(1, 'Frozen', 'a', 'b') self.assertTrue(repository.get_all()[0].identical(expected_result)) def test_ServiceUpdate_movieWithAllFields_allFieldsUpdated(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__movie_service.add_movie(1, 'Harry Potter', 'Witchcraft', 'Adventure') self.__movie_service.update_movie(1, 'Harry Potter 2', 'Wizardry', 'Action') expected = Movie(1, 'Harry Potter 2', 'Wizardry', 'Action') self.assertTrue( self.__movie_service.get_movies()[0].identical(expected)) def test_ServiceUpdate_movieWith1emptyField_thatFieldIsUnchanged(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__movie_service.add_movie(1, 'Harry Potter', 'Witchcraft', 'Adventure') self.__movie_service.update_movie(1, '', '-', '-') expected = Movie(1, 'Harry Potter', '-', '-') self.assertTrue( self.__movie_service.get_movies()[0].identical(expected)) def test_ServiceUpdate_inexistentId_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__movie_validator = ValidMovie() self.__movie_repository = Repository() self.__rental_repository = Repository self.__movie_service = ServiceMovies(self.__movie_repository, self.__movie_validator, undo_stack, redo_stack, self.__rental_repository) self.__movie_service.add_movie(1, 'Harry Potter', 'Witchcraft', 'Adventure') with self.assertRaises(RepositoryError): self.__movie_service.update_movie(2, '', '', '') def test_init_client_getProperties(self): client = Client(1, 'Jonn Doe') self.assertEqual(client.get_id(), 1) self.assertEqual(client.get_name(), 'Jonn Doe') def test_setters_client_changedProperties(self): self.__valid_client = Client(1, '-') self.__valid_client.set_name('John Doe') self.assertEqual(self.__valid_client.get_name(), 'John Doe') self.__valid_client.set_clientId(2) self.assertEqual(self.__valid_client.get_id(), 2) def test_str_validClient_string(self): client = Client(1, 'o') self.assertEqual(str(client), "Client ID: 1" + '\n' + 'Name: o') def test_eq_clientsSameID_True(self): self.__valid_client = Client(1, '-') self.__client_sameID = Client(1, 'Jane Doe') self.assertEqual(self.__valid_client, self.__client_sameID) def test_identical_identicalClients_True(self): client = Client(1, 'John Doe') self.__valid_client = Client(1, 'John Doe') self.assertTrue(self.__valid_client.identical(client)) def test_identical_differentClients_False(self): self.__valid_client = Client(1, '-') client = Client(1, 'Billy') self.assertFalse(self.__valid_client.identical(client)) def test_validate_validClient_None(self): validator = ValidClient() self.__valid_client = Client(1, 'a') validator.validate_client(self.__valid_client) def test_validate_invalidClientID_throwsException(self): validator = ValidClient() self.__client_invalidID = Client(-2, 'Elsa') with self.assertRaises(ValidationError): validator.validate_client(self.__client_invalidID) def test_validate_invalidName_throwsException(self): validator = ValidClient() self.__client_invalidName = Client(1, '') with self.assertRaises(ValidationError): validator.validate_client(self.__client_invalidName) def test_validate_invalidClient_throwsException(self): validator = ValidClient() self.__invalid_client = Client(-2, '') with self.assertRaises(ValidationError): validator.validate_client(self.__invalid_client) def test_ServiceAdd_validClient_isAdded(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) self.__client_service.add_client(1, 'John Doe') self.assertEqual( self.__client_service.get_clients()[ self.__client_service.get_number() - 1], Client(1, 'John Doe')) def test_ServiceAdd_invalidClientId_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) with self.assertRaises(ValidationError): self.__client_service.add_client(-1, '-') def test_ServiceAdd_invalidName_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) with self.assertRaises(ValidationError): self.__client_service.add_client(2, '') def test_ServiceAdd_invalidClient_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) with self.assertRaises(ValidationError): self.__client_service.add_client(-1, '') def test_ServiceAdd_existingClientId_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) self.__client_service.add_client(1, 'o') with self.assertRaises(RepositoryError): self.__client_service.add_client(1, '-') def test_ServiceRemove_existingClient_isRemoved(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) self.__client_service.add_client(1, '-') self.__client_service.remove_client(1) self.assertEqual(self.__client_service.get_number(), 0) def test_ServiceRemove_inexistentClient_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) self.__client_service.add_client(1, '-') with self.assertRaises(RepositoryError): self.__client_service.remove_client(2) def test_ServiceUpdate_client_isUpdated(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) self.__client_service.add_client(1, 'Bob') self.__client_service.update_client(1, 'Billy') self.assertEqual(self.__client_service.get_clients()[0].get_name(), 'Billy') def test_ServiceUpdate_inexistentClientId_throwsException(self): undo_stack = Stack() redo_stack = Stack() self.__rental_repository = Repository() self.__client_validator = ValidClient() self.__client_repository = Repository() self.__client_service = ServiceClients(self.__client_repository, self.__client_validator, undo_stack, redo_stack, self.__rental_repository) self.__client_service.add_client(1, 'Bob') with self.assertRaises(RepositoryError): self.__client_service.update_client(2, '-')
def test_validate_invalidTitle_throwsException(self): validator = ValidMovie() self.__movie_invalidTitle = Movie(1, '', 'No description', 'Horror') with self.assertRaises(ValidationError): validator.validate_movie(self.__movie_invalidTitle)
def test_validate_invalidID_throwsException(self): validator = ValidMovie() self.__movie_invalidID = Movie(-2, 'Lion King', 'Hamlet for kids', 'Animation') with self.assertRaises(ValidationError): validator.validate_movie(self.__movie_invalidID)
def test_validate_validMovie_None(self): self.__valid_movie = Movie(1, 'a', 'a', 'a') validator = ValidMovie() validator.validate_movie(self.__valid_movie)
def test(self): valid_movie = ValidMovie() valid_client = ValidClient() valid_rental = ValidRental() repository_movie = Repository() repository_client = Repository() repository_rental = Repository() undo_stack = Stack() redo_stack = Stack() service_movie = ServiceMovies(repository_movie, valid_movie, undo_stack, redo_stack, repository_rental) service_client = ServiceClients(repository_client, valid_client, undo_stack, redo_stack, repository_rental) service_rental = ServiceRentals(repository_movie, repository_client, repository_rental, valid_rental, undo_stack, redo_stack) service_undo = ServiceUndo(undo_stack, redo_stack) service_undo.clear() service_movie.add_movie(1, 'a', 'a', 'a') service_undo.undo() self.assertEqual(0, service_movie.get_number()) service_undo.redo() self.assertEqual(service_movie.get_movies()[0], Movie(1, 'a', 'a', 'a')) service_client.add_client(1, 'a') service_undo.undo() self.assertEqual(0, service_client.get_number()) service_undo.redo() self.assertEqual(service_client.get_clients()[0], Client(1, 'a')) with self.assertRaises(UndoError): service_undo.redo() service_client.update_client(1, 'b') service_undo.undo() self.assertEqual(service_client.get_clients()[0].get_name(), 'a') service_undo.redo() self.assertEqual(service_client.get_clients()[0].get_name(), 'b') service_rental.rent_movie(1, 1, 1, '1/1/1', '2/2/2') service_client.remove_client(1) self.assertEqual(service_rental.get_number(), 0) self.assertEqual(service_client.get_number(), 0) service_undo.undo() self.assertEqual(service_rental.get_number(), 1) self.assertEqual(service_client.get_number(), 1) service_undo.redo() self.assertEqual(service_rental.get_number(), 0) self.assertEqual(service_client.get_number(), 0) service_client.add_client(1, 'a') service_rental.rent_movie(1, 1, 1, '1/1/1', '2/2/2') service_undo.undo() self.assertEqual(service_rental.get_number(), 0) service_undo.redo() self.assertEqual( service_rental.get_rentals()[0], Rental(1, 1, 1, Date(1, 1, 1), Date(2, 2, 2), Date(0, 0, 0))) service_rental.return_movie(1, '3/3/3') service_undo.undo() self.assertEqual(service_rental.get_rentals()[0].get_returnDate(), Date(0, 0, 0)) service_undo.redo() self.assertEqual(service_rental.get_rentals()[0].get_returnDate(), Date(3, 3, 3))
def test_identical_differentMovies_False(self): movie = Movie(1, 'Frozen', '-', 'Family') self.__valid_movie = Movie(1, 'Frozen 2', 'Ice queen with magical powers', 'Animation') self.assertFalse(self.__valid_movie.identical(movie))
def test_searchMovie_validKey_returnsMovies(self): self.initialize() found_movies = self.__service_movies.search_movie('otter') expected_result = Movie(2, 'Harry Potter', 'Wizard', 'Adventure') self.assertEqual(expected_result, found_movies[0])
def test_identical_identicalMovies_True(self): movie = Movie(1, 'Frozen 2', 'Ice queen with magical powers', 'Animation') self.__valid_movie = movie self.assertTrue(self.__valid_movie.identical(movie))
def test_validate_invalidMovie_throwsException(self): validator = ValidMovie() self.__invalid_movie = Movie(-2, '', '-', 'Drama') with self.assertRaises(ValidationError): validator.validate_movie(self.__invalid_movie)
def test_add_newMovie_movieIsAdded(self): movie = Movie(1, 'a', 'a', 'a') repo = Repository() repo.add(movie) self.assertEqual(repo.size(), 1) self.assertEqual(repo.get_all()[repo.size() - 1], movie)
def test_eq_moviesSameID_True(self): movie = Movie(1, 'Frozen', 'Ice queen with magical powers', 'Animation') self.__movie_sameID = Movie(1, 'Frozen 2', 'Ice queen with magical powers', 'Kids') self.assertEqual(movie, self.__movie_sameID)