Skip to content

Commit

Permalink
Used available_apps for some plain TestCases
Browse files Browse the repository at this point in the history
Some tests test explicitly syncdb which results in nonnecessary
permission and contenttype creation.
  • Loading branch information
akaariai committed Jun 10, 2013
1 parent 02bdd9a commit b101db2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
10 changes: 10 additions & 0 deletions tests/fixtures_regress/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@


class TestFixtures(TestCase):
available_apps = [
'fixtures_regress',
'django.contrib.auth',
'django.contrib.contenttypes',
]

def animal_pre_save_check(self, signal, sender, instance, **kwargs):
self.pre_save_checks.append(
Expand Down Expand Up @@ -455,6 +460,11 @@ def test_loaddata_not_existant_fixture_file(self):


class NaturalKeyFixtureTests(TestCase):
available_apps = [
'fixtures_regress',
'django.contrib.auth',
'django.contrib.contenttypes',
]

def test_nk_deserialize(self):
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/multiple_database/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,9 @@ def test_router_init_arg(self):

class RouterTestCase(TestCase):
multi_db = True
available_apps = [
'multiple_database'
]

def setUp(self):
# Make the 'other' database appear to be a slave of the 'default'
Expand Down Expand Up @@ -1944,6 +1947,8 @@ def allow_syncdb(self, db, model):

class SyncDBTestCase(TestCase):
multi_db = True
available_apps = ['multiple_database', 'django.contrib.contenttypes',
'django.contrib.auth']

def test_syncdb_to_other_database(self):
"""Regression test for #16039: syncdb with --database option."""
Expand Down
11 changes: 4 additions & 7 deletions tests/proxy_model_inheritance/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
ConcreteModelSubclassProxy)


@override_settings(INSTALLED_APPS=('app1', 'app2'))
@override_settings(INSTALLED_APPS=('app1', 'app2', 'proxy_model_inheritance'))
class ProxyModelInheritanceTests(TransactionTestCase):
"""
Proxy model inheritance across apps can result in syncdb not creating the table
for the proxied model (as described in #12286). This test creates two dummy
apps and calls syncdb, then verifies that the table has been created.
"""

available_apps = []
available_apps = ['app1', 'app2', 'proxy_model_inheritance']

def setUp(self):
self.old_sys_path = sys.path[:]
Expand All @@ -40,11 +40,8 @@ def tearDown(self):
del cache.app_models['app2']

def test_table_exists(self):
try:
cache.set_available_apps(settings.INSTALLED_APPS)
call_command('syncdb', verbosity=0)
finally:
cache.unset_available_apps()
cache.set_available_apps(settings.INSTALLED_APPS)
call_command('syncdb', verbosity=0)
from .app1.models import ProxyModel
from .app2.models import NiceModel
self.assertEqual(NiceModel.objects.all().count(), 0)
Expand Down
3 changes: 3 additions & 0 deletions tests/swappable_models/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@


class SwappableModelTests(TestCase):
available_apps = ['swappable_models', 'django.contrib.auth',
'django.contrib.contenttypes']

def setUp(self):
# This test modifies the installed apps, so we need to make sure
# we're not dealing with a cached app list.
Expand Down
2 changes: 2 additions & 0 deletions tests/syncdb_signals/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def __call__(self, signal, sender, **kwargs):


class SyncdbSignalTests(TestCase):
available_apps = ['syncdb_signals', 'shared_models']

def test_pre_syncdb_call_time(self):
self.assertEqual(pre_syncdb_receiver.call_counter, 1)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_runner/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django import db
from django.test import runner, TransactionTestCase, skipUnlessDBFeature
from django.test import runner, TransactionTestCase, skipUnlessDBFeature, TestCase as DjangoTestCase
from django.test.simple import DjangoTestSuiteRunner, get_tests
from django.test.testcases import connections_support_transactions
from django.utils import unittest
Expand Down Expand Up @@ -238,7 +238,8 @@ def test_import_error(self):
self.assertRaises(ImportError, get_tests, module)


class Sqlite3InMemoryTestDbs(unittest.TestCase):
class Sqlite3InMemoryTestDbs(DjangoTestCase):
available_apps = ['test_runner']

@unittest.skipUnless(all(db.connections[conn].vendor == 'sqlite' for conn in db.connections),
"This is a sqlite-specific issue")
Expand Down

0 comments on commit b101db2

Please sign in to comment.