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_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
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
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
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