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
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)
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' )
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_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_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(): 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_get_settings_validator(): f = Field() f._validate_my_setting = mock.Mock() assert f._get_setting_validator('my_setting') == f._validate_my_setting
def test_field_validate_field_base_should_be_abstract(): f = Field() with pytest.raises(NotImplementedError): f._validate_field('test')
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
def test_field_set_name(): f = Field() f.set_name('test') assert f._name == 'test'
def test_feld_init_not_required(): f = Field(setting1=1) assert not f.required