Example #1
0
def load_reviews(data_path: str, repo: MemoryRepository, users):
    for data_row in read_csv_file(os.path.join(data_path, 'reviews.csv')):
        review = make_review(review_text=data_row[3],
                             user=users[data_row[1]],
                             movie=repo.get_movie(int(data_row[2])),
                             timestamp=datetime.fromisoformat(data_row[4]))
        repo.add_review(review)
def load_reviews(data_path: str, repo: MemoryRepository, users):
    for data_row in read_csv_file(os.path.join(data_path, 'comments.csv')):
        review = make_review(review_text=data_row[3],
                             user=users[data_row[1]],
                             movie=repo.get_movie(int(data_row[2])),
                             rating=int(data_row[5]))
        repo.add_review(review)
Example #3
0
def test_repository_can_add_a_review(in_memory_repo):
    user = User('aidan', 'hi1234')
    movie = Movie("asdsa", 2014)
    review = make_review("Wow good movie", user, movie, 9)
    in_memory_repo.add_review(review)
    reviews = in_memory_repo.get_reviews()
    assert len(reviews) == 1
    assert review in reviews
Example #4
0
def test_repository_add_review(in_memory_repo):
    user = User('rsin774', 'password')
    movie = Movie('Guardians of the Galaxy', 2014)
    review = make_review(user, movie, "Great!", 10, datetime.now())

    in_memory_repo.add_review(review)

    assert review in in_memory_repo.get_reviews()
Example #5
0
def test_add_and_get_reviews(in_memory_repo):
    assert len(in_memory_repo.get_reviews()) == 0

    review = make_review("Great movie", User("Martin", "pw12345"),
                         Movie("Guardians of the Galaxy", 2014), 8)

    in_memory_repo.add_review(review)
    assert review in in_memory_repo.get_reviews()
Example #6
0
def test_repository_can_add_a_review(in_memory_repo):
    user = in_memory_repo.get_user('thorke')
    movie = in_memory_repo.get_movie(2)
    review = make_review(user, movie, "good film", 8)

    in_memory_repo.add_review(review)

    assert review in in_memory_repo.get_reviews()
Example #7
0
def test_can_get_reviews_for_movie(in_memory_repo):
    movie_id = 1

    # adding review to repo
    user = User("shaun", '12345')
    review = make_review("Wow", user, in_memory_repo.get_movie(1), 10)
    in_memory_repo.add_review(review)

    # testing retrieval of review
    reviews = movies_services.get_reviews_for_movie(movie_id, in_memory_repo)
    assert len(reviews) == 1
    assert reviews[0]["review_text"] == "Wow"
Example #8
0
def add_review(movie_title: str, review_text: str, username: str, rating: int,
               repo: AbstractRepository):
    movie = repo.get_movie(movie_title)
    if movie is None:
        raise NonExistentMovieException

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

    review = make_review(review_text, user, movie, rating)
    repo.add_review(review)
Example #9
0
def add_review(movie_id: int, review_text: str, rating, username: str, repo: AbstractRepository):
    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, user, movie, rating)

    # Update Repo
    repo.add_review(review)
Example #10
0
def test_make_review_establishes_relationships(movie, user):
    review_text = 'good film'
    review = make_review(user, movie, review_text, 8)

    # 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
Example #11
0
def test_repository_can_add_a_review(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    user = User('aidan', 'hi1234')
    movie = Movie("Asdsa", 2014)
    movie.description = "Sam is sam he is"
    movie.director = Director('James')
    movie.runtime_minutes = 140
    review = make_review("Wow good movie", user, movie, 9)

    repo.add_user(user)
    repo.add_movie(movie)
    repo.add_review(review)

    reviews = repo.get_reviews()
    assert len(reviews) == 1
    assert review in reviews
Example #12
0
def add_review(movie_id: int, review_text: str, username: str, rating, 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.
    print(movie)
    review = make_review(user, movie, review_text, rating)

    # Update the repository.
    repo.add_review(review)
Example #13
0
def test_make_review_establishes_relationships(movie, user):
    review_text = "Action packed!"
    rating = 9
    review = make_review(review_text, user, movie, rating)

    # Check that user knows about review
    assert review in user.reviews

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

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

    # Check that review knows about movie
    assert review.movie is movie
Example #14
0
def test_repository_add_review_without_user(in_memory_repo):
    movie = Movie('Guardians of the Galaxy', 2014)
    review = make_review(None, movie, "Great!", 10, datetime.now())

    with pytest.raises(RepositoryException):
        in_memory_repo.add_review(review)
Example #15
0
def review(user, movie):
    return make_review("This movie was very enjoyable.", user, movie, 8)