mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Switched TestCase to SimpleTestCase where possible in Django's tests.
This commit is contained in:
@@ -3,7 +3,12 @@ import unittest
|
||||
from forms_tests.widget_tests.base import WidgetTest
|
||||
|
||||
from django.db import connection
|
||||
from django.test import TestCase, modify_settings
|
||||
from django.test import SimpleTestCase, TestCase, modify_settings
|
||||
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific tests")
|
||||
class PostgreSQLSimpleTestCase(SimpleTestCase):
|
||||
pass
|
||||
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific tests")
|
||||
@@ -14,5 +19,5 @@ class PostgreSQLTestCase(TestCase):
|
||||
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific tests")
|
||||
# To locate the widget's template.
|
||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
|
||||
class PostgreSQLWidgetTestCase(WidgetTest, PostgreSQLTestCase):
|
||||
class PostgreSQLWidgetTestCase(WidgetTest, PostgreSQLSimpleTestCase):
|
||||
pass
|
||||
|
||||
@@ -12,7 +12,9 @@ from django.test import TransactionTestCase, modify_settings, override_settings
|
||||
from django.test.utils import isolate_apps
|
||||
from django.utils import timezone
|
||||
|
||||
from . import PostgreSQLTestCase, PostgreSQLWidgetTestCase
|
||||
from . import (
|
||||
PostgreSQLSimpleTestCase, PostgreSQLTestCase, PostgreSQLWidgetTestCase,
|
||||
)
|
||||
from .models import (
|
||||
ArrayFieldSubclass, CharArrayModel, DateTimeArrayModel, IntegerArrayModel,
|
||||
NestedIntegerArrayModel, NullableIntegerArrayModel, OtherTypesArrayModel,
|
||||
@@ -440,7 +442,7 @@ class TestOtherTypesExactQuerying(PostgreSQLTestCase):
|
||||
|
||||
|
||||
@isolate_apps('postgres_tests')
|
||||
class TestChecks(PostgreSQLTestCase):
|
||||
class TestChecks(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_field_checks(self):
|
||||
class MyModel(PostgreSQLModel):
|
||||
@@ -589,7 +591,7 @@ class TestMigrations(TransactionTestCase):
|
||||
self.assertNotIn(table_name, connection.introspection.table_names(cursor))
|
||||
|
||||
|
||||
class TestSerialization(PostgreSQLTestCase):
|
||||
class TestSerialization(PostgreSQLSimpleTestCase):
|
||||
test_data = (
|
||||
'[{"fields": {"field": "[\\"1\\", \\"2\\", null]"}, "model": "postgres_tests.integerarraymodel", "pk": null}]'
|
||||
)
|
||||
@@ -604,7 +606,7 @@ class TestSerialization(PostgreSQLTestCase):
|
||||
self.assertEqual(instance.field, [1, 2, None])
|
||||
|
||||
|
||||
class TestValidation(PostgreSQLTestCase):
|
||||
class TestValidation(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_unbounded(self):
|
||||
field = ArrayField(models.IntegerField())
|
||||
@@ -664,7 +666,7 @@ class TestValidation(PostgreSQLTestCase):
|
||||
self.assertEqual(exception.params, {'nth': 1, 'value': 0, 'limit_value': 1, 'show_value': 0})
|
||||
|
||||
|
||||
class TestSimpleFormField(PostgreSQLTestCase):
|
||||
class TestSimpleFormField(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_valid(self):
|
||||
field = SimpleArrayField(forms.CharField())
|
||||
@@ -782,7 +784,7 @@ class TestSimpleFormField(PostgreSQLTestCase):
|
||||
self.assertIs(field.has_changed([], ''), False)
|
||||
|
||||
|
||||
class TestSplitFormField(PostgreSQLTestCase):
|
||||
class TestSplitFormField(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_valid(self):
|
||||
class SplitForm(forms.Form):
|
||||
|
||||
@@ -2,9 +2,9 @@ import json
|
||||
|
||||
from django.core import checks, exceptions, serializers
|
||||
from django.forms import Form
|
||||
from django.test.utils import isolate_apps, modify_settings
|
||||
from django.test.utils import isolate_apps
|
||||
|
||||
from . import PostgreSQLTestCase
|
||||
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
||||
from .models import HStoreModel, PostgreSQLModel
|
||||
|
||||
try:
|
||||
@@ -15,12 +15,7 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
|
||||
class HStoreTestCase(PostgreSQLTestCase):
|
||||
pass
|
||||
|
||||
|
||||
class SimpleTests(HStoreTestCase):
|
||||
class SimpleTests(PostgreSQLTestCase):
|
||||
def test_save_load_success(self):
|
||||
value = {'a': 'b'}
|
||||
instance = HStoreModel(field=value)
|
||||
@@ -69,7 +64,7 @@ class SimpleTests(HStoreTestCase):
|
||||
self.assertEqual(instance.array_field, expected_value)
|
||||
|
||||
|
||||
class TestQuerying(HStoreTestCase):
|
||||
class TestQuerying(PostgreSQLTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.objs = [
|
||||
@@ -191,7 +186,7 @@ class TestQuerying(HStoreTestCase):
|
||||
|
||||
|
||||
@isolate_apps('postgres_tests')
|
||||
class TestChecks(PostgreSQLTestCase):
|
||||
class TestChecks(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_invalid_default(self):
|
||||
class MyModel(PostgreSQLModel):
|
||||
@@ -218,7 +213,7 @@ class TestChecks(PostgreSQLTestCase):
|
||||
self.assertEqual(MyModel().check(), [])
|
||||
|
||||
|
||||
class TestSerialization(HStoreTestCase):
|
||||
class TestSerialization(PostgreSQLSimpleTestCase):
|
||||
test_data = json.dumps([{
|
||||
'model': 'postgres_tests.hstoremodel',
|
||||
'pk': None,
|
||||
@@ -248,7 +243,7 @@ class TestSerialization(HStoreTestCase):
|
||||
self.assertEqual(instance.field, new_instance.field)
|
||||
|
||||
|
||||
class TestValidation(HStoreTestCase):
|
||||
class TestValidation(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_not_a_string(self):
|
||||
field = HStoreField()
|
||||
@@ -262,7 +257,7 @@ class TestValidation(HStoreTestCase):
|
||||
self.assertEqual(field.clean({'a': None}, None), {'a': None})
|
||||
|
||||
|
||||
class TestFormField(HStoreTestCase):
|
||||
class TestFormField(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_valid(self):
|
||||
field = forms.HStoreField()
|
||||
@@ -325,7 +320,7 @@ class TestFormField(HStoreTestCase):
|
||||
self.assertTrue(form_w_hstore.has_changed())
|
||||
|
||||
|
||||
class TestValidator(HStoreTestCase):
|
||||
class TestValidator(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_simple_valid(self):
|
||||
validator = KeysValidator(keys=['a', 'b'])
|
||||
|
||||
@@ -11,7 +11,7 @@ from django.db.utils import NotSupportedError
|
||||
from django.test import skipUnlessDBFeature
|
||||
from django.test.utils import register_lookup
|
||||
|
||||
from . import PostgreSQLTestCase
|
||||
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
||||
from .models import CharFieldModel, IntegerArrayModel
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class IndexTestMixin:
|
||||
|
||||
|
||||
@skipUnlessDBFeature('has_brin_index_support')
|
||||
class BrinIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
class BrinIndexTests(IndexTestMixin, PostgreSQLSimpleTestCase):
|
||||
index_class = BrinIndex
|
||||
|
||||
def test_suffix(self):
|
||||
@@ -54,7 +54,7 @@ class BrinIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
BrinIndex(fields=['title'], name='test_title_brin', pages_per_range=0)
|
||||
|
||||
|
||||
class BTreeIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
class BTreeIndexTests(IndexTestMixin, PostgreSQLSimpleTestCase):
|
||||
index_class = BTreeIndex
|
||||
|
||||
def test_suffix(self):
|
||||
@@ -68,7 +68,7 @@ class BTreeIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_btree', 'fillfactor': 80})
|
||||
|
||||
|
||||
class GinIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
class GinIndexTests(IndexTestMixin, PostgreSQLSimpleTestCase):
|
||||
index_class = GinIndex
|
||||
|
||||
def test_suffix(self):
|
||||
@@ -92,7 +92,7 @@ class GinIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
})
|
||||
|
||||
|
||||
class GistIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
class GistIndexTests(IndexTestMixin, PostgreSQLSimpleTestCase):
|
||||
index_class = GistIndex
|
||||
|
||||
def test_suffix(self):
|
||||
@@ -111,7 +111,7 @@ class GistIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
})
|
||||
|
||||
|
||||
class HashIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
class HashIndexTests(IndexTestMixin, PostgreSQLSimpleTestCase):
|
||||
index_class = HashIndex
|
||||
|
||||
def test_suffix(self):
|
||||
@@ -125,7 +125,7 @@ class HashIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_hash', 'fillfactor': 80})
|
||||
|
||||
|
||||
class SpGistIndexTests(IndexTestMixin, PostgreSQLTestCase):
|
||||
class SpGistIndexTests(IndexTestMixin, PostgreSQLSimpleTestCase):
|
||||
index_class = SpGistIndex
|
||||
|
||||
def test_suffix(self):
|
||||
|
||||
@@ -9,7 +9,7 @@ from django.forms import CharField, Form, widgets
|
||||
from django.test.utils import isolate_apps
|
||||
from django.utils.html import escape
|
||||
|
||||
from . import PostgreSQLTestCase
|
||||
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
||||
from .models import JSONModel, PostgreSQLModel
|
||||
|
||||
try:
|
||||
@@ -301,7 +301,7 @@ class TestQuerying(PostgreSQLTestCase):
|
||||
|
||||
|
||||
@isolate_apps('postgres_tests')
|
||||
class TestChecks(PostgreSQLTestCase):
|
||||
class TestChecks(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_invalid_default(self):
|
||||
class MyModel(PostgreSQLModel):
|
||||
@@ -336,7 +336,7 @@ class TestChecks(PostgreSQLTestCase):
|
||||
self.assertEqual(model.check(), [])
|
||||
|
||||
|
||||
class TestSerialization(PostgreSQLTestCase):
|
||||
class TestSerialization(PostgreSQLSimpleTestCase):
|
||||
test_data = (
|
||||
'[{"fields": {"field": %s, "field_custom": null}, '
|
||||
'"model": "postgres_tests.jsonmodel", "pk": null}]'
|
||||
@@ -362,7 +362,7 @@ class TestSerialization(PostgreSQLTestCase):
|
||||
self.assertEqual(instance.field, value)
|
||||
|
||||
|
||||
class TestValidation(PostgreSQLTestCase):
|
||||
class TestValidation(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_not_serializable(self):
|
||||
field = JSONField()
|
||||
@@ -378,7 +378,7 @@ class TestValidation(PostgreSQLTestCase):
|
||||
self.assertEqual(field.clean(datetime.timedelta(days=1), None), datetime.timedelta(days=1))
|
||||
|
||||
|
||||
class TestFormField(PostgreSQLTestCase):
|
||||
class TestFormField(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_valid(self):
|
||||
field = forms.JSONField()
|
||||
|
||||
@@ -9,7 +9,7 @@ from django.test import ignore_warnings, override_settings
|
||||
from django.utils import timezone
|
||||
from django.utils.deprecation import RemovedInDjango31Warning
|
||||
|
||||
from . import PostgreSQLTestCase
|
||||
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
||||
from .models import RangeLookupsModel, RangesModel
|
||||
|
||||
try:
|
||||
@@ -355,7 +355,7 @@ class TestQueryingWithRanges(PostgreSQLTestCase):
|
||||
)
|
||||
|
||||
|
||||
class TestSerialization(PostgreSQLTestCase):
|
||||
class TestSerialization(PostgreSQLSimpleTestCase):
|
||||
test_data = (
|
||||
'[{"fields": {"ints": "{\\"upper\\": \\"10\\", \\"lower\\": \\"0\\", '
|
||||
'\\"bounds\\": \\"[)\\"}", "decimals": "{\\"empty\\": true}", '
|
||||
@@ -405,7 +405,7 @@ class TestSerialization(PostgreSQLTestCase):
|
||||
self.assertEqual(new_instance.ints, NumericRange(10, None))
|
||||
|
||||
|
||||
class TestValidators(PostgreSQLTestCase):
|
||||
class TestValidators(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_max(self):
|
||||
validator = RangeMaxValueValidator(5)
|
||||
@@ -430,7 +430,7 @@ class TestValidators(PostgreSQLTestCase):
|
||||
validator(NumericRange(None, 10)) # an unbound range
|
||||
|
||||
|
||||
class TestFormField(PostgreSQLTestCase):
|
||||
class TestFormField(PostgreSQLSimpleTestCase):
|
||||
|
||||
def test_valid_integer(self):
|
||||
field = pg_forms.IntegerRangeField()
|
||||
@@ -708,7 +708,7 @@ class TestFormField(PostgreSQLTestCase):
|
||||
self.assertIsInstance(form_field, pg_forms.DateTimeRangeField)
|
||||
|
||||
|
||||
class TestWidget(PostgreSQLTestCase):
|
||||
class TestWidget(PostgreSQLSimpleTestCase):
|
||||
def test_range_widget(self):
|
||||
f = pg_forms.ranges.DateTimeRangeField()
|
||||
self.assertHTMLEqual(
|
||||
|
||||
Reference in New Issue
Block a user