diff options
author | Nick Pope <nick.pope@flightdataservices.com> | 2018-09-12 21:53:24 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-11-19 14:06:01 -0500 |
commit | ebd270627c3350101959fac59650259f2d33efcf (patch) | |
tree | 039d6f112d175f729e6fd75db81f5c700546333f /tests/inspectdb | |
parent | 06076999026091cf007d8ea69146340a361259f8 (diff) | |
download | django-ebd270627c3350101959fac59650259f2d33efcf.tar.gz |
Refs #29722 -- Added introspection of partitions for PostgreSQL.
Diffstat (limited to 'tests/inspectdb')
-rw-r--r-- | tests/inspectdb/tests.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 90a8c5f5e2..b578dbf3df 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -335,6 +335,40 @@ class InspectDBTransactionalTests(TransactionTestCase): cursor.execute('DROP MATERIALIZED VIEW IF EXISTS inspectdb_people_materialized_view') @skipUnless(connection.vendor == 'postgresql', 'PostgreSQL specific SQL') + @skipUnlessDBFeature('supports_table_partitions') + def test_include_partitions(self): + """inspectdb --include-partitions creates models for partitions.""" + with connection.cursor() as cursor: + cursor.execute('''\ + CREATE TABLE inspectdb_partition_parent (name text not null) + PARTITION BY LIST (left(upper(name), 1)) + ''') + cursor.execute('''\ + CREATE TABLE inspectdb_partition_child + PARTITION OF inspectdb_partition_parent + FOR VALUES IN ('A', 'B', 'C') + ''') + out = StringIO() + partition_model_parent = 'class InspectdbPartitionParent(models.Model):' + partition_model_child = 'class InspectdbPartitionChild(models.Model):' + partition_managed = 'managed = False # Created from a partition.' + try: + call_command('inspectdb', table_name_filter=inspectdb_tables_only, stdout=out) + no_partitions_output = out.getvalue() + self.assertIn(partition_model_parent, no_partitions_output) + self.assertNotIn(partition_model_child, no_partitions_output) + self.assertNotIn(partition_managed, no_partitions_output) + call_command('inspectdb', table_name_filter=inspectdb_tables_only, include_partitions=True, stdout=out) + with_partitions_output = out.getvalue() + self.assertIn(partition_model_parent, with_partitions_output) + self.assertIn(partition_model_child, with_partitions_output) + self.assertIn(partition_managed, with_partitions_output) + finally: + with connection.cursor() as cursor: + cursor.execute('DROP TABLE IF EXISTS inspectdb_partition_child') + cursor.execute('DROP TABLE IF EXISTS inspectdb_partition_parent') + + @skipUnless(connection.vendor == 'postgresql', 'PostgreSQL specific SQL') def test_foreign_data_wrapper(self): with connection.cursor() as cursor: cursor.execute('CREATE EXTENSION IF NOT EXISTS file_fdw') |