def test_can_add_review(in_memory_repo): movie_id = 3 review_text = 'Really Enjoyableeeee!!' user = User('fmercury', 'ASdwdc9') # Call the service layer to add the review. movies_services.add_review(movie_id, review_text, user, in_memory_repo) # Retrieve the reviews for the movie from the repository. reviews_as_dict = movies_services.get_reviews_for_movie( movie_id, in_memory_repo) # Check that the reviews include a review with the new review text. assert next((dictionary['review_text'] for dictionary in reviews_as_dict if dictionary['review_text'] == review_text), None) is not None
def test_get_reviews_for_movie(in_memory_repo): #add a review to movie id 1 movie_id = 1 review_text = 'Really Enjoyableeeee!!' user = User('fmercury', 'ASdwdc9') # Call the service layer to add the review. movies_services.add_review(movie_id, review_text, user, in_memory_repo) reviews_as_dict = movies_services.get_reviews_for_movie(1, in_memory_repo) # Check that 1 review were returned for movie with id 1. assert len(reviews_as_dict) == 1 # Check that the reviews relate to the movie whose id is 1. review_ids = [review['movie_id'] for review in reviews_as_dict] review_ids = set(review_ids) assert 1 in review_ids and len(review_ids) == 1
def test_repository_can_retrieve_movie(in_memory_repo): movie_id = 1 movie = in_memory_repo.get_movie(movie_id) # Check that the Movie has the expected title. assert movie.title == 'Guardians of the Galaxy' # Check that the movie is reviewed as expected. review_text = 'Cool movie!' user = User('fmercury', 'ASdwdc9') review = Review(movie, review_text, 0, user) # Call the service layer to add the review. in_memory_repo.add_review(review, movie, user) review_one = [ review for review in movie.reviews if review.review_text == 'Cool movie!' ][0] assert review_one.user.username == 'fmercury'
def user(): return User('dbowie', '1234567890')
def test_repository_can_add_a_user(in_memory_repo): user = User('Dave', '123456789') in_memory_repo.add_user(user) assert user in in_memory_repo._users assert in_memory_repo.get_user('dave') is user
def test_repository_can_retrieve_a_user(in_memory_repo): user = User('fmercury', '8734gfe2058v') in_memory_repo.add_user(user) user = in_memory_repo.get_user('fmercury') assert user == User('fmercury', '8734gfe2058v')
def test_repository_can_retrieve_a_user(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('fmercury') assert user == User('fmercury', '8734gfe2058v')
def make_user(): user = User("Andrew", "aaa111") return user
def test_repository_add_user(in_memory_repo): user = User('user1', '1234') in_memory_repo.add_user(user) assert in_memory_repo.get_user('user1') is user
def user(): return User('mjackson', 'vpwJv4A7%#9b')