summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-02-24 20:16:49 +0100
committerClaude Paroz <claude@2xlibre.net>2016-02-25 08:43:56 +0100
commit4c18a8a3788a4cd25b75ae342a7244c5f775b213 (patch)
tree29621ddf6d7e60df13eb8fb8fbb841f659c602a0 /tests
parent441c537b66233ae57bf0023f02d8262474229e1a (diff)
Fixed #14098 -- Prevented crash for introspection errors in inspectdb
Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/inspectdb/tests.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
index 06eb2c82f8..6fd1778b55 100644
--- a/tests/inspectdb/tests.py
+++ b/tests/inspectdb/tests.py
@@ -6,7 +6,8 @@ from unittest import skipUnless
from django.core.management import call_command
from django.db import connection
-from django.test import TestCase, skipUnlessDBFeature
+from django.test import TestCase, mock, skipUnlessDBFeature
+from django.utils.encoding import force_text
from django.utils.six import PY3, StringIO
from .models import ColumnTypes
@@ -268,3 +269,17 @@ class InspectDBTestCase(TestCase):
self.assertIn("big_int_field = models.BigIntegerField()", output)
finally:
connection.introspection.data_types_reverse = orig_data_types_reverse
+
+ def test_introspection_errors(self):
+ """
+ Introspection errors should not crash the command, and the error should
+ be visible in the output.
+ """
+ out = StringIO()
+ with mock.patch('django.db.backends.base.introspection.BaseDatabaseIntrospection.table_names',
+ return_value=['nonexistent']):
+ call_command('inspectdb', stdout=out)
+ output = force_text(out.getvalue())
+ self.assertIn("# Unable to inspect table 'nonexistent'", output)
+ # The error message depends on the backend
+ self.assertIn("# The error was:", output)