Esempio n. 1
0
def test_invalid_field_type_raises_on_invalid(answer_store, list_store):
    schema = QuestionnaireSchema({
        "questionnaire_flow": {
            "type": "Linear",
            "options": {
                "summary": {
                    "collapsible": False
                }
            },
        }
    })

    metadata = {
        "user_id": "789473423",
        "schema_name": "0000",
        "collection_exercise_sid": "test-sid",
        "period_id": "2016-02-01",
        "period_str": "2016-01-01",
        "ref_p_start_date": "2016-02-02",
        "ref_p_end_date": "2016-03-03",
        "ru_ref": "432423423423",
        "ru_name": "Apple",
        "return_by": "2016-07-07",
        "case_id": "1234567890",
        "case_ref": "1000000000000001",
    }

    response_metadata = {}

    value_source_resolver = ValueSourceResolver(
        answer_store=answer_store,
        list_store=list_store,
        metadata=metadata,
        response_metadata=response_metadata,
        schema=schema,
        location=None,
        list_item_id=None,
        escape_answer_values=False,
    )

    rule_evaluator = RuleEvaluator(
        answer_store=answer_store,
        list_store=list_store,
        metadata=metadata,
        response_metadata=response_metadata,
        schema=schema,
        location=None,
    )

    # Given
    invalid_field_type = "Football"
    # When / Then
    with pytest.raises(KeyError):
        get_field_handler(
            answer_schema={"type": invalid_field_type},
            value_source_resolver=value_source_resolver,
            rule_evaluator=rule_evaluator,
            error_messages=error_messages,
        )
def confirmation_email_fulfilment_schema():
    return QuestionnaireSchema({
        "form_type": "H",
        "region_code": "GB-WLS",
        "submission": {
            "confirmation_email": True
        },
    })
Esempio n. 3
0
def test_load_schema_from_url_404():
    load_schema_from_url.cache_clear()

    mock_schema = QuestionnaireSchema({})
    responses.add(responses.GET, TEST_SCHEMA_URL, json=mock_schema.json, status=404)

    with pytest.raises(NotFound):
        load_schema_from_url(survey_url=TEST_SCHEMA_URL, language_code="en")
Esempio n. 4
0
def test_load_schema_from_url_200():
    load_schema_from_url.cache_clear()

    mock_schema = QuestionnaireSchema({}, language_code="cy")
    responses.add(responses.GET, TEST_SCHEMA_URL, json=mock_schema.json, status=200)
    loaded_schema = load_schema_from_url(survey_url=TEST_SCHEMA_URL, language_code="cy")

    assert loaded_schema.json == mock_schema.json
    assert loaded_schema.language_code == mock_schema.language_code
Esempio n. 5
0
def test_load_schema_from_metadata_with_survey_url():
    load_schema_from_url.cache_clear()

    metadata = {"survey_url": TEST_SCHEMA_URL, "language_code": "cy"}
    mock_schema = QuestionnaireSchema({}, language_code="cy")
    responses.add(responses.GET, TEST_SCHEMA_URL, json=mock_schema.json, status=200)
    loaded_schema = load_schema_from_metadata(metadata=metadata)

    assert loaded_schema.json == mock_schema.json
    assert loaded_schema.language_code == mock_schema.language_code
def mock_schema():
    schema = Mock(
        QuestionnaireSchema(
            {
                "questionnaire_flow": {
                    "type": "Linear",
                    "options": {"summary": {"collapsible": False}},
                }
            }
        )
    )
    return schema
def schema():
    return QuestionnaireSchema({"post_submission": {"view_response": True}})
def schema_feedback():
    return QuestionnaireSchema({
        "survey_id": survey_id,
        "data_version": data_version
    })
Esempio n. 9
0
 def address_questionnaire_schema(concatenation_type):
     return QuestionnaireSchema({
         "sections": [{
             "id":
             "address-section",
             "groups": [{
                 "blocks": [
                     {
                         "type": "Question",
                         "id": "what-is-your-address",
                         "question": {
                             "id":
                             "what-is-your-address-question",
                             "title":
                             "What is your address?",
                             "type":
                             "General",
                             "answers": [
                                 {
                                     "id": "building",
                                     "label": "Building",
                                     "mandatory": False,
                                     "type": "TextField",
                                     "default": "Government Buildings",
                                 },
                                 {
                                     "id": "address-line-1",
                                     "label": "Address Line 1",
                                     "mandatory": True,
                                     "type": "TextField",
                                 },
                                 {
                                     "id": "address-line-2",
                                     "label": "Address Line 2",
                                     "mandatory": False,
                                     "type": "TextField",
                                 },
                                 {
                                     "id": "address-line-3",
                                     "label": "Address Line 3",
                                     "mandatory": False,
                                     "type": "TextField",
                                 },
                                 {
                                     "id": "town-city",
                                     "label": "Town/City",
                                     "mandatory": False,
                                     "type": "TextField",
                                 },
                                 {
                                     "id": "county",
                                     "label": "County",
                                     "mandatory": False,
                                     "type": "TextField",
                                 },
                                 {
                                     "id": "postcode",
                                     "label": "Postcode",
                                     "mandatory": False,
                                     "type": "TextField",
                                 },
                                 {
                                     "id": "country",
                                     "label": "Country",
                                     "mandatory": False,
                                     "type": "TextField",
                                 },
                             ],
                             "summary": {
                                 "concatenation_type": concatenation_type
                             },
                         },
                     },
                 ],
                 "id":
                 "address-group",
             }],
         }]
     })