Пример #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))
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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))
Пример #8
0
 def test_should_create_empty_constraint_dictionary_if_None(self):
     constraint_info = []
     constraints = constraints_factory(constraint_info)
     self.assertEqual([], constraints)