Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Defined available_apps in relevant tests.

Fixed #20483.
  • Loading branch information...
commit c6e6d4eeb776c473567362405cdbc6a0328eb194 1 parent 4daf570
@aaugustin aaugustin authored
View
9 django/contrib/admin/tests.py
@@ -5,7 +5,16 @@
from django.utils.unittest import SkipTest
from django.utils.translation import ugettext as _
+
class AdminSeleniumWebDriverTestCase(LiveServerTestCase):
+
+ available_apps = [
+ 'django.contrib.admin',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ ]
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
@classmethod
View
8 django/contrib/auth/tests/test_handlers.py
@@ -8,10 +8,18 @@
from django.test.utils import override_settings
+# This must be a TransactionTestCase because the WSGI auth handler performs
+# its own transaction management.
class ModWsgiHandlerTestCase(TransactionTestCase):
"""
Tests for the mod_wsgi authentication handler
"""
+
+ available_apps = [
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ ]
+
@skipIfCustomUser
def test_check_password(self):
"""
View
7 tests/admin_scripts/tests.py
@@ -1474,6 +1474,13 @@ def test_option_then_setting_then_option(self):
class StartProject(LiveServerTestCase, AdminScriptTestCase):
+ available_apps = [
+ 'admin_scripts',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ ]
+
def test_wrong_args(self):
"Make sure passing the wrong kinds of arguments raises a CommandError"
out, err = self.run_django_admin(['startproject'])
View
7 tests/backends/tests.py
@@ -345,6 +345,8 @@ def test_connect_and_rollback(self):
# connection would implicitly rollback and cause problems during teardown.
class ConnectionCreatedSignalTest(TransactionTestCase):
+ available_apps = []
+
# Unfortunately with sqlite3 the in-memory test database cannot be closed,
# and so it cannot be re-opened during testing.
@skipUnlessDBFeature('test_db_allows_multiple_connections')
@@ -514,6 +516,8 @@ def test_duplicate_table_error(self):
# verify if its type is django.database.db.IntegrityError.
class FkConstraintsTests(TransactionTestCase):
+ available_apps = ['backends']
+
def setUp(self):
# Create a Reporter.
self.r = models.Reporter.objects.create(first_name='John', last_name='Smith')
@@ -777,6 +781,9 @@ def test_zero_as_autoval(self):
class DBConstraintTestCase(TransactionTestCase):
+
+ available_apps = ['backends']
+
def test_can_reference_existant(self):
obj = models.Object.objects.create()
ref = models.ObjectReference.objects.create(obj=obj)
View
3  tests/basic/tests.py
@@ -686,6 +686,9 @@ def test_ticket_20278(self):
class ConcurrentSaveTests(TransactionTestCase):
+
+ available_apps = ['basic']
+
@skipUnlessDBFeature('test_db_allows_multiple_connections')
def test_concurrent_delete_with_save(self):
"""
View
2  tests/cache/tests.py
@@ -827,6 +827,8 @@ def custom_key_func(key, key_prefix, version):
class DBCacheTests(BaseCacheTests, TransactionTestCase):
+
+ available_apps = []
backend_name = 'django.core.cache.backends.db.DatabaseCache'
def setUp(self):
View
6 tests/delete_regress/tests.py
@@ -16,6 +16,9 @@
# Can't run this test under SQLite, because you can't
# get two connections to an in-memory database.
class DeleteLockingTest(TransactionTestCase):
+
+ available_apps = ['delete_regress']
+
def setUp(self):
# Create a second connection to the default database
new_connections = ConnectionHandler(settings.DATABASES)
@@ -107,6 +110,9 @@ def test_15776(self):
class DeleteCascadeTransactionTests(TransactionTestCase):
+
+ available_apps = ['delete_regress']
+
def test_inheritance(self):
"""
Auto-created many-to-many through tables referencing a parent model are
View
2  tests/file_storage/tests.py
@@ -621,6 +621,8 @@ class FileLikeObjectTestCase(LiveServerTestCase):
"""
Test file-like objects (#15644).
"""
+
+ available_apps = []
urls = 'file_storage.urls'
def setUp(self):
View
7 tests/fixtures/tests.py
@@ -354,6 +354,13 @@ def test_output_formats(self):
class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase):
+ available_apps = [
+ 'fixtures',
+ 'django.contrib.contenttypes',
+ 'django.contrib.auth',
+ 'django.contrib.sites',
+ ]
+
@skipUnlessDBFeature('supports_forward_references')
def test_format_discovery(self):
# Load fixture 1 again, using format discovery
View
3  tests/fixtures_model_package/tests.py
@@ -26,6 +26,9 @@ def testClassFixtures(self):
class TestNoInitialDataLoading(TransactionTestCase):
+
+ available_apps = ['fixtures_model_package']
+
def test_syncdb(self):
transaction.set_autocommit(False)
try:
View
6 tests/fixtures_regress/tests.py
@@ -685,6 +685,12 @@ def test_normal_pk(self):
class TestTicket11101(TransactionTestCase):
+ available_apps = [
+ 'fixtures_regress',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ ]
+
def ticket_11101(self):
management.call_command(
'loaddata',
View
2  tests/get_or_create/tests.py
@@ -94,6 +94,8 @@ def test_get_or_create_empty(self):
class GetOrCreateTransactionTests(TransactionTestCase):
+ available_apps = ['get_or_create']
+
def test_get_or_create_integrityerror(self):
# Regression test for #15117. Requires a TransactionTestCase on
# databases that delay integrity checks until the end of transactions,
View
2  tests/handlers/tests.py
@@ -37,6 +37,8 @@ def test_bad_path_info(self):
class TransactionsPerRequestTests(TransactionTestCase):
+
+ available_apps = []
urls = 'handlers.urls'
def test_no_transaction(self):
View
1  tests/m2m_through_regress/tests.py
@@ -10,6 +10,7 @@
class M2MThroughTestCase(TestCase):
+
def test_everything(self):
bob = Person.objects.create(name="Bob")
jim = Person.objects.create(name="Jim")
View
3  tests/middleware/tests.py
@@ -707,6 +707,9 @@ class TransactionMiddlewareTest(IgnorePendingDeprecationWarningsMixin, Transacti
"""
Test the transaction middleware.
"""
+
+ available_apps = ['middleware']
+
def setUp(self):
super(TransactionMiddlewareTest, self).setUp()
self.request = HttpRequest()
View
8 tests/proxy_model_inheritance/tests.py
@@ -22,6 +22,8 @@ class ProxyModelInheritanceTests(TransactionTestCase):
apps and calls syncdb, then verifies that the table has been created.
"""
+ available_apps = []
+
def setUp(self):
self.old_sys_path = sys.path[:]
sys.path.append(os.path.dirname(os.path.abspath(upath(__file__))))
@@ -38,7 +40,11 @@ def tearDown(self):
del cache.app_models['app2']
def test_table_exists(self):
- call_command('syncdb', verbosity=0)
+ try:
+ cache.set_available_apps(settings.INSTALLED_APPS)
+ call_command('syncdb', verbosity=0)
+ finally:
+ cache.unset_available_apps()
from .app1.models import ProxyModel
from .app2.models import NiceModel
self.assertEqual(NiceModel.objects.all().count(), 0)
View
2  tests/requests/tests.py
@@ -683,6 +683,8 @@ def read(self, len=0):
"Cannot establish two connections to an in-memory SQLite database.")
class DatabaseConnectionHandlingTests(TransactionTestCase):
+ available_apps = []
+
def setUp(self):
# Use a temporary connection to avoid messing with the main one.
self._old_default_connection = connections['default']
View
9 tests/runtests.py
@@ -72,6 +72,15 @@ def get_installed():
def setup(verbosity, test_labels):
from django.conf import settings
from django.db.models.loading import get_apps, load_app
+ from django.test.testcases import TransactionTestCase, TestCase
+
+ # Force declaring available_apps in TransactionTestCase for faster tests.
+ def no_available_apps(self):
+ raise Exception("Please define available_apps in TransactionTestCase "
+ "and its subclasses.")
+ TransactionTestCase.available_apps = property(no_available_apps)
+ TestCase.available_apps = None
+
state = {
'INSTALLED_APPS': settings.INSTALLED_APPS,
'ROOT_URLCONF': getattr(settings, "ROOT_URLCONF", ""),
View
2  tests/select_for_update/tests.py
@@ -23,6 +23,8 @@
class SelectForUpdateTests(TransactionTestCase):
+ available_apps = ['select_for_update']
+
def setUp(self):
transaction.enter_transaction_management()
self.person = Person.objects.create(name='Reinhardt')
View
3  tests/serializers/tests.py
@@ -259,6 +259,9 @@ def test_pkless_serialized_strings(self):
class SerializersTransactionTestBase(object):
+
+ available_apps = ['serializers']
+
def test_forward_refs(self):
"""
Tests that objects ids can be referenced before they are
View
9 tests/servers/tests.py
@@ -30,8 +30,15 @@
class LiveServerBase(LiveServerTestCase):
- urls = 'servers.urls'
+
+ available_apps = [
+ 'servers',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ ]
fixtures = ['testdata.json']
+ urls = 'servers.urls'
@classmethod
def setUpClass(cls):
View
2  tests/settings_tests/tests.py
@@ -12,6 +12,8 @@
@override_settings(TEST='override')
class FullyDecoratedTranTestCase(TransactionTestCase):
+ available_apps = []
+
def test_override(self):
self.assertEqual(settings.TEST, 'override')
View
2  tests/test_runner/tests.py
@@ -318,6 +318,8 @@ class AutoIncrementResetTest(TransactionTestCase):
that AutoField values start from 1 for each transactional test case.
"""
+ available_apps = ['test_runner']
+
reset_sequences = True
@skipUnlessDBFeature('supports_sequence_reset')
View
16 tests/transactions/tests.py
@@ -26,6 +26,8 @@ class AtomicTests(TransactionTestCase):
syntax and the bulk of the tests use the context manager syntax.
"""
+ available_apps = ['transactions']
+
def test_decorator_syntax_commit(self):
@transaction.atomic
def make_reporter():
@@ -232,6 +234,8 @@ def tearDown(self):
class AtomicMergeTests(TransactionTestCase):
"""Test merging transactions with savepoint=False."""
+ available_apps = ['transactions']
+
def test_merged_outer_rollback(self):
with transaction.atomic():
Reporter.objects.create(first_name="Tintin")
@@ -286,6 +290,8 @@ def test_merged_outer_rollback_after_inner_failure_and_inner_success(self):
"'atomic' requires transactions and savepoints.")
class AtomicErrorsTests(TransactionTestCase):
+ available_apps = []
+
def test_atomic_prevents_setting_autocommit(self):
autocommit = transaction.get_autocommit()
with transaction.atomic():
@@ -311,6 +317,8 @@ def test_atomic_prevents_calling_transaction_management_methods(self):
class AtomicMiscTests(TransactionTestCase):
+ available_apps = []
+
def test_wrap_callable_instance(self):
# Regression test for #20028
class Callable(object):
@@ -322,6 +330,8 @@ def __call__(self):
class TransactionTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+ available_apps = ['transactions']
+
def create_a_reporter_then_fail(self, first, last):
a = Reporter(first_name=first, last_name=last)
a.save()
@@ -477,6 +487,9 @@ def test_manually_managed_with_using(self):
class TransactionRollbackTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+
+ available_apps = ['transactions']
+
def execute_bad_sql(self):
cursor = connection.cursor()
cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
@@ -494,6 +507,9 @@ def test_bad_sql(self):
transaction.rollback()
class TransactionContextManagerTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+
+ available_apps = ['transactions']
+
def create_reporter_and_fail(self):
Reporter.objects.create(first_name="Bob", last_name="Holtzman")
raise Exception
View
21 tests/transactions_regress/tests.py
@@ -10,6 +10,9 @@
from .models import Mod, M2mA, M2mB, SubMod
class ModelInheritanceTests(TransactionTestCase):
+
+ available_apps = ['transactions_regress']
+
def test_save(self):
# First, create a SubMod, then try to save another with conflicting
# cnt field. The problem was that transactions were committed after
@@ -33,6 +36,13 @@ class TestTransactionClosing(IgnorePendingDeprecationWarningsMixin, TransactionT
when they should be, and aren't left pending after operations
have been performed in them. Refs #9964.
"""
+
+ available_apps = [
+ 'transactions_regress',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ ]
+
def test_raw_committed_on_success(self):
"""
Make sure a transaction consisting of raw SQL execution gets
@@ -188,6 +198,9 @@ class TestNewConnection(IgnorePendingDeprecationWarningsMixin, TransactionTestCa
"""
Check that new connections don't have special behaviour.
"""
+
+ available_apps = ['transactions_regress']
+
def setUp(self):
self._old_backend = connections[DEFAULT_DB_ALIAS]
settings = self._old_backend.settings_dict.copy()
@@ -235,6 +248,9 @@ class TestPostgresAutocommitAndIsolation(IgnorePendingDeprecationWarningsMixin,
is restored after entering and leaving transaction management.
Refs #16047, #18130.
"""
+
+ available_apps = ['transactions_regress']
+
def setUp(self):
from psycopg2.extensions import (ISOLATION_LEVEL_AUTOCOMMIT,
ISOLATION_LEVEL_SERIALIZABLE,
@@ -311,6 +327,9 @@ def test_enter_autocommit(self):
class TestManyToManyAddTransaction(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+
+ available_apps = ['transactions_regress']
+
def test_manyrelated_add_commit(self):
"Test for https://code.djangoproject.com/ticket/16818"
a = M2mA.objects.create()
@@ -327,6 +346,8 @@ def test_manyrelated_add_commit(self):
class SavepointTest(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
+ available_apps = ['transactions_regress']
+
@skipIf(connection.vendor == 'sqlite',
"SQLite doesn't support savepoints in managed mode")
@skipUnlessDBFeature('uses_savepoints')
View
2  tests/view_tests/tests/test_i18n.py
@@ -183,6 +183,8 @@ def testI18NWithLocalePaths(self):
@unittest.skipIf(skip_selenium, 'Selenium tests not requested')
@unittest.skipUnless(firefox, 'Selenium not installed')
class JavascriptI18nTests(LiveServerTestCase):
+
+ available_apps = []
urls = 'view_tests.urls'
@classmethod
Please sign in to comment.
Something went wrong with that request. Please try again.