Ejemplo n.º 1
0
def test_generate_field_text():
    FIELD = {'name': 'first_name', 'type': 'text', 'options': {  # pylint: disable=invalid-name
        'required': True, 'max_length': 25}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.CharField)
    assert field.max_length == 25
    assert field.required
Ejemplo n.º 2
0
def test_generate_field_decimal():
    FIELD = {'name': 'decimal', 'type': 'decimal', 'options': {  # pylint: disable=invalid-name
        'max_value': 10.1, 'min_value': 5.1}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.DecimalField)
Ejemplo n.º 3
0
def test_generate_field_integer():
    FIELD = {'name': 'integer', 'type': 'integer', 'options': {  # pylint: disable=invalid-name
        'max_value': 10, 'min_value': 5}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.IntegerField)
Ejemplo n.º 4
0
def test_generate_field_time():
    FIELD = {'name': 'time', 'type': 'time'}  # pylint: disable=invalid-name
    field = generate_field(FIELD)
    assert isinstance(field, forms.TimeField)
    assert isinstance(field.widget, forms.TimeInput)
Ejemplo n.º 5
0
def test_generate_field_duration():
    FIELD = {'name': 'duration', 'type': 'duration'}  # pylint: disable=invalid-name
    field = generate_field(FIELD)
    assert isinstance(field, forms.DurationField)
Ejemplo n.º 6
0
def test_generate_field_date():
    FIELD = {'name': 'date', 'type': 'date'}  # pylint: disable=invalid-name
    field = generate_field(FIELD)
    assert isinstance(field, forms.DateField)
    assert isinstance(field.widget, forms.SelectDateWidget)
Ejemplo n.º 7
0
def test_generate_field_multiselect():
    FIELD = {'name': 'occupation_multiselect', 'type': 'multiselect',  # pylint: disable=invalid-name
             'options': {'choices': SELECT_CHOICES}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.MultipleChoiceField)
Ejemplo n.º 8
0
def test_generate_field_radio():
    FIELD = {'name': 'marital_status', 'type': 'radio', 'options': {'label': 'Marital Status', 'choices': [  # pylint: disable=invalid-name
        ['single', 'Single'], ['married', 'Married'], ['divorced', 'Divorced'], ['widower', 'Widower']]}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.ChoiceField)
    assert isinstance(field.widget, forms.RadioSelect)
Ejemplo n.º 9
0
def test_generate_field_email():
    FIELD = {'name': 'e-mail', 'type': 'email',  # pylint: disable=invalid-name
             'options': {'required': True, 'min_length': 5}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.EmailField)
Ejemplo n.º 10
0
def test_generate_field_textarea():
    FIELD = {'name': 'smallcv', 'type': 'textarea', 'options': {  # pylint: disable=invalid-name
        'label': 'Small CV', 'help_text': 'Please insert a small CV'}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.CharField)
    assert isinstance(field.widget, forms.Textarea)
Ejemplo n.º 11
0
def test_generate_field_checkbox():
    FIELD = {'name': 'internet', 'type': 'checkbox'}  # pylint: disable=invalid-name
    field = generate_field(FIELD)
    assert isinstance(field, forms.BooleanField)
    assert isinstance(field.widget, forms.CheckboxInput)
Ejemplo n.º 12
0
def test_generate_field_image():
    FIELD = {'name': 'image', 'type': 'image', 'options': {'required': False}}  # pylint: disable=invalid-name
    field = generate_field(FIELD)
    assert isinstance(field, forms.ImageField)
Ejemplo n.º 13
0
def test_generate_field_invalid():
    FIELD = {'name': 'first_name', 'type': 'nonexistent', 'options': {  # pylint: disable=invalid-name
        'required': True, 'max_length': 25}}
    with pytest.raises(ValueError):
        generate_field(FIELD)
Ejemplo n.º 14
0
def test_generate_field_filepath():
    FIELD = {'name': 'filepath', 'type': 'filepath', 'options': {  # pylint: disable=invalid-name
        'path': '/home/roig', 'required': False, 'allow_files': True}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.FilePathField)
Ejemplo n.º 15
0
def test_generate_field_file():
    FIELD = {'name': 'file', 'type': 'file', 'options': {  # pylint: disable=invalid-name
        'required': False, 'allow_empty_file': True}}
    field = generate_field(FIELD)
    assert isinstance(field, forms.FileField)