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')
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')
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
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')
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
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')
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
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