예제 #1
0
def test_update_comment(client):
    result = update_comment(comment["id"], user.email, "foo foo foo", now)
    assert result.acknowledged is True

    comments = get_movie(movie_id).get("comments")
    assert result.raw_result.get("nModified") == 1
    assert comments[0].get("text") == "foo foo foo"
예제 #2
0
def test_update_comment(client):
    result = update_comment(comment['id'], user.email, 'foo foo foo', now)
    assert result.acknowledged is True

    comments = get_movie(movie_id).get('comments')
    assert result.raw_result.get('nModified') == 1
    assert comments[0].get('text') == 'foo foo foo'
예제 #3
0
파일: movies.py 프로젝트: giokhar/mflix
def api_get_movie_by_id(id):
    movie = get_movie(id)
    if movie is None or movie == {}:
        return jsonify({"error": "not found"}), 400
    else:
        updated_type = str(type(movie.get('lastupdated')))
        return jsonify({"movie": movie, "updated_type": updated_type}), 200
예제 #4
0
def test_add_comment_should_be_implemented(client):
    # we need to add a comment
    # this test serves to do that
    result = add_comment(movie_id, user, comment['text'], now)
    comments = get_movie(movie_id).get('comments')
    assert comments[0].get('_id') == result.inserted_id
    assert comments[0].get('text') == comment['text']
    comment['id'] = result.inserted_id
def test_add_comment_should_be_implemented(client):
    # we need to add a comment
    # this test serves to do that
    result = add_comment(movie_id, user, comment["text"], now)
    comments = get_movie(movie_id).get("comments")
    assert comments[0].get("_id") == result.inserted_id
    assert comments[0].get("text") == comment["text"]
    comment["id"] = result.inserted_id
예제 #6
0
def api_get_movie_by_id(id):
    movie = get_movie(id)
    if movie is None:
        return jsonify({"error": "Not found"}), 400
    elif movie == {}:
        return jsonify({"error": "uncaught general exception"}), 400
    else:
        updated_type = str(type(movie.get('lastupdated')))
        return jsonify({"movie": movie, "updated_type": updated_type}), 200
예제 #7
0
def test_add_comment(client):
    result = add_comment(movie_id, user, comment["text"], now)
    assert isinstance(result, InsertOneResult)
    assert result.acknowledged is True
    assert result.inserted_id is not None

    comments = get_movie(movie_id).get("comments")
    assert comments[0].get("_id") == result.inserted_id
    assert comments[0].get("text") == comment["text"]
    comment["id"] = result.inserted_id
예제 #8
0
def show_movie_comments(id):
    if request.method == 'POST':
        comment = request.form["comment"]

        add_comment_to_movie(ObjectId(id), flask_login.current_user, comment,
                             datetime.now())

        return redirect(url_for('show_movie', id=id))

    comments = get_movie_comments(id)
    num_comments = comments.count()
    movie = get_movie(id)
    if "comments" in movie:
        num_comments += len(movie["comments"])

    return render_template('moviecomments.html',
                           movie=get_movie(id),
                           older_comments=comments,
                           num_comments=comments.count())
예제 #9
0
def test_add_comment(client):
    result = add_comment(movie_id, user, comment['text'], now)
    assert isinstance(result, InsertOneResult)
    assert result.acknowledged is True
    assert result.inserted_id is not None

    comments = get_movie(movie_id).get('comments')
    assert comments[0].get('_id') == result.inserted_id
    assert comments[0].get('text') == comment['text']
    comment['id'] = result.inserted_id
예제 #10
0
파일: movies.py 프로젝트: vedant511/mflix
def api_get_movie_by_id(id):
    movie = get_movie(id)
    if movie is None or movie == {}:
        return jsonify({"status": "fail"}), 400
    else:
        updated_type = str(type(movie.get('lastupdated')))
        return jsonify({
            "status": "success",
            "movie": movie,
            "updated_type": updated_type
        }), 200
def test_add_comment(client):
    result = add_comment(movie_id, user, comment['text'], now)
    assert isinstance(result, InsertOneResult)
    assert result.acknowledged is True
    assert result.inserted_id is not None
    #print("Inserted ID: {}".format(result.inserted_id))
    #print("Type: {}".format(type(result.inserted_id)))
    #print("Raw result: {}".format(dir(result)))

    comments = get_movie(movie_id).get('comments')
    #print(comments)
    assert comments[0].get('_id') == result.inserted_id
    assert comments[0].get('text') == comment['text']
    comment['id'] = result.inserted_id
예제 #12
0
def api_delete_comment():
    """
    Delete a comment. Requires a valid JWT
    """
    claims = get_jwt_claims()
    user_email = User.from_claims(claims).email
    post_data = request.get_json()
    try:
        comment_id = expect(post_data.get('comment_id'), str, 'comment_id')
        movie_id = expect(post_data.get('movie_id'), str, 'movie_id')
        delete_comment(comment_id, user_email)
        updated_comments = get_movie(movie_id).get('comments')
        return jsonify({'comments': updated_comments}), 200
    except Exception as e:
        return jsonify({'error': str(e)}), 400
