コード例 #1
0
ファイル: test_list.py プロジェクト: william57m/mix-answer
 def setUp(self):
     super().setUp()
     u1 = User(firstname="Fernando",
               lastname="Alonso",
               email="*****@*****.**")
     q1 = Question(
         title="What is the fatest car?",
         body="Which team should I chose to win the F1 world championship?",
         user=u1)
     q2 = Question(
         title="What is the fatest car?",
         body="Which team should I chose to win the F1 world championship?",
         user=u1)
     q3 = Question(
         title="What is the fatest car?",
         body="Which team should I chose to win the F1 world championship?",
         user=u1)
     q4 = Question(
         title="What is the fatest car?",
         body="Which team should I chose to win the F1 world championship?",
         user=u1)
     a1 = Answer(body="Message 1", question=q1, user=u1)
     self.db.add(u1)
     self.db.add(q1)
     self.db.add(q2)
     self.db.add(q3)
     self.db.add(q4)
     self.db.add(a1)
     self.db.commit()
コード例 #2
0
 def setUp(self):
     super().setUp()
     self.u1 = User(firstname="Fernando",
                    lastname="Alonso",
                    email="*****@*****.**")
     self.q1 = Question(
         title="What is the fatest car?",
         body="Which team should I chose to win the F1 world championship?",
         user=self.u1)
     self.q2 = Question(
         title="What is the fatest car?",
         body="Which team should I chose to win the F1 world championship?",
         user=self.u1)
     self.q3 = Question(
         title="What is the fatest car?",
         body="Which team should I chose to win the F1 world championship?",
         user=self.u1)
     self.db.add(self.u1)
     self.db.add(self.q1)
     self.db.add(self.q2)
     self.db.add(self.q3)
     self.db.commit()
     v = VoteQuestion(user_id=self.request_user.id, question_id=self.q3.id)
     self.db.add(v)
     self.db.commit()
コード例 #3
0
ファイル: test_post.py プロジェクト: william57m/mix-answer
 def setUp(self):
     super().setUp()
     u1 = User(firstname="Fernando", lastname="Alonso", email="*****@*****.**")
     self.q1 = Question(title="What is the fatest car?", body="Which team should I chose to win the F1 world championship?", user=u1)
     self.db.add(u1)
     self.db.add(self.q1)
     self.db.commit()
コード例 #4
0
ファイル: test_get.py プロジェクト: william57m/mix-answer
 def setUp(self):
     super().setUp()
     u1 = User(firstname="Fernando", lastname="Alonso", email="*****@*****.**")
     self.q1 = Question(title="What is the fatest car?", body="Which team should I chose to win the F1 world championship?", user=u1, creator_id=self.request_user.id)
     a1 = Answer(body="Message 1", question=self.q1, user=self.request_user, creator_id=self.request_user.id)
     self.db.add(u1)
     self.db.add(self.q1)
     self.db.add(a1)
     self.db.commit()
コード例 #5
0
ファイル: test_put.py プロジェクト: william57m/mix-answer
 def setUp(self):
     super().setUp()
     u1 = User(firstname="Fernando", lastname="Alonso", email="*****@*****.**")
     self.q1 = Question(title="What is the fatest car?", body="Which team should I chose to win the F1 world championship?", user=u1, creator_id=self.request_user.id)
     tag = Tag(label='JavaScript')
     self.db.add(u1)
     self.db.add(tag)
     self.db.add(self.q1)
     self.db.commit()
コード例 #6
0
ファイル: questions.py プロジェクト: william57m/mix-answer
    async def post(self):

        # Create data
        data = json.loads(self.request.body.decode('utf-8'))
        title = check_param(data,
                            name='title',
                            type_param='string',
                            required=True)
        body = check_param(data,
                           name='body',
                           type_param='string',
                           required=True)
        tags = check_param(data, name='tags', type_param='list', required=True)
        if len(tags) < 1:
            raise BadRequestError('At least one tag is required')

        # Add tag
        tags_to_add = []
        for tag_str in tags:
            tag = self.application.db.query(Tag).filter_by(
                label=tag_str).first()
            if tag is None:
                tag = Tag(label=tag_str)
                self.application.db.add(tag)
            tags_to_add.append(tag)

        question = Question(title=title,
                            body=body,
                            user=self.user,
                            tags=tags_to_add)
        self.application.db.add(question)

        # Commit in DB
        try:
            self.application.db.commit()
        except SQLAlchemyError as error:
            self.application.db.rollback()
            raise InternalServerError('Unable to create the question.', error)

        # Returns response
        self.set_status(201)
        self.write({'data': question.to_dict()})
        self.finish()
コード例 #7
0
    def setUp(self):

        super().setUp()
        u = User(firstname='Fernando',
                 lastname='Alonso',
                 email='*****@*****.**')
        self.question = Question(title='Title',
                                 body='Body',
                                 user=u,
                                 creator_id=self.request_user.id)
        self.db.add(u)
        self.db.add(self.question)
        self.db.commit()
