test_introspection.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from io import StringIO
  2. from django.core.management import call_command
  3. from . import PostgreSQLTestCase
  4. class InspectDBTests(PostgreSQLTestCase):
  5. def assertFieldsInModel(self, model, field_outputs):
  6. out = StringIO()
  7. call_command(
  8. "inspectdb",
  9. table_name_filter=lambda tn: tn.startswith(model),
  10. stdout=out,
  11. )
  12. output = out.getvalue()
  13. for field_output in field_outputs:
  14. self.assertIn(field_output, output)
  15. def test_range_fields(self):
  16. self.assertFieldsInModel(
  17. "postgres_tests_rangesmodel",
  18. [
  19. "ints = django.contrib.postgres.fields.IntegerRangeField(blank=True, "
  20. "null=True)",
  21. "bigints = django.contrib.postgres.fields.BigIntegerRangeField("
  22. "blank=True, null=True)",
  23. "decimals = django.contrib.postgres.fields.DecimalRangeField("
  24. "blank=True, null=True)",
  25. "timestamps = django.contrib.postgres.fields.DateTimeRangeField("
  26. "blank=True, null=True)",
  27. "dates = django.contrib.postgres.fields.DateRangeField(blank=True, "
  28. "null=True)",
  29. ],
  30. )