def test_new_thread_failure(app, authed_client, forum_id, creator_id): with pytest.raises(APIException): ForumThread.new( topic='NewForumThread', forum_id=forum_id, creator_id=creator_id, post_contents='a', )
def test_new_thread(app, authed_client): thread = ForumThread.new(topic='NewForumThread', forum_id=2, creator_id=1, post_contents='aaaa') assert thread.topic == 'NewForumThread' assert thread.forum_id == 2 assert thread.creator_id == 1 assert ForumThread.from_cache(thread.cache_key).id == thread.id == 6 assert len(thread.posts) == 1 assert thread.posts[0].contents == 'aaaa'
def create_thread(topic: str, forum_id: int, contents: str) -> flask.Response: """ This is the endpoint for forum thread creation. The ``forums_threads_modify`` permission is required to access this endpoint. .. :quickref: ForumThread; Create a forum thread. **Example request**: .. parsed-literal:: POST /forums/threads HTTP/1.1 Host: pul.sar Accept: application/json Content-Type: application/json { "topic": "How do I get easy ration?", "forum_id": 4 } **Example response**: .. parsed-literal:: HTTP/1.1 200 OK Vary: Accept Content-Type: application/json { "status": "success", "response": { } } :>json dict response: The newly created forum thread :statuscode 200: Creation successful :statuscode 400: Creation unsuccessful """ return flask.jsonify( ForumThread.new( topic=topic, forum_id=forum_id, creator_id=flask.g.user.id, post_contents=contents, ))
def test_subscribe_users_to_new_thread(app, authed_client): thread = ForumThread.new(topic='aa', forum_id=5, creator_id=1, post_contents='hello') assert ForumThreadSubscription.user_ids_from_thread(thread.id) == [3, 4]