mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Merged soc2009/model-validation to trunk. Thanks, Honza!
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12098 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4e89105d64
commit
471596fc1a
63 changed files with 1550 additions and 639 deletions
|
@ -147,6 +147,58 @@ class SlugFieldTests(django.test.TestCase):
|
|||
bs = BigS.objects.get(pk=bs.pk)
|
||||
self.assertEqual(bs.s, 'slug'*50)
|
||||
|
||||
|
||||
class ValidationTest(django.test.TestCase):
|
||||
def test_charfield_raises_error_on_empty_string(self):
|
||||
f = models.CharField()
|
||||
self.assertRaises(ValidationError, f.clean, "", None)
|
||||
|
||||
def test_charfield_cleans_empty_string_when_blank_true(self):
|
||||
f = models.CharField(blank=True)
|
||||
self.assertEqual('', f.clean('', None))
|
||||
|
||||
def test_integerfield_cleans_valid_string(self):
|
||||
f = models.IntegerField()
|
||||
self.assertEqual(2, f.clean('2', None))
|
||||
|
||||
def test_integerfield_raises_error_on_invalid_intput(self):
|
||||
f = models.IntegerField()
|
||||
self.assertRaises(ValidationError, f.clean, "a", None)
|
||||
|
||||
def test_charfield_with_choices_cleans_valid_choice(self):
|
||||
f = models.CharField(max_length=1, choices=[('a','A'), ('b','B')])
|
||||
self.assertEqual('a', f.clean('a', None))
|
||||
|
||||
def test_charfield_with_choices_raises_error_on_invalid_choice(self):
|
||||
f = models.CharField(choices=[('a','A'), ('b','B')])
|
||||
self.assertRaises(ValidationError, f.clean, "not a", None)
|
||||
|
||||
def test_nullable_integerfield_raises_error_with_blank_false(self):
|
||||
f = models.IntegerField(null=True, blank=False)
|
||||
self.assertRaises(ValidationError, f.clean, None, None)
|
||||
|
||||
def test_nullable_integerfield_cleans_none_on_null_and_blank_true(self):
|
||||
f = models.IntegerField(null=True, blank=True)
|
||||
self.assertEqual(None, f.clean(None, None))
|
||||
|
||||
def test_integerfield_raises_error_on_empty_input(self):
|
||||
f = models.IntegerField(null=False)
|
||||
self.assertRaises(ValidationError, f.clean, None, None)
|
||||
self.assertRaises(ValidationError, f.clean, '', None)
|
||||
|
||||
def test_charfield_raises_error_on_empty_input(self):
|
||||
f = models.CharField(null=False)
|
||||
self.assertRaises(ValidationError, f.clean, None, None)
|
||||
|
||||
def test_datefield_cleans_date(self):
|
||||
f = models.DateField()
|
||||
self.assertEqual(datetime.date(2008, 10, 10), f.clean('2008-10-10', None))
|
||||
|
||||
def test_boolean_field_doesnt_accept_empty_input(self):
|
||||
f = models.BooleanField()
|
||||
self.assertRaises(ValidationError, f.clean, None, None)
|
||||
|
||||
|
||||
class BigIntegerFieldTests(django.test.TestCase):
|
||||
def test_limits(self):
|
||||
# Ensure that values that are right at the limits can be saved
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue