def test_repository_does_not_add_a_comment_without_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    movie = repo.get_movie(2)
    review = Review(movie, 'LOL', None, None)

    with pytest.raises(RepositoryException):
        repo.add_review(review)
def add_review(movie_id: int, review_text: str, user: User,
               repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(movie_id)
    rating = 0
    review = Review(movie, review_text, rating, user)

    # Update the repository.
    repo.add_review(review, movie, user)
def test_repository_does_not_add_a_review_without_an_movie_properly_attached(in_memory_repo):
    user = in_memory_repo.get_user('thorke')
    movie = in_memory_repo.get_movie(2)
    review = Review(user,movie,"Trump's onto it!",5)

    user.add_review(review)

    with pytest.raises(RepositoryException):
        # Exception expected because the Article doesn't refer to the Comment.
        in_memory_repo.add_review(review)
Beispiel #4
0
def test_repository_does_not_add_a_comment_without_an_movie_properly_attached(
        in_memory_repo):
    user = in_memory_repo.get_user('thorke')
    movie = in_memory_repo.get_movie(2)
    comment = Review(None, movie, "Trump's onto it!", datetime.today())

    user.add_review(comment)

    with pytest.raises(RepositoryException):
        # Exception expected because the Article doesn't refer to the Comment.
        in_memory_repo.add_review(comment)
Beispiel #5
0
def recommend():
    import movie.home.recommandation as recommandation

    choosed = recommandation.main()

    if request.method == "POST":

        movie_name = request.form["movie_name"]
        movie_id = request.form["movie_id"]
        rtext = request.form["rtext"]
        rating = request.form["rating"]

        movie = Movie(movie_name, 1990, int(movie_id))
        review = Review(movie, rtext, int(rating))
        rc_reviews.append(review)

    return render_template("recommend.html", choosed=choosed)
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 test_repository_does_not_add_a_review_without_a_user(in_memory_repo):
    movie = in_memory_repo.get_movie(2)
    review = Review(None, movie, "Trump's onto it!", 5)

    with pytest.raises(RepositoryException):
        in_memory_repo.add_review(review)
Beispiel #8
0
def review():
    m = Movie('matrix', 1998, 1)
    return Review(m, 'good movie!', 5)
Beispiel #9
0
def test_repository_does_not_add_a_comment_without_a_user(in_memory_repo):
    article = in_memory_repo.get_movie(2)
    comment = Review(None, article, "Trump's onto it!", datetime.today())

    with pytest.raises(RepositoryException):
        in_memory_repo.add_review(comment)