def test_user_can_retrieve_answers_for_a_interview(self): create_answer(self.interview, self.question, "answer") self.client.force_authenticate(user=self.user) response = self.client.get(self.url, format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(isinstance(response.data, list)) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['question'], self.question.id) self.assertEqual(response.data[0]['content'], "answer")
def test_user_can_delete_answer(self): answer = create_answer(self.interview, self.question, "answer") self.client.force_authenticate(user=self.user) response = self.client.delete(self.url + str(answer.id) + '/', format="json") self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(len(Answer.objects.all()), 0)
def test_user_can_retrieve_answer_detail(self): answer = create_answer(self.interview, self.question, "answer") self.client.force_authenticate(user=self.user) response = self.client.get(self.url + str(answer.id) + '/', format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['question'], self.question.id) self.assertEqual(response.data['content'], "answer")
def create_answers_for_report(report, catalogue, questions, answers): saved_answers = [] for answer in answers: saved_answers.append( create_answer(report, questions[answer["question_index"]], answer["content"], answer["rating"])) report.overall_score = random.randint(40, 99) / 10 report.catalogue = catalogue report.save()
def test_user_can_update_content_patch(self): answer = create_answer(self.interview, self.question, "answer") self.client.force_authenticate(user=self.user) response = self.client.patch(self.url + str(answer.id) + '/', {"content": "updated"}, format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['id'], 1) self.assertEqual(response.data['content'], "updated")
def test_user_can_update_rating_put(self): answer = create_answer(self.interview, self.question, "answer") self.client.force_authenticate(user=self.user) response = self.client.put(self.url + str(answer.id) + '/', { "id": answer.id, "rating": 1, "question": 1 }, format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['id'], 1) self.assertEqual(response.data['content'], "answer") self.assertEqual(response.data['rating'], 1)