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
def test_repository_can_add_a_user(session_factory): repo = SqlAlchemyRepository(session_factory) user = User('Dave', '123456789') repo.add_user(user) repo.add_user(User('Martin', '123456789')) user2 = repo.get_user('dave') print(user2, user) assert user2 == user and user2 is user
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_does_not_retrieve_a_non_existent_user(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('xXx~qwerty~xXx') assert user is None
def test_repository_can_retrieve_a_user(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('asdfgh') assert user == User('asdfgh', '123Qweasd')