From ed297061a676e629983664031d77da1d0a70af7d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sun, 21 Sep 2014 00:00:52 +0200 Subject: Fixed #18782 -- Prevented sql_flush to flush views Thanks rodolfo_3 for the report and the initial patch, and Josh Smeaton, Shai Berger and Tim Graham for the reviews. --- tests/introspection/tests.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/introspection/tests.py') diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py index 59a9a4e5c5..c8dc5411a6 100644 --- a/tests/introspection/tests.py +++ b/tests/introspection/tests.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from django.db import connection +from django.db.utils import DatabaseError from django.test import TestCase, skipUnlessDBFeature from .models import Reporter, Article @@ -34,6 +35,23 @@ class IntrospectionTests(TestCase): tl = connection.introspection.django_table_names(only_existing=False) self.assertIs(type(tl), list) + def test_table_names_with_views(self): + with connection.cursor() as cursor: + try: + cursor.execute( + 'CREATE VIEW introspection_article_view AS SELECT headline ' + 'from introspection_article;') + except DatabaseError as e: + if 'insufficient privileges' in str(e): + self.skipTest("The test user has no CREATE VIEW privileges") + else: + raise + + self.assertIn('introspection_article_view', + connection.introspection.table_names(include_views=True)) + self.assertNotIn('introspection_article_view', + connection.introspection.table_names()) + def test_installed_models(self): tables = [Article._meta.db_table, Reporter._meta.db_table] models = connection.introspection.installed_models(tables) -- cgit v1.2.1