File: test_introspection.py

package info (click to toggle)
python-django 3%3A3.2.19-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 56,696 kB
  • sloc: python: 264,418; javascript: 18,362; xml: 193; makefile: 178; sh: 43
file content (32 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)',
            ],
        )