def post(self, ctx): auth.verify_privilege(ctx.user, 'comments:create') text = ctx.get_param_as_string('text', required=True) post_id = ctx.get_param_as_int('postId', required=True) post = posts.get_post_by_id(post_id) comment = comments.create_comment(ctx.user, post, text) ctx.session.add(comment) ctx.session.commit() return comments.serialize_comment_with_details(comment, ctx.user)
def create_comment(ctx, _params=None): auth.verify_privilege(ctx.user, 'comments:create') text = ctx.get_param_as_string('text', required=True) post_id = ctx.get_param_as_int('postId', required=True) post = posts.get_post_by_id(post_id) comment = comments.create_comment(ctx.user, post, text) ctx.session.add(comment) ctx.session.commit() return _serialize(ctx, comment)
def create_comment(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: auth.verify_privilege(ctx.user, 'comments:create') text = ctx.get_param_as_string('text') post_id = ctx.get_param_as_int('postId') post = posts.get_post_by_id(post_id) comment = comments.create_comment(ctx.user, post, text) ctx.session.add(comment) ctx.session.commit() return _serialize(ctx, comment)
def create_comment( ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: auth.verify_privilege(ctx.user, 'comments:create') text = ctx.get_param_as_string('text') post_id = ctx.get_param_as_int('postId') post = posts.get_post_by_id(post_id) comment = comments.create_comment(ctx.user, post, text) ctx.session.add(comment) ctx.session.commit() return _serialize(ctx, comment)
def test_create_comment(user_factory, post_factory, fake_datetime): user = user_factory() post = post_factory() db.session.add_all([user, post]) with patch("szurubooru.func.comments.update_comment_text"), fake_datetime( "1997-01-01"): comment = comments.create_comment(user, post, "text") assert comment.creation_time == datetime(1997, 1, 1) assert comment.user == user assert comment.post == post comments.update_comment_text.assert_called_once_with(comment, "text")
def test_create_comment(user_factory, post_factory, fake_datetime): user = user_factory() post = post_factory() db.session.add_all([user, post]) with patch('szurubooru.func.comments.update_comment_text'), \ fake_datetime('1997-01-01'): comment = comments.create_comment(user, post, 'text') assert comment.creation_time == datetime(1997, 1, 1) assert comment.user == user assert comment.post == post comments.update_comment_text.assert_called_once_with(comment, 'text')