Ejemplo n.º 1
0
def create_field_set_helper(no_fields=False):
    if no_fields:
        return FieldSet(), None, None

    f1 = mock.Mock(spec=Field())
    f2 = mock.Mock(spec=Field())
    return FieldSet(field1=f1, field2=f2), f1, f2
Ejemplo n.º 2
0
def test_field_get_settings_validator_raise_configration_error():
    f = Field()
    f.set_name('test')

    with pytest.raises(FieldSet.ConfigurationError) as e:
        f._get_setting_validator('my_setting')
    assert 'Setting "my_setting" is ' + \
           'not supported for field "test"' in str(e)
Ejemplo n.º 3
0
def test_field_get_settings_validator_raise_configration_error():
    f = Field()
    f.set_name('test')
    nose.tools.assert_raises_regexp(
        FieldSet.ConfigurationError,
        'Setting "my_setting" is not supported for field "test"',
        f._get_setting_validator,
        'my_setting'
    )
Ejemplo n.º 4
0
def test_field_validate_raises_on_field_validation():
    f = Field(my_setting=1)
    f.set_name('test')

    field_error_message = 'Field error message'
    f._validate_field = mock.Mock(
        side_effect=FieldSet.Error(field_error_message)
    )
    f._validate_my_setting = mock.Mock()

    nose.tools.assert_raises_regexp(
        FieldSet.Error,
        field_error_message,
        f.validate,
        'value'
    )
    assert not f._validate_my_setting.called
Ejemplo n.º 5
0
def test_field_validate_raises_on_setting_validation():
    f = Field(my_setting=1)
    f.set_name('test')

    f._validate_field = mock.Mock()
    my_setting_error_message = 'my setting error message'
    f._validate_my_setting = mock.Mock(
        side_effect=FieldSet.Error(my_setting_error_message)
    )

    nose.tools.assert_raises_regexp(
        FieldSet.Error,
        my_setting_error_message,
        f.validate,
        'value'
    )
    f._validate_field.assert_called_with('value')
Ejemplo n.º 6
0
def test_field_validate_raises_on_setting_validation():
    f = Field(my_setting=1)
    f.set_name('test')

    f._validate_field = mock.Mock()
    my_setting_error_message = 'my setting error message'
    f._validate_my_setting = mock.Mock(
        side_effect=FieldSet.Error(my_setting_error_message))

    with pytest.raises(FieldSet.Error) as e:
        f.validate('value')
    assert my_setting_error_message in str(e)

    f._validate_field.assert_called_with('value')
Ejemplo n.º 7
0
def test_field_validate_raises_on_field_validation():
    f = Field(my_setting=1)
    f.set_name('test')

    field_error_message = 'Field error message'
    f._validate_field = mock.Mock(
        side_effect=FieldSet.Error(field_error_message))
    f._validate_my_setting = mock.Mock()

    with pytest.raises(FieldSet.Error) as e:
        f.validate('value')
    assert field_error_message in str(e)

    assert not f._validate_my_setting.called
Ejemplo n.º 8
0
def test_field_validate():
    f = Field(my_setting=1)
    f.set_name('test')

    f._validate_field = mock.Mock(return_value='value')
    f._validate_my_setting = mock.Mock(return_value='value')

    assert f.validate('value') == 'value'

    f._validate_field.assert_called_with('value')
    f._validate_my_setting.assert_called_with(1, 'value')
Ejemplo n.º 9
0
def test_field_get_settings_validator_raise_configration_error():
    f = Field()
    f.set_name('test')

    with pytest.raises(FieldSet.ConfigurationError) as e:
        f._get_setting_validator('my_setting')
    assert 'Setting "my_setting" is ' + \
           'not supported for field "test"' in str(e)
Ejemplo n.º 10
0
def test_field_validate():
    f = Field(my_setting=1)
    f.set_name('test')

    f._validate_field = mock.Mock(return_value='value')
    f._validate_my_setting = mock.Mock(return_value='value')

    assert f.validate('value') == 'value'

    f._validate_field.assert_called_with('value')
    f._validate_my_setting.assert_called_with(1, 'value')
Ejemplo n.º 11
0
def test_field_validate_raises_on_setting_validation():
    f = Field(my_setting=1)
    f.set_name('test')

    f._validate_field = mock.Mock()
    my_setting_error_message = 'my setting error message'
    f._validate_my_setting = mock.Mock(
        side_effect=FieldSet.Error(my_setting_error_message)
    )

    with pytest.raises(FieldSet.Error) as e:
        f.validate('value')
    assert my_setting_error_message in str(e)

    f._validate_field.assert_called_with('value')
Ejemplo n.º 12
0
def test_field_validate_raises_on_field_validation():
    f = Field(my_setting=1)
    f.set_name('test')

    field_error_message = 'Field error message'
    f._validate_field = mock.Mock(
        side_effect=FieldSet.Error(field_error_message)
    )
    f._validate_my_setting = mock.Mock()

    with pytest.raises(FieldSet.Error) as e:
        f.validate('value')
    assert field_error_message in str(e)

    assert not f._validate_my_setting.called
Ejemplo n.º 13
0
def test_field_get_settings_validator():
    f = Field()
    f._validate_my_setting = mock.Mock()
    assert f._get_setting_validator('my_setting') == f._validate_my_setting
Ejemplo n.º 14
0
def test_field_validate_field_base_should_be_abstract():
    f = Field()

    with pytest.raises(NotImplementedError):
        f._validate_field('test')
Ejemplo n.º 15
0
def test_field_init():
    f = Field(setting1=1, setting2=2, required=True)
    assert f._name is None
    assert f._settings == {'setting1': 1, 'setting2': 2}
    assert f.required
Ejemplo n.º 16
0
def test_field_get_settings_validator():
    f = Field()
    f._validate_my_setting = mock.Mock()
    assert f._get_setting_validator('my_setting') == f._validate_my_setting
Ejemplo n.º 17
0
def test_field_validate_field_base_should_be_abstract():
    f = Field()

    with pytest.raises(NotImplementedError):
        f._validate_field('test')
Ejemplo n.º 18
0
def test_field_set_name():
    f = Field()
    f.set_name('test')
    assert f._name == 'test'
Ejemplo n.º 19
0
def test_feld_init_not_required():
    f = Field(setting1=1)
    assert not f.required
Ejemplo n.º 20
0
def test_field_set_name():
    f = Field()
    f.set_name('test')
    assert f._name == 'test'