2017-09-09 14:39:09 +02:00
|
|
|
from io import StringIO
|
|
|
|
|
|
|
|
from django.core.management import call_command
|
|
|
|
|
|
|
|
from . import PostgreSQLTestCase
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2017-09-09 18:33:05 +02:00
|
|
|
def test_range_fields(self):
|
|
|
|
self.assertFieldsInModel(
|
|
|
|
"postgres_tests_rangesmodel",
|
|
|
|
[
|
2018-04-09 18:46:31 +02:00
|
|
|
"ints = django.contrib.postgres.fields.IntegerRangeField(blank=True, "
|
|
|
|
"null=True)",
|
|
|
|
"bigints = django.contrib.postgres.fields.BigIntegerRangeField("
|
|
|
|
"blank=True, null=True)",
|
2018-10-03 01:17:23 +02:00
|
|
|
"decimals = django.contrib.postgres.fields.DecimalRangeField("
|
|
|
|
"blank=True, null=True)",
|
2018-04-09 18:46:31 +02:00
|
|
|
"timestamps = django.contrib.postgres.fields.DateTimeRangeField("
|
|
|
|
"blank=True, null=True)",
|
|
|
|
"dates = django.contrib.postgres.fields.DateRangeField(blank=True, "
|
|
|
|
"null=True)",
|
2017-09-09 18:33:05 +02:00
|
|
|
],
|
|
|
|
)
|