mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Switched TestCase to SimpleTestCase where possible in Django's tests.
This commit is contained in:
parent
f091ea3515
commit
193c109327
37 changed files with 130 additions and 134 deletions
|
@ -1,8 +1,7 @@
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class ValidationTestCase(TestCase):
|
||||
class ValidationAssertions:
|
||||
def assertFailsValidation(self, clean, failed_fields, **kwargs):
|
||||
with self.assertRaises(ValidationError) as cm:
|
||||
clean(**kwargs)
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from . import ValidationTestCase
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from . import ValidationAssertions
|
||||
from .models import CustomMessagesModel
|
||||
|
||||
|
||||
class CustomMessagesTest(ValidationTestCase):
|
||||
class CustomMessagesTests(ValidationAssertions, SimpleTestCase):
|
||||
def test_custom_simple_validator_message(self):
|
||||
cmm = CustomMessagesModel(number=12)
|
||||
self.assertFieldFailsValidationWithMessage(cmm.full_clean, 'number', ['AAARGH'])
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from . import ValidationTestCase
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from . import ValidationAssertions
|
||||
from .models import ModelToValidate
|
||||
|
||||
|
||||
class TestModelsWithValidators(ValidationTestCase):
|
||||
class TestModelsWithValidators(ValidationAssertions, SimpleTestCase):
|
||||
def test_custom_validator_passes_for_correct_value(self):
|
||||
mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=42,
|
||||
f_with_iterable_of_validators=42)
|
||||
|
|
|
@ -3,14 +3,14 @@ from django.core.exceptions import NON_FIELD_ERRORS
|
|||
from django.test import TestCase
|
||||
from django.utils.functional import lazy
|
||||
|
||||
from . import ValidationTestCase
|
||||
from . import ValidationAssertions
|
||||
from .models import (
|
||||
Article, Author, GenericIPAddressTestModel, GenericIPAddrUnpackUniqueTest,
|
||||
ModelToValidate,
|
||||
)
|
||||
|
||||
|
||||
class BaseModelValidationTests(ValidationTestCase):
|
||||
class BaseModelValidationTests(ValidationAssertions, TestCase):
|
||||
|
||||
def test_missing_required_field_raises_error(self):
|
||||
mtv = ModelToValidate(f_with_custom_validator=42)
|
||||
|
@ -126,7 +126,7 @@ class ModelFormsTests(TestCase):
|
|||
self.assertEqual(list(form.errors), ['pub_date'])
|
||||
|
||||
|
||||
class GenericIPAddressFieldTests(ValidationTestCase):
|
||||
class GenericIPAddressFieldTests(ValidationAssertions, TestCase):
|
||||
|
||||
def test_correct_generic_ip_passes(self):
|
||||
giptm = GenericIPAddressTestModel(generic_ip="1.2.3.4")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue