コード例 #1
0
def in_memory_repo():
    repo.repo_instance = MemoryRepository()
    read_csv_file(os.path.join(TEST_DATA_PATH, 'movies.csv'),
                  repo.repo_instance)

    with open(os.path.join(TEST_DATA_PATH, 'users.csv'),
              mode='r',
              encoding='utf-8-sig') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if row == 0:
                continue
            repo.repo_instance.add_user(User(row["username"], row['password']))

    with open(os.path.join(TEST_DATA_PATH, 'reviews.csv'),
              mode='r',
              encoding='utf-8-sig') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if row == 0:
                continue
            movie = repo.repo_instance.get_movie(row['title'])
            user = repo.repo_instance.get_user(row['user'])
            review = Review(user, movie, row['comment-text'],
                            float(row['rating']))
            review.time_stamp = row["timestamp"]
            repo.repo_instance.add_review(review)
            movie.review.append(review)
    return repo.repo_instance
コード例 #2
0
ファイル: test_domain_model.py プロジェクト: nbel113/CS235-A2
def test_review():
    movie = Movie("Moana", 2016)
    review_text = "This movie was very enjoyable."
    rating = 8
    review1 = Review(movie, review_text, rating)
    review2 = Review(movie, review_text, rating)
    review3 = Review(movie, review_text, 0)
    review4 = Review(movie, review_text, 11)

    #print(review1.movie)
    #print("Review: {}".format(review1.review_text))
    #print("Rating: {}".format(review1.rating))
    #print("Timestamp1: {}".format(review1.timestamp))
    #print("Timestamp2: {}".format(review2.timestamp))

    #print(review1)
    #print(review2)
    #print(review3)
    #print(review4)
    #print(review1 == review2)

    assert repr(
        review1
    ) == "<Review <Movie Moana, 2016>, This movie was very enjoyable., 8>"
    assert repr(
        review2
    ) == "<Review <Movie Moana, 2016>, This movie was very enjoyable., 8>"
    assert repr(review3) == "<Review None, None, None>"
    assert repr(review4) == "<Review None, None, None>"
    assert review1 == review2
コード例 #3
0
ファイル: test_domain_model.py プロジェクト: nbel113/CS235-A2
def test_user():  # add movie
    user1 = User('  Martin   ', 'pw12345')
    #print(user1.user_name)
    assert user1.user_name == "martin"

    user1 = User('Martin', 'pw12345')
    user2 = User('Ian', 'pw67890')
    user3 = User('Daniel', 'pw87465')

    #print(user1)
    #print(user2)
    #print(user3)

    assert repr(user1) == "<User martin>"
    assert repr(user2) == "<User ian>"
    assert repr(user3) == "<User daniel>"

    movie1 = Movie("Up", 2009)
    movie1.runtime_minutes = 150
    user1.watch_movie(movie1)
    user1.watch_movie(movie1)

    #print("Watched Movies:", user1.watched_movies)
    #print("Watching Time:", user1.time_spent_watching_movies_minutes)

    assert repr(user1.watched_movies) == "[<Movie Up, 2009>]"
    assert user1.time_spent_watching_movies_minutes == 150

    review1 = Review(movie1, "test", 5)
    user1.add_review(review1)
    user1.add_review(review1)

    #print(user1.reviews)
    assert repr(user1.reviews) == "[<Review <Movie Up, 2009>, test, 5>]"
コード例 #4
0
def comment_on_director():
    username = session['username']
    form = CommentForm()
    if form.validate_on_submit():
        title = form.title.data
        review = Review(username, title, form.comment.data, form.rating.data)
        director = repo.repo_instance.get_director(title)
        director.review.append(review)
        try:
            director.rating += review.rating
            director.rating_num += 1
        except:
            pass
        director.add_comment_url = url_for('search_bp.comment_on_director', title=director.director_full_name)
        return redirect(url_for('movies_bp.display_director', title = 'Review_Genre', name= title))

    if request.method == 'GET':
        title = request.args.get('title')
        form.title.data = title
    else:
        title = form.title.data
    director = repo.repo_instance.get_director(title)
    return render_template(
        'search_movie/comment_on_other.html',
        title='Review_Director',
        name=director,
        comment = director.review,
        form=form,
        handler_url=url_for('search_bp.comment_on_director'))
コード例 #5
0
def test_repository_can_add_a_review(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    user = User('Dave', '123456789')
    repo.add_user(user)
    review = Review('Dave', 'Prometheus', None, None, None, '?', 8)
    repo.add_review(review)
    review1 = repo.get_review()[0]
    assert review == review1 and review1 is review
コード例 #6
0
def test_repository_does_not_add_a_review_without_a_movie_properly_attached(
        in_memory_repo):
    user = in_memory_repo.get_user('thorke')
    movie = in_memory_repo.get_movie(2)
    review = Review(None, movie, "Trump's onto it!", 8)

    user.add_review(review)

    with pytest.raises(RepositoryException):
        # Exception expected because the Movie doesn't refer to the Review.
        in_memory_repo.add_review(review)
コード例 #7
0
def edit_review(review: Review, new_review: TempReview):
    edit_occurred = False
    """
    if new_review.movie is None or new_review.movie.title == "":
        print("A1a")
    else:
        print("A2")
        review.movie = new_review.movie
        edit_occurred = True

    if new_review.review_text == "" or new_review.review_text is None:
        print("B1")
    else:
        print("B2")
        review.review_text = new_review.review_text
        edit_occurred = True

    if new_review.rating == "" or new_review.rating is None:
        print("C1")
    else:
        print("C2")
        review.rating = new_review.rating
        edit_occurred = True
    """
    repo_string = get_repo_string()

    if not (new_review.movie is None or new_review.movie.title == ""):
        review.movie = new_review.movie
        edit_occurred = True

    if not (new_review.review_text == "" or new_review.review_text is None):
        review.review_text = new_review.review_text
        edit_occurred = True

    if not (new_review.rating == "" or new_review.rating is None):
        review.rating = new_review.rating
        edit_occurred = True

    if edit_occurred:
        review.latest_edit = new_review.timestamp
コード例 #8
0
ファイル: test_domain_model.py プロジェクト: nbel113/CS235-A2
def test_watching_sim_add_review():
    a = MovieWatchingSimulation()
    movie1 = Movie("Moana", 2016)
    movie2 = Movie("Ice Age", 2002)
    movie3 = Movie("Guardians of the Galaxy", 2012)
    user1 = User('Jack', 'pw12345')
    user2 = User('James', 'pw67890')
    user3 = User('Janice', 'pw87465')
    review1 = Review(movie1, "Was good", 6)
    review2 = Review(movie1, "Average", 5)
    review3 = Review(movie1, "Very Great", 8)
    review4 = Review(movie2, "Great", 7)
    review5 = Review(movie2, "Excellent", 9)
    review6 = Review(movie3, "Boring", 3)

    a.add_movie_review(review1.movie, user1, review1.rating)
    a.add_movie_review(review2.movie, user2, review2.rating)
    a.add_movie_review(review3.movie, user3, review3.rating)
    a.add_movie_review(review4.movie, user1, review4.rating)
    a.add_movie_review(review5.movie, user2, review5.rating)
    a.add_movie_review(review6.movie, user1, review6.rating)
    a.add_movie_review(review4.movie, user1, review4.rating)

    assert a.movie_dict == {
        movie1: [[user1, 6], [user2, 5], [user3, 8]],
        movie2: [[user1, 7], [user2, 9], [user1, 7]],
        movie3: [[user1, 3]]
    }
コード例 #9
0
ファイル: test_domain_model.py プロジェクト: nbel113/CS235-A2
def test_watching_sim_review_average():
    a = MovieWatchingSimulation()
    movie1 = Movie("Moana", 2016)
    movie2 = Movie("Ice Age", 2002)
    movie3 = Movie("Guardians of the Galaxy", 2012)
    user1 = User('Jack', 'pw12345')
    user2 = User('James', 'pw67890')
    user3 = User('Janice', 'pw87465')
    review1 = Review(movie1, "Was good", 6)
    review2 = Review(movie1, "Average", 5)
    review3 = Review(movie1, "Very Great", 8)
    review4 = Review(movie2, "Great", 7)
    review5 = Review(movie2, "Excellent", 9)
    review6 = Review(movie3, "Boring", 3)

    a.add_movie_review(review1.movie, user1, review1.rating)
    a.add_movie_review(review2.movie, user2, review2.rating)
    a.add_movie_review(review3.movie, user3, review3.rating)
    a.add_movie_review(review4.movie, user1, review4.rating)
    a.add_movie_review(review5.movie, user2, review5.rating)
    a.add_movie_review(review6.movie, user1, review6.rating)

    #print(a.get_movie_rating_average(movie1))
    #print(a.get_movie_rating_average(movie2))
    #print(a.get_movie_rating_average(movie3))

    assert a.get_movie_rating_average(movie1) == "Average Rating: 6.33"
    assert a.get_movie_rating_average(movie2) == "Average Rating: 8.0"
    assert a.get_movie_rating_average(movie3) == "Average Rating: 3.0"
コード例 #10
0
def test_repo_can_retrieve_review_count(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title_1 = "Star Trek"
    review_movie_1 = memory_repo.get_review(review_movie_title_1)
    review_text_1 = "Not as good as the original series"
    review_score_1 = 6
    review1 = Review(review_movie_1, review_text_1, review_score_1)

    review_movie_title_2 = "Split"
    review_movie_2 = memory_repo.get_review(review_movie_title_2)
    review_text_2 = "Pretty good"
    review_score_2 = 8
    review2 = Review(review_movie_2, review_text_2, review_score_2)

    memory_repo.add_review(user, review1)
    memory_repo.add_review(user, review2)

    assert len(memory_repo.get_all_reviews()) == 2
コード例 #11
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_can_add_review(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_score = 6
    review = Review(review_movie, review_text, review_score)

    review_services.add_review(user, review)
    assert review in user.reviews
コード例 #12
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_cannot_add_review_with_no_user(memory_repo):
    user = None
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_score = 6
    review = Review(review_movie, review_text, review_score)

    try:
        review_services.add_review(user, review)
        assert review in user.reviews
    except UnknownUserException:
        assert True
コード例 #13
0
ファイル: reviews.py プロジェクト: nbel113/CS235-A3
def create_review():
    error_list = []
    session_user_name = session['user_name']
    user_name = request.args.get('user')
    if 'user_name' not in session:
        return redirect(url_for('home_bp.home'))
    if user_name != session_user_name:
        return redirect(url_for('reviews_bp.reviews_by_user'))

    form = CreateReviewForm()
    repo_inst = repo.repo_instance
    user = repo_inst.get_user(user_name)

    if request.method == 'POST':
        movie_title = str(form.movie_title.data)
        movie = repo_inst.get_movie(str(form.movie_title.data))
        review_text = str(form.review_text.data)
        rating = form.rating.data

        if movie is None:
            if movie_title == "":
                error_list.append('Please provide a movie title for your review.')
            else:
                error_list.append('This is not a movie in the system.')
        if review_text == "":
            error_list.append('Please provide some text for your review.')
        if profanity.contains_profanity(review_text):
            error_list.append('Your review contains profanity.')
        if type(rating) == int:
            if int(rating) < 1 or int(rating) > 10:
                error_list.append('Your review rating is out of range (1-10 inclusive).')
        else:
            error_list.append('Please provide an integer for your review rating.')

        if len(error_list) == 0:
            review = Review(movie, review_text, int(rating))

            repo_inst.add_review(user, review)          #for database
            review_services.add_review(user, review)    #for memory
            return redirect(url_for('reviews_bp.reviews_by_user'))

    return render_template(
        'reviews/create_review.html',
        title='Create Review',
        form=form,
        review_url=url_for('reviews_bp.reviews_by_user'),
        error_list=error_list
    )
コード例 #14
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_can_delete_review(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_rating = 6
    review = Review(review_movie, review_text, review_rating)

    review_services.add_review(user, review)
    review_services.delete_review(new_username, review, memory_repo)

    assert review not in review_services.get_reviews_from_user(
        new_username, memory_repo)
コード例 #15
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_can_get_review_by_user_and_id(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_score = 6
    review = Review(review_movie, review_text, review_score)

    session_user_name = new_username
    review_id = review.review_id

    # Call the service layer to add the comment.
    review_services.add_review(user, review)
    a = review_services.get_review_by_user_and_id(session_user_name, review_id,
                                                  memory_repo)

    assert review is a
コード例 #16
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_can_edit_review_change_none(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_rating = 6
    review = Review(review_movie, review_text, review_rating)

    new_review_movie_title = None
    new_review_movie = memory_repo.get_movie(new_review_movie_title)
    new_review_text = ""
    new_review_rating = None
    new_review = TempReview(new_review_movie, new_review_text,
                            new_review_rating)

    review_services.edit_review(review, new_review)
    assert review.movie == review_movie
    assert review.review_text == review_text
    assert review.rating == review_rating
コード例 #17
0
def comment_on_movie():
    username = session['username']
    form = CommentForm()
    if form.validate_on_submit():
        title = form.title.data
        review = Review(username, title, form.comment.data, form.rating.data)
        movie = repo.repo_instance.get_movie(title)
        movie.review.append(review)
        movie.add_comment_url = url_for('search_bp.comment_on_movie', title=movie.title)
        return redirect(url_for('movies_bp.display_movies', title = 'Review', movie_title= title))
    if request.method == 'GET':
        title = request.args.get('title')
        form.title.data = title
    else:
        title = form.title.data
    movie = repo.repo_instance.get_movie(title)
    return render_template(
        'search_movie/comment_on_movie.html',
        title='Review',
        movie=movie,
        comment = movie.review,
        form=form,
        handler_url=url_for('search_bp.comment_on_movie'))
コード例 #18
0
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, "good movie", 8)

    with pytest.raises(RepositoryException):
        in_memory_repo.add_review(review)
コード例 #19
0
def review1():
    return Review(user, movie, 'Hello World', 29)
コード例 #20
0
def review2():
    return Review(user, movie, 'Hello World', 7)