def test_dynamic_list():
    question = ContentQuestion({
        "id":
        "q1",
        "type":
        "dynamic_list",
        "questions": [{
            "id": "q1a",
            "name": "Subquestion 1",
            "question": "This is subquestion 1",
            "type": "boolean"
        }, {
            "id": "q1b",
            "name": "Subquestion 2",
            "question": "This is subquestion 2",
            "type": "text"
        }]
    })

    result = multiquestion(question)

    assert set(result["q1"]["items"]["properties"].keys()) \
        == {"q1a", "q1b"}

    assert result["q1"]["items"]["properties"]["q1a"]["type"] == "boolean"
    assert result["q1"]["items"]["properties"]["q1b"]["type"] == "string"
Esempio n. 2
0
def test_followup():
    question = ContentQuestion({
        "id":
        "multiq",
        "type":
        "multiquestion",
        "questions": [{
            'id': 'subquestion1',
            'name': 'Subquestion 1',
            'question': 'This is subquestion 1',
            'type': 'boolean',
            'followup': {
                'subquestion2': [True]
            }
        }, {
            'id': 'subquestion2',
            'name': 'Subquestion 2',
            'question': 'This is subquestion 2',
            'type': 'text'
        }]
    })

    result, schema_addition = multiquestion(question)
    assert 'subquestion1' in result.keys()
    assert 'subquestion2' in result.keys()

    assert schema_addition == {
        'allOf': [{
            'oneOf': [{
                'properties': {
                    'subquestion1': {
                        'enum': [False]
                    },
                    'subquestion2': {
                        'type': 'null'
                    }
                }
            }, {
                'properties': {
                    'subquestion1': {
                        'enum': [True]
                    }
                },
                'required': ['subquestion1', 'subquestion2']
            }]
        }],
        'required': ['subquestion1']
    }
Esempio n. 3
0
def test_checkboxes_followup():
    question = ContentQuestion({
        "id": "multiq",
        "type": "multiquestion",
        "questions": [
            {
                'id': 'subquestion1',
                'name': 'Subquestion 1',
                'question': 'This is subquestion 1',
                'type': 'checkboxes',
                'options': [{'label': 'AA', 'value': 'a'}, {'label': 'BB', 'value': 'b'}],
                'followup': {
                    'subquestion2': ['a']
                }
            },
            {
                'id': 'subquestion2',
                'name': 'Subquestion 2',
                'optional': True,
                'question': 'This is subquestion 2',
                'type': 'text'
            }
        ]
    })

    result, schema_addition = multiquestion(question)
    assert 'subquestion1' in result.keys()
    assert 'subquestion2' in result.keys()

    assert schema_addition == {
        'allOf': [
            {'oneOf': [
                {'properties': {
                    'subquestion1': {'items': {'enum': ['b']}},
                    'subquestion2': {'type': 'null'}
                }},
                {
                    'properties': {'subquestion1': {'not': {'items': {'enum': ['b']}}}},
                    'required': ['subquestion1']
                }
            ]}
        ],
        'required': ['subquestion1']
    }
def test_followup():
    question = ContentQuestion({
        "id": "multiq",
        "type": "multiquestion",
        "questions": [
            {
                'id': 'subquestion1',
                'name': 'Subquestion 1',
                'question': 'This is subquestion 1',
                'type': 'boolean',
                'followup': {
                    'subquestion2': [True]
                }
            },
            {
                'id': 'subquestion2',
                'name': 'Subquestion 2',
                'question': 'This is subquestion 2',
                'type': 'text'
            }
        ]
    })

    result, schema_addition = multiquestion(question)
    assert 'subquestion1' in result.keys()
    assert 'subquestion2' in result.keys()

    assert schema_addition == {
        'allOf': [
            {'oneOf': [
                {'properties': {
                    'subquestion1': {'enum': [False]},
                    'subquestion2': {'type': 'null'}
                }},
                {
                    'properties': {'subquestion1': {'enum': [True]}},
                    'required': ['subquestion1', 'subquestion2']
                }
            ]}
        ],
        'required': ['subquestion1']
    }
Esempio n. 5
0
def test_multiquestion():
    question = ContentQuestion({
        "type":
        "multiquestion",
        "questions": [{
            'id': 'subquestion1',
            'name': 'Subquestion 1',
            'question': 'This is subquestion 1',
            'type': 'boolean'
        }, {
            'id': 'subquestion2',
            'name': 'Subquestion 2',
            'question': 'This is subquestion 2',
            'type': 'text'
        }]
    })

    result, schema_addition = multiquestion(question)
    assert 'subquestion1' in result.keys()
    assert 'subquestion2' in result.keys()

    assert schema_addition == {'required': ['subquestion1', 'subquestion2']}
def test_dynamic_list_with_dynamic_content():
    question = ContentQuestion({
        "id":
        "q",
        "type":
        "dynamic_list",
        "questions": [{
            "id":
            "q1",
            "question":
            TemplateField("This is question 1 for '{{ item }}' " +
                          str(mock.sentinel.template_field)),
            "type":
            "text",
            "validations": [
                {
                    "name":
                    "answer_required",
                    "message":
                    TemplateField("Answer {{ item }} " +
                                  str(mock.sentinel.template_field))
                },
            ],
        }]
    })

    result = multiquestion(question)

    assert set(result["q"]["items"]["properties"].keys()) \
        == {"q1"}

    assert result["q"]["items"]["properties"]["q1"]["type"] == "string"

    # check that template fields don't show up in schema
    assert ("{{ item }}" not in str(result)
            and str(mock.sentinel.template_field) not in str(result)
            ), "a template field is being used in the generated schema"
def test_multiquestion():
    question = ContentQuestion({
        "type": "multiquestion",
        "questions": [
            {
                'id': 'subquestion1',
                'name': 'Subquestion 1',
                'question': 'This is subquestion 1',
                'type': 'boolean'
            },
            {
                'id': 'subquestion2',
                'name': 'Subquestion 2',
                'question': 'This is subquestion 2',
                'type': 'text'
            }
        ]
    })

    result, schema_addition = multiquestion(question)
    assert 'subquestion1' in result.keys()
    assert 'subquestion2' in result.keys()

    assert schema_addition == {'required': ['subquestion1', 'subquestion2']}