summaryrefslogtreecommitdiff
path: root/tests/postgres_tests
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2022-12-01 20:23:43 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-15 06:17:57 +0100
commit09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca (patch)
tree15bb8bb049f9339f30d637e78b340473c2038126 /tests/postgres_tests
parentd44ee518c4c110af25bebdbedbbf9fba04d197aa (diff)
downloaddjango-09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca.tar.gz
Fixed #33308 -- Added support for psycopg version 3.
Thanks Simon Charette, Tim Graham, and Adam Johnson for reviews. Co-authored-by: Florian Apolloner <florian@apolloner.eu> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/postgres_tests')
-rw-r--r--tests/postgres_tests/test_apps.py12
-rw-r--r--tests/postgres_tests/test_array.py2
2 files changed, 6 insertions, 8 deletions
diff --git a/tests/postgres_tests/test_apps.py b/tests/postgres_tests/test_apps.py
index 7c4cc38183..d9fb962251 100644
--- a/tests/postgres_tests/test_apps.py
+++ b/tests/postgres_tests/test_apps.py
@@ -19,6 +19,7 @@ try:
DateTimeRange,
DateTimeTZRange,
NumericRange,
+ is_psycopg3,
)
except ImportError:
pass
@@ -59,6 +60,7 @@ class PostgresConfigTests(TestCase):
MigrationWriter.serialize(field)
assertNotSerializable()
+ import_name = "psycopg.types.range" if is_psycopg3 else "psycopg2.extras"
with self.modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"}):
for default, test_field in tests:
with self.subTest(default=default):
@@ -68,16 +70,12 @@ class PostgresConfigTests(TestCase):
imports,
{
"import django.contrib.postgres.fields.ranges",
- "import psycopg2.extras",
+ f"import {import_name}",
},
)
self.assertIn(
- "%s.%s(default=psycopg2.extras.%r)"
- % (
- field.__module__,
- field.__class__.__name__,
- default,
- ),
+ f"{field.__module__}.{field.__class__.__name__}"
+ f"(default={import_name}.{default!r})",
serialized_field,
)
assertNotSerializable()
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index a3c26fddae..86e9d00b41 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -317,7 +317,7 @@ class TestQuerying(PostgreSQLTestCase):
def test_in_including_F_object(self):
# This test asserts that Array objects passed to filters can be
# constructed to contain F objects. This currently doesn't work as the
- # psycopg2 mogrify method that generates the ARRAY() syntax is
+ # psycopg mogrify method that generates the ARRAY() syntax is
# expecting literals, not column references (#27095).
self.assertSequenceEqual(
NullableIntegerArrayModel.objects.filter(field__in=[[models.F("id")]]),