def test_is_empty(self):
        questions = [
            Question({
                'id': 'q1',
                'name': 'q1',
                'type': 'unknown'
            }),
            Question({
                'id': 'q2',
                'name': 'q2',
                'type': 'unknown'
            })
        ]  # note that id and type are required as this function indirectly calls QuestionSummary.value

        section = ContentSection(slug='section',
                                 name=TemplateField('Section'),
                                 prefill=False,
                                 editable=False,
                                 edit_questions=False,
                                 questions=questions)
        answered = section.summary({'q1': 'a1', 'q2': 'a2'})
        assert not answered.is_empty
        half_answered = section.summary({'q1': 'a1', 'q2': ''})
        assert not half_answered.is_empty
        not_answered = section.summary({'q1': '', 'q2': ''})
        assert not_answered.is_empty
    def test_question_followup_get_data(self):
        section = ContentSection(slug='section',
                                 name=TemplateField('Section one'),
                                 prefill=False,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[
                                     Question({
                                         'id': 'q1',
                                         'followup': {
                                             'q2': [False]
                                         },
                                         'type': 'boolean'
                                     }),
                                     Question({
                                         'id': 'q2',
                                         'type': 'boolean'
                                     })
                                 ]).filter({})

        assert section.get_data(MultiDict([('q1', 'false')])) == {'q1': False}
        assert section.get_data(MultiDict([('q1', 'true')])) == {
            'q1': True,
            'q2': None
        }
        assert section.get_data(MultiDict([('q1', 'false'),
                                           ('q2', 'true')])) == {
                                               'q1': False,
                                               'q2': True
                                           }
        assert section.get_data(MultiDict([('q1', 'true'),
                                           ('q2', 'true')])) == {
                                               'q1': True,
                                               'q2': None
                                           }
Example #3
0
    def test_question_followup_get_data(self, filter_inplace_allowed, get_data_arg, expected_retval):
        section = ContentSection(
            slug='section',
            name=TemplateField('Section one'),
            prefill=False,
            editable=False,
            edit_questions=False,
            questions=[Question({'id': 'q1', 'followup': {'q2': [False]}, 'type': 'boolean'}),
                       Question({'id': 'q2', 'type': 'boolean'})]
        ).filter({}, inplace_allowed=filter_inplace_allowed)

        assert section.get_data(get_data_arg) == expected_retval
Example #4
0
    def test_is_empty(self, summary_arg, expect_empty, summary_inplace_allowed):
        questions = [
            Question({'id': 'q1', 'name': 'q1', 'type': 'unknown'}),
            Question({'id': 'q2', 'name': 'q2', 'type': 'unknown'})
        ]  # note that id and type are required as this function indirectly calls QuestionSummary.value

        section = ContentSection(
            slug='section',
            name=TemplateField('Section'),
            prefill=False,
            editable=False,
            edit_questions=False,
            questions=questions
        )
        assert section.summary(summary_arg, inplace_allowed=summary_inplace_allowed).is_empty is expect_empty
    def test_populate_styled_ods_with_data_with_boolean_list(self):
        questions = [
            {
                'id': 'blah',
                'name': 'Blah Blah',
                'type': 'boolean_list'
            },
        ]

        self.instance.get_questions = mock.Mock(
            return_value=[Question(question) for question in questions])

        doc = self.instance.populate_styled_ods_with_data(
            self.instance.create_blank_ods_with_styles(), {
                'brief': self.brief,
                'responses': self.responses
            })

        sheet = doc.sheet("Supplier evidence")

        row = 0
        for question in questions:
            for name_idx, name in enumerate(self.brief[question['id']]):
                row += 1

                if name_idx == 0:
                    assert sheet.read_cell(0, row) == question['name']
                else:
                    assert sheet.read_cell(0, row) == ''

                assert sheet.read_cell(1, row) == name

                for col, response in enumerate(self.responses):
                    assert sheet.read_cell(col + 2, row) == str(
                        response[question['id']][name_idx]).lower()
    def test_question_fields_without_template_tags_are_unchanged(self):
        section = ContentSection(slug='section',
                                 name=TemplateField('Section'),
                                 prefill=False,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[Question({'name': 'Question'})])

        assert section.filter({}).questions[0].name == 'Question'
    def test_not_all_fields_are_templated(self):
        section = ContentSection(slug='# {{ section }}',
                                 name=TemplateField('Section'),
                                 prefill=True,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[Question({})])

        assert section.filter({}).slug == '# {{ section }}'
Example #8
0
 def question(self):
     return Question(
         {
             "id": "startDate",
             "name": "Latest start date",
             "question": "What is the latest start date?",
             "type": "date"
         }
     )
