Ticket #14152: tests.diff

File tests.diff, 2.1 KB (added by ludovicofischer, 14 years ago)

Test for this case

  • tests/modeltests/validation/models.py

    diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
    index dd42936..6c5f1e3 100644
    a b class ModelToValidate(models.Model):  
    1616    email = models.EmailField(blank=True)
    1717    url = models.URLField(blank=True)
    1818    f_with_custom_validator = models.IntegerField(blank=True, null=True, validators=[validate_answer_to_universe])
    19 
    2019    def clean(self):
    2120        super(ModelToValidate, self).clean()
    2221        if self.number == 11:
    2322            raise ValidationError('Invalid number supplied!')
    2423
     24class ModelWithNonBlank(models.Model):
     25    f_non_blank = models.IntegerField(blank=False)
     26    def clean(self):
     27        super(ModelWithNonBlank, self).clean()
     28        if not self.f_non_blank:
     29            self.f_non_blank = 12
     30
    2531class UniqueFieldsModel(models.Model):
    2632    unique_charfield = models.CharField(max_length=100, unique=True)
    2733    unique_integerfield = models.IntegerField(unique=True)
  • tests/modeltests/validation/tests.py

    diff --git a/tests/modeltests/validation/tests.py b/tests/modeltests/validation/tests.py
    index 0027393..23f2404 100644
    a b from django import forms  
    22from django.test import TestCase
    33from django.core.exceptions import NON_FIELD_ERRORS
    44from modeltests.validation import ValidationTestCase
    5 from modeltests.validation.models import Author, Article, ModelToValidate
     5from modeltests.validation.models import Author, Article, ModelToValidate, ModelWithNonBlank
    66
    77# Import other tests for this package.
    88from modeltests.validation.validators import TestModelsWithValidators
    class BaseModelValidationTests(ValidationTestCase):  
    6464        mtv = ModelToValidate(number=10, name='Some Name'*100)
    6565        self.assertFailsValidation(mtv.full_clean, ['name',])
    6666
     67    def test_blank_passes(self):
     68        mwnb = ModelWithNonBlank()
     69        self.assertEqual(None, mwnb.full_clean())
     70
    6771class ArticleForm(forms.ModelForm):
    6872    class Meta:
    6973        model = Article
Back to Top