diff options
author | Nick Pope <nick.pope@flightdataservices.com> | 2018-09-12 01:23:35 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-10-02 14:02:04 -0400 |
commit | bf8b625a3bb6c2cb5f1be3713f3bafe2c1050366 (patch) | |
tree | bc5b93f5358016b15e7dd49ba2cb1f9002dea9d2 /tests/inspectdb | |
parent | 45ef3df7d07489ee0b76479cc799faa92e443a69 (diff) | |
download | django-bf8b625a3bb6c2cb5f1be3713f3bafe2c1050366.tar.gz |
Refs #29722 -- Added introspection of materialized views for PostgreSQL.
Diffstat (limited to 'tests/inspectdb')
-rw-r--r-- | tests/inspectdb/tests.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 83c49eb7e3..849773ef9e 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -311,6 +311,30 @@ class InspectDBTransactionalTests(TransactionTestCase): cursor.execute('DROP VIEW inspectdb_people_view') @skipUnless(connection.vendor == 'postgresql', 'PostgreSQL specific SQL') + def test_include_materialized_views(self): + """inspectdb --include-views creates models for database materialized views.""" + with connection.cursor() as cursor: + cursor.execute( + 'CREATE MATERIALIZED VIEW inspectdb_people_materialized_view AS ' + 'SELECT id, name FROM inspectdb_people' + ) + out = StringIO() + view_model = 'class InspectdbPeopleMaterializedView(models.Model):' + view_managed = 'managed = False # Created from a view.' + try: + call_command('inspectdb', table_name_filter=inspectdb_tables_only, stdout=out) + no_views_output = out.getvalue() + self.assertNotIn(view_model, no_views_output) + self.assertNotIn(view_managed, no_views_output) + call_command('inspectdb', table_name_filter=inspectdb_tables_only, include_views=True, stdout=out) + with_views_output = out.getvalue() + self.assertIn(view_model, with_views_output) + self.assertIn(view_managed, with_views_output) + finally: + with connection.cursor() as cursor: + cursor.execute('DROP MATERIALIZED VIEW IF EXISTS inspectdb_people_materialized_view') + + @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') |