示例#1
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')
示例#2
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')
示例#3
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')
示例#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()

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

    assert not f._validate_my_setting.called
示例#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)
    )

    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')
示例#6
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
示例#7
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')
示例#8
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
示例#9
0
def test_field_validate_field_base_should_be_abstract():
    f = Field()

    with pytest.raises(NotImplementedError):
        f._validate_field('test')
示例#10
0
def test_field_validate_field_base_should_be_abstract():
    f = Field()

    with pytest.raises(NotImplementedError):
        f._validate_field('test')