Ejemplo n.º 1
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()
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
    async def post(self, question_id):

        # Create data
        data = json.loads(self.request.body.decode('utf-8'))
        body = check_param(data,
                           name='body',
                           type_param='string',
                           required=True)
        answer = Answer(body=body, question_id=question_id, user=self.user)

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

        # Returns response
        self.set_status(201)
        self.write({'data': answer.to_dict()})
        self.finish()
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
    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()