Exemplo n.º 1
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')
Exemplo n.º 2
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
Exemplo n.º 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')
Exemplo 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()

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

    assert not f._validate_my_setting.called
Exemplo 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')
Exemplo n.º 6
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')