summaryrefslogtreecommitdiff
path: root/tests/inspectdb
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-03-12 10:02:10 -0400
committerTim Graham <timograham@gmail.com>2018-03-12 11:15:13 -0400
commit25b97ee1702e8950de9b9cc6fc551485b385cf0f (patch)
tree074e0fe48b868c29e88402c269dff8843c6746f4 /tests/inspectdb
parente1cf2a607ef7e1cd8bc3612c93e4e7a9aa9589cc (diff)
Added functions for inspectdb table filtering in tests.
Diffstat (limited to 'tests/inspectdb')
-rw-r--r--tests/inspectdb/tests.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
index ed55e31353..7ffdaf71f2 100644
--- a/tests/inspectdb/tests.py
+++ b/tests/inspectdb/tests.py
@@ -10,15 +10,23 @@ from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
from .models import ColumnTypes
+def inspectdb_tables_only(table_name):
+ """
+ Limit introspection to tables created for models of this app.
+ Some databases such as Oracle are extremely slow at introspection.
+ """
+ return table_name.startswith('inspectdb_')
+
+
+def special_table_only(table_name):
+ return table_name.startswith('inspectdb_special')
+
+
class InspectDBTestCase(TestCase):
def test_stealth_table_name_filter_option(self):
out = StringIO()
- # Lets limit the introspection to tables created for models of this
- # application
- call_command('inspectdb',
- table_name_filter=lambda tn: tn.startswith('inspectdb_'),
- stdout=out)
+ call_command('inspectdb', table_name_filter=inspectdb_tables_only, stdout=out)
error_message = "inspectdb has examined a table that should have been filtered out."
# contrib.contenttypes is one of the apps always installed when running
# the Django test suite, check that one of its tables hasn't been
@@ -136,11 +144,7 @@ class InspectDBTestCase(TestCase):
@skipUnlessDBFeature('can_introspect_foreign_keys')
def test_attribute_name_not_python_keyword(self):
out = StringIO()
- # Lets limit the introspection to tables created for models of this
- # application
- call_command('inspectdb',
- table_name_filter=lambda tn: tn.startswith('inspectdb_'),
- stdout=out)
+ call_command('inspectdb', table_name_filter=inspectdb_tables_only, stdout=out)
output = out.getvalue()
error_message = "inspectdb generated an attribute name which is a python keyword"
# Recursive foreign keys should be set to 'self'
@@ -186,9 +190,7 @@ class InspectDBTestCase(TestCase):
unsuitable for Python identifiers
"""
out = StringIO()
- call_command('inspectdb',
- table_name_filter=lambda tn: tn.startswith('inspectdb_special'),
- stdout=out)
+ call_command('inspectdb', table_name_filter=special_table_only, stdout=out)
output = out.getvalue()
base_name = 'field' if connection.features.uppercases_column_names else 'Field'
self.assertIn("field = models.IntegerField()", output)
@@ -204,9 +206,7 @@ class InspectDBTestCase(TestCase):
unsuitable for Python identifiers
"""
out = StringIO()
- call_command('inspectdb',
- table_name_filter=lambda tn: tn.startswith('inspectdb_special'),
- stdout=out)
+ call_command('inspectdb', table_name_filter=special_table_only, stdout=out)
output = out.getvalue()
self.assertIn("class InspectdbSpecialTableName(models.Model):", output)