예제 #1
0
 def test_post_should_update_answers(self):
     post_data = { "questions": [{ "question_id": self.question_id, "answer": "This is a test - updated"}]}
     response = requests.post("%s/forms/%s/users/%s" % (self.URL, self.form_id, self.user_id), data=json.dumps(post_data))
     self.assertEquals(200, response.status_code)
     item = Table("answers").get_item(form_question_id = Answer.form_question_id(self.form_id, self.question_id),
                                         user_id=self.user_id)
     self.assertEquals("This is a test - updated", item["answer"])
예제 #2
0
 def setUp(self):
     self.user_id = "unit_test"
     self.question_id = uuid.uuid1().hex
     question_data = { "question_id": self.question_id, "type": "essay", "question": "What is difference between unit and functional tests?" }
     Table("questions").put_item(data=question_data)
     self.form_id = uuid.uuid1().hex
     forms_data = { "form_id" : self.form_id, "name" : "Unit testing",
                    "questions" : set([self.question_id])}
     Table("forms").put_item(data=forms_data)
     answer_data = {"form_question_id" : Answer.form_question_id(self.form_id, self.question_id),
                                     "answer": "This is a test",
                                     "user_id" : self.user_id}
     Table("answers").put_item(data=answer_data)
예제 #3
0
 def tearDown(self):
     Table("answers").delete_item(user_id=self.user_id, form_question_id=Answer.form_question_id(self.form_id, self.question_id))
     Table("forms").delete_item(form_id=self.form_id)
     Table("questions").delete_item(question_id=self.question_id)
예제 #4
0
 def update_with_answers(self, user_id):
     answers_table = Table("answers")
     for q in self.questions:
         answer_item = answers_table.get_item(user_id=user_id, form_question_id=Answer.form_question_id(self.id, q.id()))
         q.update_with_answer(answer_item["answer"] if len(answer_item.items()) > 0 else "")