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'
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"
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)})
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
def test_do_not_update_comment_if_is_not_owner(client): result = update_comment(comment['id'], n_user.email, 'blah', now) assert result.raw_result.get('nModified') == 0
def test_do_not_update_comment_if_is_not_owner(client): result = update_comment(comment["id"], n_user.email, "blah", now) assert result.raw_result.get("nModified") == 0