mirror of
https://github.com/django/django.git
synced 2025-07-07 11:19:12 +00:00
[soc2009/model-validation] moved validation tests to tests.py out of models.py
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10878 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3ca1199da8
commit
afcb3c8872
@ -14,20 +14,3 @@ class ModelToValidate(models.Model):
|
||||
if self.number == 11:
|
||||
raise ValidationError('Invalid number supplied!')
|
||||
|
||||
class BaseModelValidationTests(TestCase):
|
||||
def test_missing_required_field_raises_error(self):
|
||||
mtv = ModelToValidate()
|
||||
self.assertRaises(ValidationError, mtv.clean)
|
||||
try:
|
||||
mtv.clean()
|
||||
except ValidationError, e:
|
||||
self.assertEquals(['name', 'number'], sorted(e.message_dict.keys()))
|
||||
|
||||
def test_with_correct_value_model_validates(self):
|
||||
mtv = ModelToValidate(number=10, name='Some Name')
|
||||
self.assertEqual(None, mtv.clean())
|
||||
|
||||
def test_custom_validate_method_is_called(self):
|
||||
mtv = ModelToValidate(number=11)
|
||||
self.assertRaises(ValidationError, mtv.clean)
|
||||
|
||||
|
22
tests/modeltests/validation/tests.py
Normal file
22
tests/modeltests/validation/tests.py
Normal file
@ -0,0 +1,22 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase
|
||||
|
||||
from models import ModelToValidate
|
||||
|
||||
class BaseModelValidationTests(TestCase):
|
||||
def test_missing_required_field_raises_error(self):
|
||||
mtv = ModelToValidate()
|
||||
self.assertRaises(ValidationError, mtv.clean)
|
||||
try:
|
||||
mtv.clean()
|
||||
except ValidationError, e:
|
||||
self.assertEquals(['name', 'number'], sorted(e.message_dict.keys()))
|
||||
|
||||
def test_with_correct_value_model_validates(self):
|
||||
mtv = ModelToValidate(number=10, name='Some Name')
|
||||
self.assertEqual(None, mtv.clean())
|
||||
|
||||
def test_custom_validate_method_is_called(self):
|
||||
mtv = ModelToValidate(number=11)
|
||||
self.assertRaises(ValidationError, mtv.clean)
|
||||
|
Loading…
x
Reference in New Issue
Block a user