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"
示例#2
0
def test_hours_for_price():
    manifest = {
        "id": "Test",
        "type": "pricing",
        "fields": {
            "hours_for_price": "pfh"
        }
    }
    cq = ContentQuestion(manifest)
    result = pricing_property(cq)
    assert "enum" in result['pfh'].keys()
示例#3
0
def test_pricing_property_price_unit_and_interval():
    manifest = {
        "id": "Test",
        "fields": {
            "price_unit": "priceUnit",
            "price_interval": "priceInterval"
        }
    }
    cq = ContentQuestion(manifest)
    result = pricing_property(cq)
    assert type(result['priceInterval']['enum']) == list
    assert type(result['priceUnit']['enum']) == list
示例#4
0
def test_pricing_property_minmax_price():
    manifest = {
        "id": "Test",
        "fields": {
            "minimum_price": "priceMin",
            "maximum_price": "priceMax"
        }
    }
    cq = ContentQuestion(manifest)
    result = pricing_property(cq)
    assert not result['priceMin']['pattern'].startswith("^$|")
    assert not result['priceMax']['pattern'].startswith("^$|")
示例#5
0
def test_pricing_property_price_unit_and_interval_optional():
    manifest = {
        "id": "Test",
        "fields": {
            "price_unit": "priceUnit",
            "price_interval": "priceInterval"
        },
        "optional_fields": ["price_unit", "price_interval"]
    }
    cq = ContentQuestion(manifest)
    result = pricing_property(cq)
    assert "" in result['priceUnit']['enum']
    assert "" in result['priceInterval']['enum']
示例#6
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']
    }
示例#7
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']
    }
示例#8
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"