Exemple #1
0
    def test_done_saves_anonymised_qs(self, mockReport):
        self.maxDiff = None

        radio_button_q = RadioButton.objects.create(text="this is a radio button question", page=self.page2)
        for i in range(5):
            Choice.objects.create(text="This is choice %i" % i, question=radio_button_q)
        wizard = EncryptedFormWizard.wizard_factory()()

        PageOneForm = wizard.form_list[0]
        PageTwoForm = wizard.form_list[1]
        KeyForm = wizard.form_list[2]

        page_one = PageOneForm({'question_%i' % self.question1.pk: 'test answer'})
        page_one.is_valid()
        page_two = PageTwoForm({'question_%i' % self.question2.pk: 'another answer to a different question',
                                'question_%i' % radio_button_q.pk: radio_button_q.choice_set.all()[2].pk})
        page_two.is_valid()
        key_form = KeyForm({'key': self.report_key, 'key2': self.report_key})
        key_form.is_valid()

        mock_report = Report()
        mock_report.save = Mock()
        mock_report.owner = self.request.user
        mockReport.return_value = mock_report

        self._get_wizard_response(wizard, form_list=[page_one, page_two, key_form], request=self.request)
Exemple #2
0
 def test_wizard_done_is_called(self, mockReport):
     mock_report = Report()
     mock_report.id = 1
     mock_report.owner = self.request.user
     mockReport.return_value = mock_report
     wizard = EncryptedFormWizard.wizard_factory()()
     PageOneForm = wizard.form_list[0]
     PageTwoForm = wizard.form_list[1]
     KeyForm = wizard.form_list[2]
     page_one = PageOneForm({'question_%i' % self.question1.pk: ""})
     page_one.is_valid()
     page_two = PageTwoForm({'question_%i' % self.question2.pk: ""})
     page_two.is_valid()
     key_form = KeyForm({'key': self.report_key, 'key2': self.report_key})
     key_form.is_valid()
     form_list = [page_one, page_two, key_form]
     wizard.processed_answers = wizard.process_answers(form_list=form_list, form_dict=dict(enumerate(form_list)))
     response = wizard.done(form_list=form_list, form_dict=dict(enumerate(form_list)), request=self.request)
     self.assertContains(response, 1)
    def test_done_saves_anonymised_qs(self, mockEvalRow, mockReport):
        self.maxDiff = None

        radio_button_q = RadioButton.objects.create(
            text="this is a radio button question", page=self.page2)
        for i in range(5):
            Choice.objects.create(text="This is choice %i" % i,
                                  question=radio_button_q)
        wizard = EncryptedFormWizard.wizard_factory()()

        PageOneForm = wizard.form_list[0]
        PageTwoForm = wizard.form_list[1]
        KeyForm = wizard.form_list[2]

        page_one = PageOneForm(
            {'question_%i' % self.question1.pk: 'test answer'})
        page_one.is_valid()
        page_two = PageTwoForm({
            'question_%i' % self.question2.pk:
            'another answer to a different question',
            'question_%i' % radio_button_q.pk:
            radio_button_q.choice_set.all()[2].pk
        })
        page_two.is_valid()
        key_form = KeyForm({'key': self.report_key, 'key2': self.report_key})
        key_form.is_valid()

        mock_report = Report()
        mock_report.save = Mock()
        mock_report.owner = self.request.user
        mockReport.return_value = mock_report

        mock_eval_row = EvalRow()
        mock_eval_row.save = Mock()
        mockEvalRow.return_value = mock_eval_row

        self._get_wizard_response(wizard,
                                  form_list=[page_one, page_two, key_form],
                                  request=self.request)
        mock_eval_row.save.assert_any_call()
 def test_wizard_done_is_called(self, mockReport):
     mock_report = Report()
     mock_report.id = 1
     mock_report.owner = self.request.user
     mockReport.return_value = mock_report
     wizard = EncryptedFormWizard.wizard_factory()()
     PageOneForm = wizard.form_list[0]
     PageTwoForm = wizard.form_list[1]
     KeyForm = wizard.form_list[2]
     page_one = PageOneForm({'question_%i' % self.question1.pk: ""})
     page_one.is_valid()
     page_two = PageTwoForm({'question_%i' % self.question2.pk: ""})
     page_two.is_valid()
     key_form = KeyForm({'key': self.report_key, 'key2': self.report_key})
     key_form.is_valid()
     form_list = [page_one, page_two, key_form]
     wizard.processed_answers = wizard.process_answers(
         form_list=form_list, form_dict=dict(enumerate(form_list)))
     response = wizard.done(form_list=form_list,
                            form_dict=dict(enumerate(form_list)),
                            request=self.request)
     self.assertContains(response, 1)
