django/tests/postgres_tests/test_introspection.py
Alasdair Nicol 0eb71b85bf [2.0.x] Fixed #29307 -- Fixed inspectdb import paths for django.contrib.postgres fields.
Thanks erindy for the report.

Backport of 65c44a5c1d5412d402af19480e3c1c3e3e88893a from master
2018-04-10 09:58:40 -04:00

41 lines
1.5 KiB
Python

from io import StringIO
from django.core.management import call_command
from django.test import skipUnlessDBFeature
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()
call_command(
'inspectdb',
table_name_filter=lambda tn: tn.startswith(model),
stdout=out,
)
output = out.getvalue()
for field_output in field_outputs:
self.assertIn(field_output, output)
@skipUnlessDBFeature('has_jsonb_datatype')
def test_json_field(self):
self.assertFieldsInModel(
'postgres_tests_jsonmodel',
['field = django.contrib.postgres.fields.JSONField(blank=True, null=True)'],
)
def test_range_fields(self):
self.assertFieldsInModel(
'postgres_tests_rangesmodel',
[
'ints = django.contrib.postgres.fields.IntegerRangeField(blank=True, null=True)',
'bigints = django.contrib.postgres.fields.BigIntegerRangeField(blank=True, null=True)',
'floats = django.contrib.postgres.fields.FloatRangeField(blank=True, null=True)',
'timestamps = django.contrib.postgres.fields.DateTimeRangeField(blank=True, null=True)',
'dates = django.contrib.postgres.fields.DateRangeField(blank=True, null=True)',
],
)