summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_apps.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/postgres_tests/test_apps.py')
-rw-r--r--tests/postgres_tests/test_apps.py49
1 files changed, 31 insertions, 18 deletions
diff --git a/tests/postgres_tests/test_apps.py b/tests/postgres_tests/test_apps.py
index 94001822c2..340e555609 100644
--- a/tests/postgres_tests/test_apps.py
+++ b/tests/postgres_tests/test_apps.py
@@ -7,12 +7,12 @@ from django.test.utils import modify_settings
from . import PostgreSQLTestCase
try:
- from psycopg2.extras import (
- DateRange, DateTimeRange, DateTimeTZRange, NumericRange,
- )
+ from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, NumericRange
from django.contrib.postgres.fields import (
- DateRangeField, DateTimeRangeField, DecimalRangeField,
+ DateRangeField,
+ DateTimeRangeField,
+ DecimalRangeField,
IntegerRangeField,
)
except ImportError:
@@ -22,17 +22,24 @@ except ImportError:
class PostgresConfigTests(PostgreSQLTestCase):
def test_register_type_handlers_connection(self):
from django.contrib.postgres.signals import register_type_handlers
- self.assertNotIn(register_type_handlers, connection_created._live_receivers(None))
- with modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'}):
- self.assertIn(register_type_handlers, connection_created._live_receivers(None))
- self.assertNotIn(register_type_handlers, connection_created._live_receivers(None))
+
+ self.assertNotIn(
+ register_type_handlers, connection_created._live_receivers(None)
+ )
+ with modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"}):
+ self.assertIn(
+ register_type_handlers, connection_created._live_receivers(None)
+ )
+ self.assertNotIn(
+ register_type_handlers, connection_created._live_receivers(None)
+ )
def test_register_serializer_for_migrations(self):
tests = (
(DateRange(empty=True), DateRangeField),
(DateTimeRange(empty=True), DateRangeField),
- (DateTimeTZRange(None, None, '[]'), DateTimeRangeField),
- (NumericRange(Decimal('1.0'), Decimal('5.0'), '()'), DecimalRangeField),
+ (DateTimeTZRange(None, None, "[]"), DateTimeRangeField),
+ (NumericRange(Decimal("1.0"), Decimal("5.0"), "()"), DecimalRangeField),
(NumericRange(1, 10), IntegerRangeField),
)
@@ -40,25 +47,31 @@ class PostgresConfigTests(PostgreSQLTestCase):
for default, test_field in tests:
with self.subTest(default=default):
field = test_field(default=default)
- with self.assertRaisesMessage(ValueError, 'Cannot serialize: %s' % default.__class__.__name__):
+ with self.assertRaisesMessage(
+ ValueError, "Cannot serialize: %s" % default.__class__.__name__
+ ):
MigrationWriter.serialize(field)
assertNotSerializable()
- with self.modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'}):
+ with self.modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"}):
for default, test_field in tests:
with self.subTest(default=default):
field = test_field(default=default)
serialized_field, imports = MigrationWriter.serialize(field)
- self.assertEqual(imports, {
- 'import django.contrib.postgres.fields.ranges',
- 'import psycopg2.extras',
- })
+ self.assertEqual(
+ imports,
+ {
+ "import django.contrib.postgres.fields.ranges",
+ "import psycopg2.extras",
+ },
+ )
self.assertIn(
- '%s.%s(default=psycopg2.extras.%r)' % (
+ "%s.%s(default=psycopg2.extras.%r)"
+ % (
field.__module__,
field.__class__.__name__,
default,
),
- serialized_field
+ serialized_field,
)
assertNotSerializable()