Optimized inspectdb tests by specifying database tables/views.

This commit is contained in:
Nick Pope 2020-07-29 12:59:29 +01:00 committed by Mariusz Felisiak
parent 1fb97fb965
commit be183fc94f
1 changed files with 34 additions and 5 deletions

View File

@ -19,6 +19,13 @@ def inspectdb_tables_only(table_name):
return table_name.startswith('inspectdb_') return table_name.startswith('inspectdb_')
def inspectdb_views_only(table_name):
return (
table_name.startswith('inspectdb_') and
table_name.endswith(('_materialized', '_view'))
)
def special_table_only(table_name): def special_table_only(table_name):
return table_name.startswith('inspectdb_special') return table_name.startswith('inspectdb_special')
@ -337,11 +344,20 @@ class InspectDBTransactionalTests(TransactionTestCase):
view_model = 'class InspectdbPeopleView(models.Model):' view_model = 'class InspectdbPeopleView(models.Model):'
view_managed = 'managed = False # Created from a view.' view_managed = 'managed = False # Created from a view.'
try: try:
call_command('inspectdb', table_name_filter=inspectdb_tables_only, stdout=out) call_command(
'inspectdb',
table_name_filter=inspectdb_views_only,
stdout=out,
)
no_views_output = out.getvalue() no_views_output = out.getvalue()
self.assertNotIn(view_model, no_views_output) self.assertNotIn(view_model, no_views_output)
self.assertNotIn(view_managed, no_views_output) self.assertNotIn(view_managed, no_views_output)
call_command('inspectdb', table_name_filter=inspectdb_tables_only, include_views=True, stdout=out) call_command(
'inspectdb',
table_name_filter=inspectdb_views_only,
include_views=True,
stdout=out,
)
with_views_output = out.getvalue() with_views_output = out.getvalue()
self.assertIn(view_model, with_views_output) self.assertIn(view_model, with_views_output)
self.assertIn(view_managed, with_views_output) self.assertIn(view_managed, with_views_output)
@ -361,11 +377,20 @@ class InspectDBTransactionalTests(TransactionTestCase):
view_model = 'class InspectdbPeopleMaterialized(models.Model):' view_model = 'class InspectdbPeopleMaterialized(models.Model):'
view_managed = 'managed = False # Created from a view.' view_managed = 'managed = False # Created from a view.'
try: try:
call_command('inspectdb', table_name_filter=inspectdb_tables_only, stdout=out) call_command(
'inspectdb',
table_name_filter=inspectdb_views_only,
stdout=out,
)
no_views_output = out.getvalue() no_views_output = out.getvalue()
self.assertNotIn(view_model, no_views_output) self.assertNotIn(view_model, no_views_output)
self.assertNotIn(view_managed, no_views_output) self.assertNotIn(view_managed, no_views_output)
call_command('inspectdb', table_name_filter=inspectdb_tables_only, include_views=True, stdout=out) call_command(
'inspectdb',
table_name_filter=inspectdb_views_only,
include_views=True,
stdout=out,
)
with_views_output = out.getvalue() with_views_output = out.getvalue()
self.assertIn(view_model, with_views_output) self.assertIn(view_model, with_views_output)
self.assertIn(view_managed, with_views_output) self.assertIn(view_managed, with_views_output)
@ -426,7 +451,11 @@ class InspectDBTransactionalTests(TransactionTestCase):
foreign_table_model = 'class InspectdbIrisForeignTable(models.Model):' foreign_table_model = 'class InspectdbIrisForeignTable(models.Model):'
foreign_table_managed = 'managed = False' foreign_table_managed = 'managed = False'
try: try:
call_command('inspectdb', stdout=out) call_command(
'inspectdb',
table_name_filter=inspectdb_tables_only,
stdout=out,
)
output = out.getvalue() output = out.getvalue()
self.assertIn(foreign_table_model, output) self.assertIn(foreign_table_model, output)
self.assertIn(foreign_table_managed, output) self.assertIn(foreign_table_managed, output)