1
0
mirror of https://github.com/django/django.git synced 2024-12-24 10:05:46 +00:00
django/tests/postgres_tests/test_introspection.py
sage 6789ded0a6 Fixed #12990, Refs #27694 -- Added JSONField model field.
Thanks to Adam Johnson, Carlton Gibson, Mariusz Felisiak, and Raphael
Michel for mentoring this Google Summer of Code 2019 project and
everyone else who helped with the patch.

Special thanks to Mads Jensen, Nick Pope, and Simon Charette for
extensive reviews.

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2020-05-08 07:23:31 +02:00

33 lines
1.2 KiB
Python

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()
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)
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)',
'decimals = django.contrib.postgres.fields.DecimalRangeField(blank=True, null=True)',
'timestamps = django.contrib.postgres.fields.DateTimeRangeField(blank=True, null=True)',
'dates = django.contrib.postgres.fields.DateRangeField(blank=True, null=True)',
],
)