Skip to content

Commit

Permalink
Refs #33308 -- Ensured type handlers are registered for all PostgreSQ…
Browse files Browse the repository at this point in the history
…L specific tests.

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
  • Loading branch information
apollo13 and felixxm committed Dec 1, 2022
1 parent 3cafb78 commit 149b55f
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 35 deletions.
4 changes: 4 additions & 0 deletions tests/postgres_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@


@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

Expand Down
8 changes: 5 additions & 3 deletions tests/postgres_tests/test_apps.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -19,7 +20,8 @@
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

Expand Down
9 changes: 1 addition & 8 deletions tests/postgres_tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
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

Expand Down Expand Up @@ -1259,8 +1254,6 @@ def test_invalid_integer(self):
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)
Expand Down
3 changes: 0 additions & 3 deletions tests/postgres_tests/test_bulk_update.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from datetime import date

from django.test import modify_settings

from . import PostgreSQLTestCase
from .models import (
HStoreModel,
Expand All @@ -18,7 +16,6 @@
pass # psycopg2 isn't installed.


@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class BulkSaveTests(PostgreSQLTestCase):
def test_bulk_update(self):
test_data = [
Expand Down
2 changes: 0 additions & 2 deletions tests/postgres_tests/test_citext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
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")

Expand Down
5 changes: 1 addition & 4 deletions tests/postgres_tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
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
Expand All @@ -37,7 +37,6 @@
pass


@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class SchemaTests(PostgreSQLTestCase):
get_opclass_query = """
SELECT opcname, c.relname FROM pg_opclass AS oc
Expand Down Expand Up @@ -255,7 +254,6 @@ def test_opclass_func(self):
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."""
Expand Down Expand Up @@ -1198,7 +1196,6 @@ class Meta:
)


@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."""
Expand Down
3 changes: 1 addition & 2 deletions tests/postgres_tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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
Expand Down Expand Up @@ -235,7 +235,6 @@ def test_deconstruction(self):
)


@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class SchemaTests(PostgreSQLTestCase):
get_opclass_query = """
SELECT opcname, c.relname FROM pg_opclass AS oc
Expand Down
2 changes: 0 additions & 2 deletions tests/postgres_tests/test_introspection.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
6 changes: 0 additions & 6 deletions tests/postgres_tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""
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
Expand Down Expand Up @@ -103,7 +102,6 @@ def setUpTestData(cls):
)


@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class SimpleSearchTest(GrailTestData, PostgreSQLTestCase):
def test_simple(self):
searched = Line.objects.filter(dialogue__search="elbows")
Expand Down Expand Up @@ -140,7 +138,6 @@ def test_search_with_F_expression(self):
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"))
Expand Down Expand Up @@ -339,7 +336,6 @@ def test_config_from_field_implicit(self):
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(
Expand Down Expand Up @@ -462,7 +458,6 @@ def test_query_combined_mismatch(self):
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 = (
Expand Down Expand Up @@ -661,7 +656,6 @@ def test_str(self):
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(
Expand Down
3 changes: 0 additions & 3 deletions tests/postgres_tests/test_trigram.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.test import modify_settings

from . import PostgreSQLTestCase
from .models import CharFieldModel, TextFieldModel

Expand All @@ -16,7 +14,6 @@
pass


@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
class TrigramTest(PostgreSQLTestCase):
Model = CharFieldModel

Expand Down
2 changes: 0 additions & 2 deletions tests/postgres_tests/test_unaccent.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 149b55f

Please sign in to comment.