summaryrefslogtreecommitdiff
path: root/tests/postgres_tests
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2022-12-01 09:39:46 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-01 09:39:46 +0100
commit149b55fefad03c18589d580ef53d41e7c99408ed (patch)
treee9b9118d1b6b76598746d37c1b0eeb484e78c61f /tests/postgres_tests
parent3cafb783f3f711c7413ba2b8d7c8ff750bd4d6e1 (diff)
downloaddjango-149b55fefad03c18589d580ef53d41e7c99408ed.tar.gz
Refs #33308 -- Ensured type handlers are registered for all PostgreSQL specific tests.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/postgres_tests')
-rw-r--r--tests/postgres_tests/__init__.py4
-rw-r--r--tests/postgres_tests/test_apps.py8
-rw-r--r--tests/postgres_tests/test_array.py9
-rw-r--r--tests/postgres_tests/test_bulk_update.py3
-rw-r--r--tests/postgres_tests/test_citext.py2
-rw-r--r--tests/postgres_tests/test_constraints.py5
-rw-r--r--tests/postgres_tests/test_indexes.py3
-rw-r--r--tests/postgres_tests/test_introspection.py2
-rw-r--r--tests/postgres_tests/test_search.py6
-rw-r--r--tests/postgres_tests/test_trigram.py3
-rw-r--r--tests/postgres_tests/test_unaccent.py2
11 files changed, 12 insertions, 35 deletions
diff --git a/tests/postgres_tests/__init__.py b/tests/postgres_tests/__init__.py
index 6f02531ed0..9f78f5afd8 100644
--- a/tests/postgres_tests/__init__.py
+++ b/tests/postgres_tests/__init__.py
@@ -7,11 +7,15 @@ from django.test import SimpleTestCase, TestCase, modify_settings
@unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests")
+# To register type handlers and locate the widget's template.
+@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class PostgreSQLSimpleTestCase(SimpleTestCase):
pass
@unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests")
+# To register type handlers and locate the widget's template.
+@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class PostgreSQLTestCase(TestCase):
pass
diff --git a/tests/postgres_tests/test_apps.py b/tests/postgres_tests/test_apps.py
index 340e555609..678e5a9374 100644
--- a/tests/postgres_tests/test_apps.py
+++ b/tests/postgres_tests/test_apps.py
@@ -1,11 +1,12 @@
+import unittest
from decimal import Decimal
+from django.db import connection
from django.db.backends.signals import connection_created
from django.db.migrations.writer import MigrationWriter
+from django.test import TestCase
from django.test.utils import modify_settings
-from . import PostgreSQLTestCase
-
try:
from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, NumericRange
@@ -19,7 +20,8 @@ except ImportError:
pass
-class PostgresConfigTests(PostgreSQLTestCase):
+@unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests")
+class PostgresConfigTests(TestCase):
def test_register_type_handlers_connection(self):
from django.contrib.postgres.signals import register_type_handlers
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 9e20ab3baf..e1d9be6c02 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -12,12 +12,7 @@ from django.core.management import call_command
from django.db import IntegrityError, connection, models
from django.db.models.expressions import Exists, OuterRef, RawSQL, Value
from django.db.models.functions import Cast, JSONObject, Upper
-from django.test import (
- TransactionTestCase,
- modify_settings,
- override_settings,
- skipUnlessDBFeature,
-)
+from django.test import TransactionTestCase, override_settings, skipUnlessDBFeature
from django.test.utils import isolate_apps
from django.utils import timezone
@@ -1259,8 +1254,6 @@ class TestSplitFormField(PostgreSQLSimpleTestCase):
with self.assertRaisesMessage(exceptions.ValidationError, msg):
SplitArrayField(forms.IntegerField(max_value=100), size=2).clean([0, 101])
- # To locate the widget's template.
- @modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
def test_rendering(self):
class SplitForm(forms.Form):
array = SplitArrayField(forms.CharField(), size=3)
diff --git a/tests/postgres_tests/test_bulk_update.py b/tests/postgres_tests/test_bulk_update.py
index 5f91f77791..f0b473efa7 100644
--- a/tests/postgres_tests/test_bulk_update.py
+++ b/tests/postgres_tests/test_bulk_update.py
@@ -1,7 +1,5 @@
from datetime import date
-from django.test import modify_settings
-
from . import PostgreSQLTestCase
from .models import (
HStoreModel,
@@ -18,7 +16,6 @@ except ImportError:
pass # psycopg2 isn't installed.
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class BulkSaveTests(PostgreSQLTestCase):
def test_bulk_update(self):
test_data = [
diff --git a/tests/postgres_tests/test_citext.py b/tests/postgres_tests/test_citext.py
index 314f2e40d3..2abb56b39f 100644
--- a/tests/postgres_tests/test_citext.py
+++ b/tests/postgres_tests/test_citext.py
@@ -5,14 +5,12 @@ strings and thus eliminates the need for operations such as iexact and other
modifiers to enforce use of an index.
"""
from django.db import IntegrityError
-from django.test.utils import modify_settings
from django.utils.deprecation import RemovedInDjango51Warning
from . import PostgreSQLTestCase
from .models import CITestModel
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class CITextTestCase(PostgreSQLTestCase):
case_sensitive_lookups = ("contains", "startswith", "endswith", "regex")
diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py
index 5084f116ab..72e3e66895 100644
--- a/tests/postgres_tests/test_constraints.py
+++ b/tests/postgres_tests/test_constraints.py
@@ -16,7 +16,7 @@ from django.db.models import (
)
from django.db.models.fields.json import KeyTextTransform
from django.db.models.functions import Cast, Left, Lower
-from django.test import ignore_warnings, modify_settings, skipUnlessDBFeature
+from django.test import ignore_warnings, skipUnlessDBFeature
from django.test.utils import isolate_apps
from django.utils import timezone
from django.utils.deprecation import RemovedInDjango50Warning
@@ -37,7 +37,6 @@ except ImportError:
pass
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class SchemaTests(PostgreSQLTestCase):
get_opclass_query = """
SELECT opcname, c.relname FROM pg_opclass AS oc
@@ -255,7 +254,6 @@ class SchemaTests(PostgreSQLTestCase):
Scene.objects.create(scene="ScEnE 10", setting="Sir Bedemir's Castle")
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class ExclusionConstraintTests(PostgreSQLTestCase):
def get_constraints(self, table):
"""Get the constraints on the table using a new cursor."""
@@ -1198,7 +1196,6 @@ class ExclusionConstraintTests(PostgreSQLTestCase):
)
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class ExclusionConstraintOpclassesDepracationTests(PostgreSQLTestCase):
def get_constraints(self, table):
"""Get the constraints on the table using a new cursor."""
diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py
index dc1064b35d..52bfcbeb06 100644
--- a/tests/postgres_tests/test_indexes.py
+++ b/tests/postgres_tests/test_indexes.py
@@ -15,7 +15,7 @@ from django.db import NotSupportedError, connection
from django.db.models import CharField, F, Index, Q
from django.db.models.functions import Cast, Collate, Length, Lower
from django.test import skipUnlessDBFeature
-from django.test.utils import modify_settings, register_lookup
+from django.test.utils import register_lookup
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
from .fields import SearchVector, SearchVectorField
@@ -235,7 +235,6 @@ class SpGistIndexTests(IndexTestMixin, PostgreSQLSimpleTestCase):
)
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class SchemaTests(PostgreSQLTestCase):
get_opclass_query = """
SELECT opcname, c.relname FROM pg_opclass AS oc
diff --git a/tests/postgres_tests/test_introspection.py b/tests/postgres_tests/test_introspection.py
index 3179b47cc9..73c426d1ba 100644
--- a/tests/postgres_tests/test_introspection.py
+++ b/tests/postgres_tests/test_introspection.py
@@ -1,12 +1,10 @@
from io import StringIO
from django.core.management import call_command
-from django.test.utils import modify_settings
from . import PostgreSQLTestCase
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class InspectDBTests(PostgreSQLTestCase):
def assertFieldsInModel(self, model, field_outputs):
out = StringIO()
diff --git a/tests/postgres_tests/test_search.py b/tests/postgres_tests/test_search.py
index d085ac852c..92ea8d3e33 100644
--- a/tests/postgres_tests/test_search.py
+++ b/tests/postgres_tests/test_search.py
@@ -7,7 +7,6 @@ transcript.
"""
from django.db import connection
from django.db.models import F, Value
-from django.test import modify_settings
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
from .models import Character, Line, LineSavedSearch, Scene
@@ -103,7 +102,6 @@ class GrailTestData:
)
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class SimpleSearchTest(GrailTestData, PostgreSQLTestCase):
def test_simple(self):
searched = Line.objects.filter(dialogue__search="elbows")
@@ -140,7 +138,6 @@ class SimpleSearchTest(GrailTestData, PostgreSQLTestCase):
self.assertSequenceEqual(searched, [match])
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class SearchVectorFieldTest(GrailTestData, PostgreSQLTestCase):
def test_existing_vector(self):
Line.objects.update(dialogue_search_vector=SearchVector("dialogue"))
@@ -339,7 +336,6 @@ class MultipleFieldsTest(GrailTestData, PostgreSQLTestCase):
self.assertSequenceEqual(searched, [self.french])
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class TestCombinations(GrailTestData, PostgreSQLTestCase):
def test_vector_add(self):
searched = Line.objects.annotate(
@@ -462,7 +458,6 @@ class TestCombinations(GrailTestData, PostgreSQLTestCase):
Line.objects.filter(dialogue__search=None & SearchQuery("kneecaps"))
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class TestRankingAndWeights(GrailTestData, PostgreSQLTestCase):
def test_ranking(self):
searched = (
@@ -661,7 +656,6 @@ class SearchQueryTests(PostgreSQLSimpleTestCase):
self.assertEqual(str(query), expected_str)
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class SearchHeadlineTests(GrailTestData, PostgreSQLTestCase):
def test_headline(self):
searched = Line.objects.annotate(
diff --git a/tests/postgres_tests/test_trigram.py b/tests/postgres_tests/test_trigram.py
index 3fa0550441..812403a324 100644
--- a/tests/postgres_tests/test_trigram.py
+++ b/tests/postgres_tests/test_trigram.py
@@ -1,5 +1,3 @@
-from django.test import modify_settings
-
from . import PostgreSQLTestCase
from .models import CharFieldModel, TextFieldModel
@@ -16,7 +14,6 @@ except ImportError:
pass
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class TrigramTest(PostgreSQLTestCase):
Model = CharFieldModel
diff --git a/tests/postgres_tests/test_unaccent.py b/tests/postgres_tests/test_unaccent.py
index a512184589..6d115773d4 100644
--- a/tests/postgres_tests/test_unaccent.py
+++ b/tests/postgres_tests/test_unaccent.py
@@ -1,11 +1,9 @@
from django.db import connection
-from django.test import modify_settings
from . import PostgreSQLTestCase
from .models import CharFieldModel, TextFieldModel
-@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class UnaccentTest(PostgreSQLTestCase):
Model = CharFieldModel