def setUp(self): super(TestCustomPropertiesField, self).setUp() test_validator_1 = mock.MagicMock(__call__=lambda: None) test_validator_2 = { 'expr': { 'validators': [django_validator.RegexValidator()] } } test_validator_3 = { 'expr': fields.RawProperty(None, None) } kwargs = { 'validators': [ test_validator_1, test_validator_2, test_validator_3 ] } for arg in fields.FIELD_ARGS_TO_ESCAPE: kwargs[arg] = 'foo_' + arg custom_props_field = fields.CustomPropertiesField(**kwargs) for arg in fields.FIELD_ARGS_TO_ESCAPE: self.assertTrue(hasattr(custom_props_field, arg)) self.assertEqual('foo_{0}'.format(arg), getattr(custom_props_field, arg)) self.assertEqual(3, len(custom_props_field.validators))
def test_clean(self): mock_form = mock.Mock() mock_form.cleaned_data = 'test_cleaned_data' custom_props_field = fields.CustomPropertiesField() custom_props_field.form = mock_form custom_props_field.enabled = True self.assertEqual('foo', custom_props_field.clean('foo')) custom_props_field.enabled = False self.assertEqual('foo', custom_props_field.clean('foo'))