コード例 #8
0
 def setUp(self):
     super().setUp()
     self.u1 = User(firstname="Fernando", lastname="Alonso", email="*****@*****.**")
     self.q1 = Question(title="What is the fatest car?", body="Which team should I chose to win the F1 world championship?", user=self.u1)
     self.a1 = Answer(body="Message 1", question=self.q1, user=self.u1)
     self.a2 = Answer(body="Message 1", question=self.q1, user=self.u1)
     self.a3 = Answer(body="Message 1", question=self.q1, user=self.u1, vote_counter=1)
     self.db.add(self.u1)
     self.db.add(self.q1)
     self.db.add(self.a1)
     self.db.add(self.a2)
     self.db.commit()
     v = VoteAnswer(user_id=self.request_user.id, answer_id=self.a3.id)
     self.db.add(v)
     self.db.commit()
コード例 #9
0
def add_data_test(db):

    # Add users
    u1 = User(firstname="Fernando",
              lastname="Alonso",
              email="*****@*****.**")
    u2 = User(firstname="Kimi",
              lastname="Raikkonen",
              email="*****@*****.**")
    db.add(u1)
    db.add(u2)

    # Add tags
    t1 = Tag(label='JavaScript')
    t2 = Tag(label='ReactJS')
    t3 = Tag(label='Weekend')
    t4 = Tag(label='Setup')
    t5 = Tag(label='Docker')
    db.add(t1)
    db.add(t2)
    db.add(t3)
    db.add(t4)
    db.add(t5)

    # Add answers
    a1 = Answer(
        body=
        'Mix Answer has been setup to work with Docker. You just need to install Docker on your machine and follow the instruction, it\'s as easy as that.',
        user=u2,
        vote_counter=2)
    a2 = Answer(body='I confirm, just follow the instructions, it\'s so easy.',
                user=u2)
    a3 = Answer(
        body=
        'There are a lot of popular frameworks today so it\'s difficult to choose. I can recommend you ReactJS, this is the tool used for Mix Answer',
        user=u1)
    db.add(a1)
    db.add(a2)
    db.add(a3)
    db.flush()

    # Add questions
    q1 = Question(
        title='How do you setup Mix Answer?',
        body='I\'m trying to install Mix Answer, what tool do I need?',
        user_id=u1.id,
        answers=[a1, a2],
        tags=[t4, t5],
        vote_counter=1)
    q2 = Question(
        title='What is the best front-end technology?',
        body=
        'I\'d like to create a website but I don\'t know which framework to use',
        user_id=u1.id,
        answers=[a3],
        tags=[t1, t4, t5],
        vote_counter=1)
    q3 = Question(title='What did you plan for this weekend?',
                  body='What are you planning to do this weekend?',
                  user_id=u2.id,
                  tags=[t3])
    db.add(q1)
    db.add(q2)
    db.add(q3)
    db.flush()

    # Add votes
    v1 = VoteAnswer(answer_id=a1.id, user_id=u1.id)
    v2 = VoteAnswer(answer_id=a1.id, user_id=u2.id)
    v3 = VoteQuestion(question_id=q1.id, user_id=u1.id)
    v4 = VoteQuestion(question_id=q2.id, user_id=u2.id)
    db.add(v1)
    db.add(v2)
    db.add(v3)
    db.add(v4)

    # Commit data
    db.commit()
コード例 #10
0
ファイル: test_get.py プロジェクト: william57m/mix-answer
    def setUp(self):
        super().setUp()

        # User
        u1 = User(firstname="Fernando",
                  lastname="Alonso",
                  email="*****@*****.**")
        self.db.add(u1)

        # Questions
        questions = [{
            "title": "What is an apple?",
            "body": "This is the first body?",
            "user": u1
        }, {
            "title": "What is an orange?",
            "body": "This is the second body",
            "user": u1
        }, {
            "title": "What is an ananas?",
            "body": "This is the third body",
            "user": u1
        }, {
            "title": "What is a mango?",
            "body": "This is the fourth body",
            "user": u1
        }, {
            "title": "How taste a banana?",
            "body": "This is the fifth body",
            "user": u1
        }]
        self.questions = []
        for question in questions:
            q = Question(**question)
            self.db.add(q)
            self.questions.append(q)

        # Answer
        answers = [{
            "body": "Message 1",
            "question": self.questions[0],
            "user": u1
        }, {
            "body": "Message 1",
            "question": self.questions[0],
            "user": u1
        }, {
            "body": "Message 1",
            "question": self.questions[1],
            "user": u1
        }, {
            "body": "Message 1",
            "question": self.questions[2],
            "user": u1
        }]
        self.answers = []
        for answer in self.answers:
            a = Answer(**answer)
            self.db.add(a)
            self.answers.append(a)

        self.db.commit()