def test_repository_can_add_and_get_review(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('asdfgh') movie = repo.get_movie("Moana") review_text = "This movie was very enjoyable." rating = 8 review = Review(movie, review_text, rating) repo.add_review(user, review) assert repo.get_review_by_user_and_id(user.user_name, review.reviewID, repo) is review
def test_repository_can_delete_review(session_factory): repo = SqlAlchemyRepository(session_factory) user1 = repo.get_user('asdfgh') movie1 = repo.get_movie("Fury") movie2 = repo.get_movie("Star Trek") review_text = "This movie was very enjoyable." rating = 8 review1 = Review(movie1, review_text, rating) review2 = Review(movie2, review_text, rating) repo.add_review(user1, review1) repo.add_review(user1, review2) assert len(user1.reviews) == 2 repo.delete_review(user1.user_name, review1, repo) assert len(user1.reviews) == 1
def test_repository_can_retrieve_reviews_from_user(session_factory): repo = SqlAlchemyRepository(session_factory) user1 = repo.get_user('asdfgh') user2 = repo.get_user('zxcvbn') movie1 = repo.get_movie("Fury") movie2 = repo.get_movie("Star Trek") review_text = "This movie was very enjoyable." rating = 8 review1 = Review(movie1, review_text, rating) review2 = Review(movie2, review_text, rating) review3 = Review(movie1, review_text, rating) review4 = Review(movie2, review_text, rating) review5 = Review(movie2, "meh", rating) repo.add_review(user1, review1) repo.add_review(user1, review2) repo.add_review(user2, review3) repo.add_review(user2, review4) repo.add_review(user2, review5) assert len(repo.get_reviews_from_user("asdfgh", repo)) == 2 assert len(repo.get_reviews_from_user("zxcvbn", repo)) == 3