Exemple #5
0
    def test_done_serializes_questions(self, mockReport):
        self.maxDiff = None

        radio_button_q = RadioButton.objects.create(text="this is a radio button question", page=self.page2)
        for i in range(5):
            Choice.objects.create(text="This is choice %i" % i, question=radio_button_q)
        wizard = EncryptedFormWizard.wizard_factory()()

        PageOneForm = wizard.form_list[0]
        PageTwoForm = wizard.form_list[1]
        KeyForm = wizard.form_list[2]

        page_one = PageOneForm({'question_%i' % self.question1.pk: 'test answer'})
        page_one.is_valid()
        page_two = PageTwoForm({'question_%i' % self.question2.pk: 'another answer to a different question',
                                'question_%i' % radio_button_q.pk: radio_button_q.choice_set.all()[2].pk})
        page_two.is_valid()
        key_form = KeyForm({'key': self.report_key, 'key2': self.report_key})
        key_form.is_valid()

        object_ids = [choice.pk for choice in radio_button_q.choice_set.all()]
        selected_id = object_ids[2]
        object_ids.insert(0, radio_button_q.pk)
        object_ids.insert(0, selected_id)
        object_ids.insert(0, self.question2.pk)
        object_ids.insert(0, self.question1.pk)

        json_report = """[
    { "answer": "test answer",
      "id": %i,
      "section": 1,
      "question_text": "first question",
      "type": "SingleLineText"
    },
    { "answer": "another answer to a different question",
      "id": %i,
      "section": 1,
      "question_text": "2nd question",
      "type": "SingleLineText"
    },
    { "answer": "%i",
      "id": %i,
      "section": 1,
      "question_text": "this is a radio button question",
            "choices": [{"id": %i, "choice_text": "This is choice 0"},
                  {"id": %i, "choice_text": "This is choice 1"},
                  {"id": %i, "choice_text": "This is choice 2"},
                  {"id": %i, "choice_text": "This is choice 3"},
                  {"id": %i, "choice_text": "This is choice 4"}],
      "type": "RadioButton"
    }
  ]""" % tuple(object_ids)

        mock_report = Report()
        mock_report.save = Mock()
        mock_report.owner = self.request.user
        mockReport.return_value = mock_report

        def check_json():
            self.assertEqual(sort_json(mock_report.decrypted_report(self.report_key)),
                             sort_json(json_report))

        mock_report.save.side_effect = check_json

        self._get_wizard_response(wizard, form_list=[page_one, page_two, key_form], request=self.request)
        mock_report.save.assert_any_call()
 def test_reports_have_owners(self):
     report = Report()
     report.owner = self.user
     report.save()
     self.assertIn(report, self.user.report_set.all())
    def test_done_serializes_questions(self, mockReport):
        self.maxDiff = None

        radio_button_q = RadioButton.objects.create(
            text="this is a radio button question", page=self.page2)
        for i in range(5):
            Choice.objects.create(text="This is choice %i" % i,
                                  question=radio_button_q)
        wizard = EncryptedFormWizard.wizard_factory()()

        PageOneForm = wizard.form_list[0]
        PageTwoForm = wizard.form_list[1]
        KeyForm = wizard.form_list[2]

        page_one = PageOneForm(
            {'question_%i' % self.question1.pk: 'test answer'})
        page_one.is_valid()
        page_two = PageTwoForm({
            'question_%i' % self.question2.pk:
            'another answer to a different question',
            'question_%i' % radio_button_q.pk:
            radio_button_q.choice_set.all()[2].pk
        })
        page_two.is_valid()
        key_form = KeyForm({'key': self.report_key, 'key2': self.report_key})
        key_form.is_valid()

        object_ids = [choice.pk for choice in radio_button_q.choice_set.all()]
        selected_id = object_ids[2]
        object_ids.insert(0, radio_button_q.pk)
        object_ids.insert(0, selected_id)
        object_ids.insert(0, self.question2.pk)
        object_ids.insert(0, self.question1.pk)

        json_report = """[
    { "answer": "test answer",
      "id": %i,
      "section": 1,
      "question_text": "first question",
      "type": "SingleLineText"
    },
    { "answer": "another answer to a different question",
      "id": %i,
      "section": 1,
      "question_text": "2nd question",
      "type": "SingleLineText"
    },
    { "answer": "%i",
      "id": %i,
      "section": 1,
      "question_text": "this is a radio button question",
            "choices": [{"id": %i, "choice_text": "This is choice 0"},
                  {"id": %i, "choice_text": "This is choice 1"},
                  {"id": %i, "choice_text": "This is choice 2"},
                  {"id": %i, "choice_text": "This is choice 3"},
                  {"id": %i, "choice_text": "This is choice 4"}],
      "type": "RadioButton"
    }
  ]""" % tuple(object_ids)

        mock_report = Report()
        mock_report.save = Mock()
        mock_report.owner = self.request.user
        mockReport.return_value = mock_report

        def check_json():
            self.assertEqual(
                sort_json(mock_report.decrypted_report(self.report_key)),
                sort_json(json_report))

        mock_report.save.side_effect = check_json

        self._get_wizard_response(wizard,
                                  form_list=[page_one, page_two, key_form],
                                  request=self.request)
        mock_report.save.assert_any_call()
 def test_reports_have_owners(self):
     report = Report()
     report.owner = self.user
     report.save()
     self.assertIn(report, self.user .report_set.all())