Exemplo n.º 1
0
 def test_should_create_a_constraint_dictionary(self):
     constraint_info = [(ConstraintTypes.LENGTH, {
         ConstraintAttributes.MIN: 10,
         ConstraintAttributes.MAX: 20
     }), (ConstraintTypes.REGEX, "^\w")]
     constraints = constraints_factory(constraint_info)
     self.assertEqual(2, len(constraints))
Exemplo n.º 2
0
def _get_short_code_field(code, dictionary, label, name, instruction, required,
                          parent_field_code):
    constraints, constraints_json = [], dictionary.get("constraints")
    if constraints_json is not None:
        constraints = constraints_factory(constraints_json)
    field = ShortCodeField(name=name,
                           code=code,
                           label=label,
                           constraints=constraints,
                           instruction=instruction,
                           required=required,
                           parent_field_code=parent_field_code)
    return field
Exemplo n.º 3
0
def _get_text_field(code, dictionary, label, name, instruction, required,
                    parent_field_code):
    constraints, constraints_json = [], dictionary.get("constraints")
    if constraints_json is not None:
        constraints = constraints_factory(constraints_json)
    field = TextField(name=name,
                      code=code,
                      label=label,
                      constraints=constraints,
                      instruction=instruction,
                      required=required,
                      parent_field_code=parent_field_code,
                      is_calculated=dictionary.get('is_calculated'))
    return field
Exemplo n.º 4
0
def _get_integer_field(code, dictionary, label, name, instruction, required,
                       parent_field_code):
    constraints, constraint_list = [], dictionary.get('constraints')
    if constraint_list is not None:
        constraints = constraints_factory(constraint_list)

    integer_field = IntegerField(name=name,
                                 code=code,
                                 label=label,
                                 instruction=instruction,
                                 constraints=constraints,
                                 required=required,
                                 parent_field_code=parent_field_code)

    return integer_field
Exemplo n.º 5
0
def _get_telephone_number_field(code, dictionary, label, name, instruction,
                                required, parent_field_code):
    constraints, constraints_json = [], dictionary.get("constraints")
    if constraints_json is not None:
        constraints = constraints_factory(constraints_json)

    field = TelephoneNumberField(name=name,
                                 code=code,
                                 label=label,
                                 constraints=constraints,
                                 instruction=instruction,
                                 required=required,
                                 parent_field_code=parent_field_code)

    return field
Exemplo n.º 6
0
def _get_field_set_field(code, dictionary, label, name, instruction, required,
                         dbm, parent_field_code):
    constraints, constraints_json = [], dictionary.get("constraints")
    if constraints_json is not None:
        constraints = constraints_factory(constraints_json)

    sub_fields = dictionary.get("fields")
    fieldset_type = dictionary.get("fieldset_type")
    repeat_question_fields = [create_question_from(f, dbm) for f in sub_fields]
    field = FieldSet(name=name,
                     code=code,
                     label=label,
                     instruction=instruction,
                     required=required,
                     field_set=repeat_question_fields,
                     fieldset_type=fieldset_type,
                     parent_field_code=parent_field_code)
    return field
Exemplo n.º 7
0
 def test_should_throw_error_if_constraint_not_known(self):
     constraint_info = [('nonsense', 'this should bomb'), ('regex', '^$')]
     constraints = constraints_factory(constraint_info)
     self.assertEqual(1, len(constraints))
     self.assertTrue(isinstance(constraints[0], RegexConstraint))
Exemplo n.º 8
0
 def test_should_create_empty_constraint_dictionary_if_None(self):
     constraint_info = []
     constraints = constraints_factory(constraint_info)
     self.assertEqual([], constraints)