Esempio n. 1
0
def test_article_post_question(client, article):
    resp = client.post(f'/article/{article.get_id()}/question/',
                       data=json.dumps({'question': "my question"}),
                       content_type='application/json')

    assert resp.status_code == 200
    assert len(Question.get_many()) == 1
Esempio n. 2
0
 def get_by_owner(self):
     account = Account.get_one(self.owner)
     article_ids = [a.get_id()
                    for a in Article.get_many(user=account['user_id'])]
     questions = []
     for article_id in article_ids:
         questions.extend(
             Question.get_many(article_id=article_id)
         )
     return self.append_article_to_questions(questions)
Esempio n. 3
0
def questions(_id):
    try:
        article = Article.get_one(_id)
    except ValueError as e:
        return response(message=str(e), ok=False), 400

    if not article:
        return response(message=f"Article {_id} not found", ok=False), 400

    return jsonify({
        'data': [q.to_json() for q in Question.get_many(article_id=_id)],
        'ok':
        True
    })
Esempio n. 4
0
    def get_questions(self):
        if self.owner:
            return self.get_by_owner()

        queryset = Question.get_many(**self.args)
        return self.append_article_to_questions(queryset)