def repository(): repo = MemoryRepository() user1 = User("Myles Kennedy", "123") user2 = User("Mark Tremonti", "456") director1 = Director("Taika Waititi") director2 = Director("Steven Speilberg") actor1 = Actor("Chris Pratt") actor2 = Actor("Emma Watson") genre1 = Genre("Comedy") genre2 = Genre("Animation") movie1 = Movie("Moana", 2016) movie2 = Movie("Ice Age", 2002) movie1.director = director1 movie2.director = director2 movie1.add_actor(actor1) movie2.add_actor(actor2) movie1.add_genre(genre1) movie2.add_genre(genre2) review1 = Review(movie1, "very nice", 9) review2 = Review(movie2, "incredible", 10) user1.add_review(review1) user2.add_review(review2) repo.add_movie(movie1) repo.add_movie(movie2) repo.add_director(director1) repo.add_director(director2) repo.add_actor(actor1) repo.add_actor(actor2) repo.add_genre(genre1) repo.add_genre(genre2) repo.add_review(review1) repo.add_review(review2) repo.add_user(user1) repo.add_user(user2) return repo
def test_add_and_get_reviews(session_factory): repository = SqlAlchemyRepository(session_factory) movie1 = repository.get_movie("Moana", 2016) movie2 = repository.get_movie("Inception", 2010) review1 = Review(movie1, "Very good", 8) review2 = Review(movie2, "Excellent", 10) repository.add_review(review1) repository.add_review(review2) assert repository.get_reviews() == [review1, review2]
def load_data(data_path: str, repo: MemoryRepository): reader = MovieFileCSVReader(os.path.join(data_path, 'data1000Movies.csv')) reader.read_csv_file() for actor in reader.dataset_of_actors: repo.add_actor(actor) for movie in reader.dataset_of_movies: repo.add_movie(movie) for actor in movie.actors: for colleague in movie.actors: if not actor.check_if_this_actor_worked_with( colleague) and actor != colleague: actor.add_actor_colleague(colleague) for director in reader.dataset_of_directors: repo.add_director(director) for genre in reader.dataset_of_genres: repo.add_genre(genre) user = User(user_name="Myles Kennedy", password=generate_password_hash("123")) review = Review(repo.get_movie("Inception", 2010), "Absolutely incredible movie!", 10) repo.add_review(review) user.add_review(review) user.watchlist.add_movie(repo.get_movie("The Da Vinci Code", 2006)) user.watchlist.add_movie(repo.get_movie("Moana", 2016)) repo.add_user(user)
def test_reviews_to_dict(repository): review_dicts = services.reviews_to_dict(repository.get_reviews(), repository) assert review_dicts[0]['movie_title'] == "Moana" and review_dicts[0]['movie_release_year'] == 2016 and \ review_dicts[0]['user'] == "Myles Kennedy" and review_dicts[0]['review_text'] == "very nice" and \ review_dicts[0]['rating'] == 9 and len(review_dicts) == 2 review3 = Review(services.get_movie("Moana", 2016, repository), "Not my favourite.", 4) assert services.review_to_dict(review3, repository) is None assert services.review_to_dict("not a review", repository) is None
def add_review(title: str, release_year: int, username: str, review_text: str, rating: int, repo: AbstractRepository): movie = repo.get_movie(title=title, release_year=release_year) if movie is None: raise NonExistentMovieException user = repo.get_user(username=username) if user is None: raise UnknownUserException review = Review(movie, review_text, rating) user.add_review(review) repo.add_review(review)
def test_review_methods(): user1 = "user1" user2 = "user2" movie = Movie("Moana", 2016) review_text = "This movie was very enjoyable." rating = 8 review1 = Review(user1, movie, review_text, rating) movie = Movie("Moana", 2016) review_text = "This movie was very enjoyable." rating = 8 review2 = Review(user1, movie, review_text, rating) movie = Movie("Cats", 2016) review_text = "This movie was very lame." rating = 4 review3 = Review(user2, movie, review_text, rating) assert review1.__eq__(review2) == True assert review1.__eq__(review1) == True assert review1.__eq__(review3) == False
def test_can_add_review(in_memory_repo): movie_id = 1 movie = in_memory_repo.get_movie_by_id(1) review_text = "Hi this is my review" rating = 9 username = "******" password = "******" user = User(username, password) in_memory_repo.add_user(user) movies_services.add_review(movie_id, review_text, rating, username, in_memory_repo) assert Review(username, movie, review_text, rating) in movie.reviews
def add_review(movie_id: int, review_text: str, rating: int, username: str, repo: AbstractRepository): # Check that the movie exists. movie = repo.get_movie_by_id(movie_id) if movie is None: raise NonExistentMovieException user = repo.get_user(username) if user is None: raise UnknownUserException # Create review. review = Review(username, movie, review_text, rating) # Update the repository. user.add_review(review)
def test_save_reviewed_movie(empty_session): # Create Article User objects. movie = make_movie() # Create a new Comment that is bidirectionally linked with the User and Article. review_text = "Some review text." review = Review(movie, review_text, 10) # Save the new Article. empty_session.add(review) empty_session.commit() # Test test_saving_of_article() checks for insertion into the articles table. rows = list(empty_session.execute('SELECT id FROM movies')) movie_key = rows[0][0] # Check that the comments table has a new record that links to the articles and users # tables. rows = list(empty_session.execute('SELECT movie_id, review_text FROM reviews')) assert rows == [(movie_key, review_text)]
def test_saving_of_review(empty_session): movie_key = insert_movie(empty_session) user_key = insert_user(empty_session, ("Andrew", "1234")) rows = empty_session.query(Movie).all() movie = rows[0] user = empty_session.query(User).filter(User._user_name == "Andrew").one() # Create a new Comment that is bidirectionally linked with the User and Article. review_text = "Some review text." review = Review(movie, review_text, 10) user.add_review(review) # Note: if the bidirectional links between the new Comment and the User and # Article objects hadn't been established in memory, they would exist following # committing the addition of the Comment to the database. empty_session.add(review) empty_session.commit() rows = list(empty_session.execute('SELECT user_id, movie_id, review_text FROM reviews')) assert rows == [(user_key, movie_key, review_text)]
def test_user_review_property(): movie1 = Movie("Princess and The Frog", 2009) user1 = User("Jenna da Cruz", "testing123") review1 = Review(movie1, "I loved it", 10) user1.add_review(review1) assert user1.reviews == [review1]
def test_user_add_review(): movie1 = Movie("Princess and The Frog", 2009) review1 = Review(movie1, "I really liked it", 9) user1 = User("Jenna da Cruz", "testing123") user1.add_review(review1) assert user1.reviews == [review1]
def test_review_timestamp_property(): movie1 = Movie("Princess and The Frog", 2009) review1 = Review(movie1, "I really liked it", 9) assert review1.timestamp == datetime.time
def test_review_rating_property(): movie1 = Movie("Princess and The Frog", 2009) review1 = Review(movie1, "I really liked it", 9) assert review1.rating is 9
def test_review_3_false_eq_function(): movie1 = Movie("Princess and The Frog", 2009) review1 = Review(movie1, "I really liked it", 9) review2 = Review(movie1, "I really liked it", 8) assert review1.__eq__(review2) is False
def write_review(self, user, review_text, rating): if type(user) is User and user in self.__users and type(review_text) is str and type(rating) is int \ and 11 > rating >= 0 and self.__movie is not None: review = Review(self.__movie, review_text, rating) user.add_review(review)
def test_add_and_get_reviews(repository): review1 = Review(Movie("Moana", 2016), "Very good", 8) review2 = Review(Movie("Ice Age", 2002), "Excellent", 10) repository.add_review(review1) repository.add_review(review2) assert repository.get_reviews() == [review1, review2]