Example #9
0
 def question(self):
     return Question(
         {
             "id": "yesOrNo",
             "name": "Yes or no",
             "question": "Yes or no?",
             "type": "boolean"
         }
     )
    def test_section_name_is_templated(self):
        section = ContentSection(slug='section',
                                 name=TemplateField('Section {{ name }}'),
                                 prefill=True,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[Question({})])

        assert section.filter({'name': 'one'}).name == 'Section one'
    def test_section_description_is_not_set(self):
        section = ContentSection(slug='section',
                                 name=TemplateField('Section one'),
                                 prefill=False,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[Question({})])

        assert section.filter({}).description is None
Example #12
0
 def question_without_word_count(self):
     return Question(
         {
             "id": "description",
             "name": "Description",
             "question": "Describe the specialist's role",
             "question_advice": "Describe the team the specialist will be working with on this project.",
             "type": "textbox_large"
         }
     )
    def test_missing_context_variable_raises_an_error(self):
        section = ContentSection(slug='section',
                                 name=TemplateField('Section {{ name }}'),
                                 prefill=False,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[Question({})])

        with pytest.raises(ContentTemplateError):
            section.filter({}).name
Example #14
0
 def question(self):
     return Question(
         {
             "id": "file-upload",
             "name": Markup("File upload required"),
             "question": Markup("Upload a file"),
             "question_advice": Markup("Your file should meet accessibility standards"),
             "type": "upload",
             "hint": Markup("Read the guidance on accessible documents (opens in new tab)")
         }
     )
Example #15
0
 def question(self):
     return Question(
         {
             "id": "title",
             "name": "Title",
             "question": "What you want to call your requirements",
             "question_advice": "This will help you to refer to your requirements",
             "hint": "100 characters maximum",
             "type": "text",
         }
     )
    def test_fields_without_template_tags_are_unchanged(self):
        section = ContentSection(slug='section',
                                 name=TemplateField('Section'),
                                 description=TemplateField('just a string'),
                                 prefill=True,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[Question({})])

        assert section.filter({}).name == 'Section'
        assert section.filter({}).description == 'just a string'
        assert section.filter({}).prefill is True
Example #17
0
 def question(self):
     return Question(
         {
             "id": "description",
             "name": "Description",
             "question": "Describe the specialist's role",
             "question_advice": "Describe the team the specialist will be working with on this project.",
             "type": "textbox_large",
             "hint": "Enter at least one word, and no more than 100",
             "max_length_in_words": 100
         }
     )
    def test_unused_context_variables_are_ignored(self):
        section = ContentSection(slug='section',
                                 name=TemplateField('Section {{ name }}'),
                                 prefill=True,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[Question({})])

        assert section.filter({
            'name': 'one',
            'name2': 'ignored'
        }).name == 'Section one'
    def test_section_description_is_templated(self):
        section = ContentSection(
            slug='section',
            name=TemplateField('Section one'),
            prefill=False,
            editable=False,
            edit_questions=False,
            questions=[Question({})],
            description=TemplateField("This is the {{ name }} section"))

        assert section.filter({
            'name': 'first'
        }).description == 'This is the first section'
Example #20
0
 def question(self):
     return Question(
         {
             "id": "oneAndAnother",
             "name": "One and another",
             "question": "Choose one and/or another",
             "type": "checkboxes",
             "options": [
                 {"label": "One", "value": "one"},
                 {"label": "Another", "value": "another"},
             ],
         }
     )
Example #21
0
 def question(self):
     return Question(
         {
             "id": "yesOrNo",
             "name": "Yes or no",
             "question": "Yes or no?",
             "type": "radios",
             "options": [
                 {"label": "Yes", "value": "yes"},
                 {"label": "No", "value": "no"},
             ],
         }
     )
Example #22
0
    def test_it_raises_jinja2_undefined_error_if_question_type_is_not_handled(self):
        ctx = mock.Mock()

        question = Question(
            {
                "id": "q1",
                "name": "Mysterious question",
                "question": "A question we don't know how to render",
                "type": "unhandled",
            }
        )

        with pytest.raises(jinja2.UndefinedError):
            render_question(ctx, question)
Example #23
0
 def question(self):
     return Question(
         {
             "id": "culturalFitCriteria",
             "name": "Title",
             "question": "Cultural fit criteria",
             "question_advice": (
                 '<p class="govuk-body">Cultural fit is about how well you and the specialist work together</p>'
             ),
             "hint": "Enter at least one criteria",
             "number_of_items": 5,
             "type": "list",
         }
     )
    def test_copying_section_preserves_value_of_context_attribute(self):
        section = ContentSection(slug='section',
                                 name=TemplateField('Section'),
                                 prefill=False,
                                 editable=False,
                                 edit_questions=False,
                                 questions=[Question({'name': 'Question'})
                                            ]).filter({'context': 'context1'})
        assert section._context == {'context': 'context1'}

        copied_section = section.copy()
        assert copied_section._context == section._context
        assert copied_section.prefill is False
        assert copied_section.editable is False
