Esempio n. 1
0
    def test_answer_factory(self):
        AnswerFactory.create()

        self.assertEqual(Answer.objects.count(), 1)
        self.assertEqual(Session.objects.count(), 1)
        self.assertEqual(Questionnaire.objects.count(), 1)
        self.assertEqual(Question.objects.count(), 1)
Esempio n. 2
0
    def test_get_all_answers(self):
        q_graph = create_diamond_plus()
        session = SessionFactory.create(questionnaire__graph=q_graph)
        service = SessionService(session)
        service.question_graph_service.refresh_from_db()
        self.assertEqual(len(service.question_graph_service._questions_by_id),
                         7)

        for q in service.question_graph_service._questions:
            AnswerFactory.create(session=session, question=q, payload='answer')
        answers = service._get_all_answers(session)
        self.assertEqual(len(answers), 7)
Esempio n. 3
0
    def setUp(self):
        self.graph = _question_graph_with_decision()
        self.session = SessionFactory.create(questionnaire__graph=self.graph)

        with freeze_time('2021-08-17 12:00:00'):
            AnswerFactory.create(session=self.session,
                                 question=self.graph.first_question,
                                 payload='no')

        with freeze_time('2021-08-17 12:10:00'):
            AnswerFactory.create(session=self.session,
                                 question=self.graph.first_question,
                                 payload='yes')

        self.q2 = Question.objects.get(retrieval_key='q_yes')
        with freeze_time('2021-08-17 12:20:00'):
            AnswerFactory.create(session=self.session,
                                 question=self.q2,
                                 payload='yes happy')
    def test_answer_question_detail_not_allowed(self):
        answer = AnswerFactory.create()

        response = self.client.get(f'{self.base_endpoint}{self.question.uuid}/answer/{answer.pk}')
        self.assertEqual(response.status_code, 404)