Exemplo n.º 1
0
def get_test_form_class(answer_schema, messages=None):
    handler = NumberHandler(answer_schema, error_messages=messages)

    class TestForm(Form):
        test_field = handler.get_field()

    return TestForm
def get_test_form_class(answer_schema,
                        value_source_resolver,
                        rule_evaluator,
                        messages=error_messages.copy()):
    handler = NumberHandler(answer_schema,
                            value_source_resolver,
                            rule_evaluator,
                            error_messages=messages)

    class TestForm(Form):
        test_field = handler.get_field()

    return TestForm
def test_get_schema_value_answer_store(value_source_resolver, rule_evaluator):
    answer_schema = {
        "id": "test-range",
        "label": "",
        "description": "Range Test",
        "mandatory": False,
        "type": "Number",
        "decimal_places": 2,
        "maximum": {
            "value": {
                "identifier": "set-maximum",
                "source": "answers"
            }
        },
        "minimum": {
            "value": {
                "identifier": "set-minimum",
                "source": "answers"
            }
        },
    }
    value_source_resolver.metadata = {
        "schema_name": "test_numbers",
        "language_code": "en",
    }
    answer_store = AnswerStore()

    answer_store.add_or_update(Answer(answer_id="set-maximum", value=10))
    answer_store.add_or_update(Answer(answer_id="set-minimum", value=1))
    value_source_resolver.answer_store = answer_store
    number_handler = NumberHandler(answer_schema, value_source_resolver,
                                   rule_evaluator, error_messages)

    maximum = number_handler.get_schema_value(answer_schema["maximum"])
    minimum = number_handler.get_schema_value(answer_schema["minimum"])

    assert maximum == 10
    assert minimum == 1
Exemplo n.º 4
0
def test_default_range():
    answer = {
        "decimal_places": 2,
        "label": "Range Test 10 to 20",
        "mandatory": False,
        "validation": {
            "messages": {
                "INVALID_NUMBER":
                "Please only enter whole numbers into the field.",
                "NUMBER_TOO_SMALL":
                "The minimum value allowed is 10. Please correct your answer.",
                "NUMBER_TOO_LARGE":
                "The maximum value allowed is 20. Please correct your answer.",
            }
        },
        "id": "test-range",
        "type": "Currency",
    }
    handler = NumberHandler(answer)
    field_references = handler.get_field_references()

    assert field_references["maximum"] == MAX_NUMBER
    assert field_references["minimum"] == 0