Exemplo n.º 1
0
def test_repository_can_retrieve_reviews(in_memory_repo):
    assert len(in_memory_repo.get_reviews()) == 0
    user = User('spooky', 'Spookier9')
    in_memory_repo.add_user(user)
    user = in_memory_repo.get_user('spooky')
    movie = in_memory_repo.get_movie(2)
    review = make_review(review_text="HIGHLY RECOMMEND!", user=user, movie=movie)

    in_memory_repo.add_review(review)
    assert len(in_memory_repo.get_reviews()) == 1
Exemplo n.º 2
0
def test_repository_can_add_a_review(in_memory_repo):
    user = User('spooky', 'Spookier9')
    in_memory_repo.add_user(user)
    user = in_memory_repo.get_user('spooky')
    movie = in_memory_repo.get_movie(2)
    review = make_review(review_text="This was pretty boring", user=user, movie= movie)

    in_memory_repo.add_review(review)

    assert review in in_memory_repo.get_reviews()
Exemplo n.º 3
0
def test_make_review_establishes_relationships(movie, user):
    review_text = 'very bad'
    review = make_review(review_text=review_text, user=user, movie=movie)

    assert review in user.reviews

    assert review.user is user

    assert review in movie.reviews

    assert review.movie is movie
Exemplo n.º 4
0
def test_repository_can_retrieve_reviews(in_memory_repo):
    assert len(in_memory_repo.get_reviews()) == 0
    user = User('wpking', 'Alphadog123')
    in_memory_repo.add_user(user)
    user = in_memory_repo.get_user('wpking')
    movie = in_memory_repo.get_movie(2)
    review = make_review(review_text="This movie was terrible",
                         user=user,
                         movie=movie)

    in_memory_repo.add_review(review)
    assert len(in_memory_repo.get_reviews()) == 1
Exemplo n.º 5
0
def test_repository_can_add_a_review(in_memory_repo):
    user = User('wpking', 'Alphadog123')
    in_memory_repo.add_user(user)
    user = in_memory_repo.get_user('wpking')
    movie = in_memory_repo.get_movie(2)
    review = make_review(review_text="This movie was not entertaining",
                         user=user,
                         movie=movie)

    in_memory_repo.add_review(review)

    assert review in in_memory_repo.get_reviews()
Exemplo n.º 6
0
def test_repository_can_retrieve_reviews(in_memory_repo):
    assert len(in_memory_repo.get_reviews()) == 0
    user = User('Nina', '123456789')
    in_memory_repo.add_user(user)
    user = in_memory_repo.get_user('Nina')
    movie = in_memory_repo.get_movie(2)
    review = make_review(review_text="This movie was average",
                         user=user,
                         movie=movie)

    in_memory_repo.add_review(review)
    assert len(in_memory_repo.get_reviews()) == 1
Exemplo n.º 7
0
def test_make_review_establishes_relationships(movie, user):
    review_text = 'very bad'
    #rating = 1
    review = make_review(review_text=review_text, user=user, movie=movie)

    # Check that the User object knows about the review.
    assert review in user.reviews

    # Check that the review knows about the User.
    assert review.user is user

    # Check that movie knows about the review.
    assert review in movie.reviews

    # Check that the review knows about the movie.
    assert review.movie is movie
Exemplo n.º 8
0
def add_review(movie_id: int, review_text: str, username: str,
               repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(movie_id)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    # Create review.
    review = make_review(review_text=review_text, user=user, movie=movie)

    # Update the repository.
    repo.add_review(review)
    return review_to_dict(review)