def test_repository_cannot_add_invalid_review(in_memory_repo): with pytest.raises(RepositoryException): in_memory_repo.add_review(Director('Joe')) with pytest.raises(RepositoryException): in_memory_repo.add_review(Review('', '', 0)) user = User("Martin", "pw12345") movie = Movie('Sing', 2016) review = Review(movie, "This movie was very enjoyable.", 8) review1 = Review(review.movie, review.review_text, review.rating) assert review is not review1 and review.id is not review1.id with pytest.raises(RepositoryException): in_memory_repo.add_review(review) movie.add_review(review) with pytest.raises(RepositoryException): in_memory_repo.add_review(review) review.user = user with pytest.raises(RepositoryException): in_memory_repo.add_review(review) user.add_review(review) with pytest.raises(RepositoryException): in_memory_repo.add_review(review) user.add_review(review1) in_memory_repo.add_review(review1) assert in_memory_repo.get_review(review1.id) is review1
def test_movie_review_relationship(movie, review, user): movie.add_review(review) assert review not in movie.reviews user.add_review(review) assert review in user.reviews assert review in movie.reviews assert review.movie == movie movie.add_review(review) movie2 = Movie('Batman', 1989) movie2.add_review(review) assert review not in movie2.reviews assert review.movie == movie user.remove_review(review) assert review not in user.reviews assert review not in movie.reviews movie.remove_review(review) user2 = User('Ian', 'pw67890') user2.add_review(review) assert review not in user2.reviews assert review.user == user