Ejemplo n.º 1
0
def test_get_mandatory_validator_optional():
    answer = {"mandatory": False}

    text_area_handler = StringHandler(answer, None, AnswerStore(), {})
    validate_with = text_area_handler.get_mandatory_validator()

    assert isinstance(validate_with, validators.Optional)
Ejemplo n.º 2
0
def test_get_mandatory_validator_optional(value_source_resolver,
                                          rule_evaluator):
    answer = {"mandatory": False}

    text_area_handler = StringHandler(answer, value_source_resolver,
                                      rule_evaluator, error_messages)
    validate_with = text_area_handler.get_mandatory_validator()

    assert isinstance(validate_with, validators.Optional)
Ejemplo n.º 3
0
def test_get_mandatory_validator_mandatory():
    answer = {"mandatory": True}

    text_area_handler = StringHandler(
        answer,
        {"MANDATORY_TEXTFIELD": "This is the default mandatory message"},
        AnswerStore(),
        {},
    )

    validate_with = text_area_handler.get_mandatory_validator()

    assert isinstance(validate_with, ResponseRequired)
    assert validate_with.message == "This is the default mandatory message"
Ejemplo n.º 4
0
def test_get_mandatory_validator_mandatory(value_source_resolver,
                                           rule_evaluator):
    answer = {"mandatory": True}

    text_area_handler = StringHandler(
        answer,
        value_source_resolver,
        rule_evaluator,
        {"MANDATORY_TEXTFIELD": "This is the default mandatory message"},
    )
    validate_with = text_area_handler.get_mandatory_validator()

    assert isinstance(validate_with, ResponseRequired)
    assert validate_with.message == "This is the default mandatory message"
Ejemplo n.º 5
0
def test_get_length_validator_with_max_length_override():
    answer = {"max_length": 30}

    string_handler = StringHandler(answer, error_messages=MagicMock())
    validator = string_handler.get_length_validator

    assert validator.max == 30
Ejemplo n.º 6
0
def test_get_length_validator_with_max_length_override():
    answer = {"max_length": 30}

    string_handler = StringHandler(answer)
    validator = string_handler.get_length_validator

    assert validator.max == 30
Ejemplo n.º 7
0
def test_get_length_validator(value_source_resolver, rule_evaluator):
    string_handler = StringHandler(
        {}, value_source_resolver, rule_evaluator, error_messages
    )

    validator = string_handler.get_length_validator

    assert isinstance(validator, validators.Length)
Ejemplo n.º 8
0
def test_get_mandatory_validator_mandatory_with_error(value_source_resolver,
                                                      rule_evaluator):
    answer = {
        "mandatory": True,
        "validation": {
            "messages": {
                "MANDATORY_TEXTFIELD":
                "This is the mandatory message for an answer"
            }
        },
    }

    text_area_handler = StringHandler(answer, value_source_resolver,
                                      rule_evaluator, error_messages)
    validate_with = text_area_handler.get_mandatory_validator()

    assert isinstance(validate_with, ResponseRequired)
    assert validate_with.message == "This is the mandatory message for an answer"
Ejemplo n.º 9
0
def test_get_length_validator_with_message_override():
    answer = {
        "validation": {"messages": {"MAX_LENGTH_EXCEEDED": "The message is too long!"}}
    }
    string_handler = StringHandler(
        answer, {"MAX_LENGTH_EXCEEDED": "This is the default max length message"}
    )

    validator = string_handler.get_length_validator

    assert validator.message == "The message is too long!"
Ejemplo n.º 10
0
def test_get_length_validator_with_max_length_override(
    value_source_resolver, rule_evaluator
):
    answer = {"max_length": 30}

    string_handler = StringHandler(
        answer, value_source_resolver, rule_evaluator, error_messages
    )
    validator = string_handler.get_length_validator

    assert validator.max == 30
Ejemplo n.º 11
0
def test_get_mandatory_validator_mandatory_with_question_in_error():
    answer = {
        "mandatory": True,
        "validation": {
            "messages": {
                "MANDATORY_TEXTFIELD":
                "Select an answer to ‘%(question_title)s’"
            }
        },
    }

    text_area_handler = StringHandler(
        answer,
        {"MANDATORY_TEXTFIELD": "This is the default mandatory message"},
        AnswerStore(),
        metadata={},
        question_title="To be or not to be?",
    )
    validate_with = text_area_handler.get_mandatory_validator()

    assert isinstance(validate_with, ResponseRequired)
    assert validate_with.message == "Select an answer to ‘To be or not to be?’"
Ejemplo n.º 12
0
def test_get_length_validator_with_message_override(
    value_source_resolver, rule_evaluator
):
    answer = {
        "validation": {"messages": {"MAX_LENGTH_EXCEEDED": "The message is too long!"}}
    }

    string_handler = StringHandler(
        answer, value_source_resolver, rule_evaluator, error_messages
    )

    validator = string_handler.get_length_validator

    assert validator.message == "The message is too long!"
Ejemplo n.º 13
0
def test_string_field():
    textfield_json = {
        "id": "job-title-answer",
        "label": "Job title",
        "mandatory": False,
        "guidance": "<p>Please enter your job title in the space provided.</p>",
        "type": "TextField",
    }
    string_handler = StringHandler(textfield_json, disable_validation=True)

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

    form = TestForm()

    assert isinstance(form.test_field, StringField)
    assert form.test_field.label.text == textfield_json["label"]
    assert form.test_field.description == textfield_json["guidance"]
Ejemplo n.º 14
0
def test_get_length_validator():
    string_handler = StringHandler({}, error_messages=MagicMock())

    validator = string_handler.get_length_validator

    assert isinstance(validator, validators.Length)
Ejemplo n.º 15
0
def test_get_length_validator():
    string_handler = StringHandler({})

    validator = string_handler.get_length_validator

    assert isinstance(validator, validators.Length)