1
0
mirror of https://github.com/django/django.git synced 2025-07-07 19:29: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:
Honza Král 2009-06-01 15:42:13 +00:00
parent 3ca1199da8
commit afcb3c8872
2 changed files with 22 additions and 17 deletions

View File

@ -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)

View 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)