예제 #13
0
def api_post_comment():
    """
    Posts a comment about a specific movie. Validates the user is logged in by
    ensuring a valid JWT is provided
    """
    claims = get_jwt_claims()
    user = User.from_claims(claims)
    post_data = request.get_json()
    try:
        movie_id = expect(post_data.get('movie_id'), str, 'movie_id')
        comment = expect(post_data.get('comment'), str, 'comment')
        add_comment(movie_id, user, comment, datetime.now())
        updated_comments = get_movie(movie_id).get('comments')
        return jsonify({"comments": updated_comments}), 200
    except Exception as e:
        return jsonify({'error': str(e)}), 400
def test_comments_should_be_sorted_by_date(client):
    # in order from most to least recent
    movie_ids = [
        "573a1391f29313caabcd8414", "573a1392f29313caabcd9d4f",
        "573a1392f29313caabcdae3d", "573a1392f29313caabcdb40b",
        "573a1392f29313caabcdb585", "573a1393f29313caabcdbe7c",
        "573a1393f29313caabcdd6aa"
    ]
    for id in movie_ids:
        comments = get_movie(id).get('comments', [])
        test_comments = sorted(comments[:],
                               key=lambda c: c.get('date'),
                               reverse=True)
        for _ in range(0, min(10, len(comments))):
            rand_int = randint(0, len(comments) - 1)
            assert comments[rand_int] == test_comments[rand_int]
예제 #15
0
def api_update_comment():
    """
    Updates a user comment. Validates the user is logged in by ensuring a
    valid JWT is provided
    """
    claims = get_jwt_claims()
    user_email = User.from_claims(claims).email
    post_data = request.get_json()
    try:
        comment_id = expect(post_data.get('comment_id'), str, 'comment_id')
        updated_comment = expect(post_data.get('updated_comment'), str,
                                 'updated_comment')
        movie_id = expect(post_data.get('movie_id'), str, 'movie_id')
        update_comment(comment_id, user_email, updated_comment, datetime.now())
        updated_comments = get_movie(movie_id).get('comments')
        return jsonify({"status": "success", "comments": updated_comments})
    except Exception as e:
        return jsonify({'status': 'fail', 'error': str(e)})
예제 #16
0
def api_update_comment():
    """
    Updates a user comment. Validates the user is logged in by ensuring a
    valid JWT is provided
    """
    claims = get_jwt_claims()
    user_email = User.from_claims(claims).email
    post_data = request.get_json()
    try:
        comment_id = expect(post_data.get('comment_id'), str, 'comment_id')
        updated_comment = expect(post_data.get('updated_comment'), str,
                                 'updated_comment')
        movie_id = expect(post_data.get('movie_id'), str, 'movie_id')
        edit_result = update_comment(comment_id, user_email, updated_comment,
                                     datetime.now())
        if edit_result.modified_count == 0:
            raise ValueError("no document updated")
        updated_comments = get_movie(movie_id).get('comments')
        return jsonify({"comments": updated_comments}), 200
    except Exception as e:
        return jsonify({'error': str(e)}), 400
예제 #17
0
def test_proper_type(client):
    result = get_movie("573a1391f29313caabcd8526")
    print(type(result.get('lastupdated')))
    assert isinstance(result.get('lastupdated'), datetime)
예제 #18
0
def watch_movie(id):
    return render_template('moviewatch.html', movie=get_movie(id))
def test_search_by_movie_id(client):
    actual = get_movie("573a13eff29313caabdd82f3")
    assert actual['title'] == 'The Martian'
def test_search_by_movie_id(client):
    actual = get_movie("573a13acf29313caabd29647")
    assert actual["title"] == "King Kong"
예제 #21
0
def test_no_error(client):
    response = get_movie("foobar")
    assert response is None
예제 #22
0
def test_fetch_comments_for_movie(client):
    # The Martian
    movie_id = "573a13eff29313caabdd82f3"
    result = get_movie(movie_id)
    assert len(result.get('comments', [])) == 1
예제 #23
0
def show_movie(id):
    return render_template('movie.html',
                           movie=get_movie(id),
                           new_comment=request.form.get("comment"))
예제 #24
0
def test_proper_type(client):
    result = get_movie("573a13b8f29313caabd4c8c5")
    assert isinstance(result.get("lastupdated"), datetime)
예제 #25
0
def test_fetch_comments_for_another_movie(client):
    # 300
    movie_id = "573a13b1f29313caabd36321"
    result = get_movie(movie_id)
    assert len(result.get('comments', [])) == 409
def test_fetch_comments_for_movie(client):
    # Lady and the Tramp
    movie_id = "573a1394f29313caabcdfd61"
    result = get_movie(movie_id)
    assert len(result.get("comments", [])) == 126
def test_fetch_comments_for_movie(client):
    # X-Men
    movie_id = "573a139af29313caabcf0f51"
    result = get_movie(movie_id)
    assert len(result.get('comments', [])) == 432
예제 #28
0
def test_fetch_comments_for_movie(client):
    # Once Upon a Time in Mexico
    movie_id = "573a13a6f29313caabd17bd5"
    result = get_movie(movie_id)
    assert len(result.get('comments', [])) == 2