Ejemplo n.º 1
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.º 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():
    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.º 5
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.º 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_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.º 9
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.º 10
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.º 11
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.º 12
0
def test_field_set_name():
    f = Field()
    f.set_name('test')
    assert f._name == 'test'
Ejemplo n.º 13
0
def test_field_set_name():
    f = Field()
    f.set_name('test')
    assert f._name == 'test'