Example #25
0
    def test_it_renders_question_advice(self):
        ctx = mock.Mock()
        ctx.resolve.return_value = str

        question = Question(
            {
                "id": "title",
                "name": "Title",
                "question": "What you want to call your requirements",
                "question_advice": "This will help you to refer to your requirements",
                "hint": "100 characters maximum",
                "type": "text",
            }
        )

        assert "This will help you to refer to your requirements" in render_question(ctx, question)
Example #26
0
    def test_filtering_a_section_with_a_description_template(self, filter_inplace_allowed, lot, expected_description):
        section = ContentSection(
            slug='section',
            name=TemplateField('Section one'),
            prefill=False,
            editable=False,
            edit_questions=False,
            questions=[Question({})],
            description=TemplateField(
                "description for {% if lot == 'digital-specialists' %}specialists{% else %}outcomes{% endif %}"
            )
        )

        assert section.filter(
            {"lot": lot},
            inplace_allowed=filter_inplace_allowed,
        ).description == expected_description
    def test_get_templatable_section_attributes_calls_render(self):
        section = ContentSection(
            slug='section',
            name=TemplateField(
                '{% if True %}Section one{% else %}Section two{% endif %}'),
            prefill=True,
            editable=False,
            edit_questions=False,
            questions=[Question({})],
            description=TemplateField(
                "description for {% if lot == 'digital-specialists' %}specialists{% else %}outcomes{% endif %}"
            ))

        assert section.name == 'Section one'
        with pytest.raises(ContentTemplateError):
            section.description

        assert section.slug == 'section'
    def test_filtering_a_section_with_a_description_template(self):
        section = ContentSection(
            slug='section',
            name=TemplateField('Section one'),
            prefill=False,
            editable=False,
            edit_questions=False,
            questions=[Question({})],
            description=TemplateField(
                "description for {% if lot == 'digital-specialists' %}specialists{% else %}outcomes{% endif %}"
            ))

        assert section.filter({
            "lot": "digital-specialists"
        }).description == "description for specialists"
        assert section.filter({
            "lot": "digital-outcomes"
        }).description == "description for outcomes"
    def test_populate_styled_ods_with_data(self):
        questions = [
            {
                'id': 'supplierName',
                'name': 'Supplier',
                'type': 'text'
            },
            {
                'id': 'respondToEmailAddress',
                'name': 'Email address',
                'type': 'text'
            },
            {
                'id': 'availability',
                'name': 'Availability',
                'type': 'text'
            },
            {
                'id': 'dayRate',
                'name': 'Day rate',
                'type': 'text'
            },
        ]

        self.instance.get_questions = mock.Mock(
            return_value=[Question(question) for question in questions])

        doc = self.instance.populate_styled_ods_with_data(
            self.instance.create_blank_ods_with_styles(), {
                'brief': self.brief,
                'responses': self.responses
            })

        sheet = doc.sheet("Supplier evidence")

        assert sheet.read_cell(0, 0) == self.brief['title']

        for i, question in enumerate(questions):
            assert sheet.read_cell(0, i + 1) == question['name']
            assert sheet.read_cell(1, i + 1) == ''

            for j, response in enumerate(self.responses):
                assert sheet.read_cell(j + 2,
                                       i + 1) == response[question['id']]
    def test_populate_styled_ods_with_data_with_dynamic_list(self):
        questions = [
            {
                'id': 'niceToHaveRequirements',
                'name': 'Nice-to-have skills & evidence',
                'type': 'dynamic_list'
            },
            {
                'id': 'essentialRequirements',
                'name': 'Essential skills & evidence',
                'type': 'dynamic_list'
            },
        ]

        self.instance.get_questions = mock.Mock(
            return_value=[Question(question) for question in questions])

        doc = self.instance.populate_styled_ods_with_data(
            self.instance.create_blank_ods_with_styles(), {
                'brief': self.brief,
                'responses': self.responses
            })

        sheet = doc.sheet("Supplier evidence")

        row = 0
        for question in questions:
            for name_idx, name in enumerate(self.brief[question['id']]):
                row += 1

                if name_idx == 0:
                    assert sheet.read_cell(0, row) == question['name']
                else:
                    assert sheet.read_cell(0, row) == ''

                assert sheet.read_cell(1, row) == name

                for col, response in enumerate(self.responses):
                    assert sheet.read_cell(
                        col + 2,
                        row) == response[question['id']][name_idx].get(
                            'evidence', '')