parent
4daf570b98
commit
c6e6d4eeb7
|
@ -5,7 +5,16 @@ from django.utils.module_loading import import_by_path
|
|||
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
|
||||
|
|
|
@ -8,10 +8,18 @@ from django.test import TransactionTestCase
|
|||
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):
|
||||
"""
|
||||
|
|
|
@ -1474,6 +1474,13 @@ class ArgumentOrder(AdminScriptTestCase):
|
|||
|
||||
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'])
|
||||
|
|
|
@ -345,6 +345,8 @@ class PostgresNewConnectionTest(TestCase):
|
|||
# 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 @@ class BackendTestCase(TestCase):
|
|||
# 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 @@ class MySQLPKZeroTests(TestCase):
|
|||
|
||||
|
||||
class DBConstraintTestCase(TransactionTestCase):
|
||||
|
||||
available_apps = ['backends']
|
||||
|
||||
def test_can_reference_existant(self):
|
||||
obj = models.Object.objects.create()
|
||||
ref = models.ObjectReference.objects.create(obj=obj)
|
||||
|
|
|
@ -686,6 +686,9 @@ class ModelTest(TestCase):
|
|||
|
||||
|
||||
class ConcurrentSaveTests(TransactionTestCase):
|
||||
|
||||
available_apps = ['basic']
|
||||
|
||||
@skipUnlessDBFeature('test_db_allows_multiple_connections')
|
||||
def test_concurrent_delete_with_save(self):
|
||||
"""
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -16,6 +16,9 @@ from .models import (Book, Award, AwardNote, Person, Child, Toy, PlayedWith,
|
|||
# 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 @@ class DeleteCascadeTests(TestCase):
|
|||
|
||||
|
||||
class DeleteCascadeTransactionTests(TransactionTestCase):
|
||||
|
||||
available_apps = ['delete_regress']
|
||||
|
||||
def test_inheritance(self):
|
||||
"""
|
||||
Auto-created many-to-many through tables referencing a parent model are
|
||||
|
|
|
@ -621,6 +621,8 @@ class FileLikeObjectTestCase(LiveServerTestCase):
|
|||
"""
|
||||
Test file-like objects (#15644).
|
||||
"""
|
||||
|
||||
available_apps = []
|
||||
urls = 'file_storage.urls'
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -354,6 +354,13 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
|
|||
|
||||
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
|
||||
|
|
|
@ -26,6 +26,9 @@ class SampleTestCase(TestCase):
|
|||
|
||||
|
||||
class TestNoInitialDataLoading(TransactionTestCase):
|
||||
|
||||
available_apps = ['fixtures_model_package']
|
||||
|
||||
def test_syncdb(self):
|
||||
transaction.set_autocommit(False)
|
||||
try:
|
||||
|
|
|
@ -685,6 +685,12 @@ class NaturalKeyFixtureTests(TestCase):
|
|||
|
||||
class TestTicket11101(TransactionTestCase):
|
||||
|
||||
available_apps = [
|
||||
'fixtures_regress',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
]
|
||||
|
||||
def ticket_11101(self):
|
||||
management.call_command(
|
||||
'loaddata',
|
||||
|
|
|
@ -94,6 +94,8 @@ class GetOrCreateTests(TestCase):
|
|||
|
||||
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,
|
||||
|
|
|
@ -37,6 +37,8 @@ class HandlerTests(TestCase):
|
|||
|
||||
|
||||
class TransactionsPerRequestTests(TransactionTestCase):
|
||||
|
||||
available_apps = []
|
||||
urls = 'handlers.urls'
|
||||
|
||||
def test_no_transaction(self):
|
||||
|
|
|
@ -10,6 +10,7 @@ from .models import (Person, Group, Membership, UserMembership, Car, Driver,
|
|||
|
||||
|
||||
class M2MThroughTestCase(TestCase):
|
||||
|
||||
def test_everything(self):
|
||||
bob = Person.objects.create(name="Bob")
|
||||
jim = Person.objects.create(name="Jim")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 @@ class ProxyModelInheritanceTests(TransactionTestCase):
|
|||
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()
|
||||
from .app1.models import ProxyModel
|
||||
from .app2.models import NiceModel
|
||||
self.assertEqual(NiceModel.objects.all().count(), 0)
|
||||
|
|
|
@ -683,6 +683,8 @@ class RequestsTests(SimpleTestCase):
|
|||
"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']
|
||||
|
|
|
@ -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", ""),
|
||||
|
|
|
@ -23,6 +23,8 @@ requires_threading = unittest.skipUnless(threading, 'requires threading')
|
|||
|
||||
class SelectForUpdateTests(TransactionTestCase):
|
||||
|
||||
available_apps = ['select_for_update']
|
||||
|
||||
def setUp(self):
|
||||
transaction.enter_transaction_management()
|
||||
self.person = Person.objects.create(name='Reinhardt')
|
||||
|
|
|
@ -259,6 +259,9 @@ class SerializersTestBase(object):
|
|||
|
||||
|
||||
class SerializersTransactionTestBase(object):
|
||||
|
||||
available_apps = ['serializers']
|
||||
|
||||
def test_forward_refs(self):
|
||||
"""
|
||||
Tests that objects ids can be referenced before they are
|
||||
|
|
|
@ -30,8 +30,15 @@ TEST_SETTINGS = {
|
|||
|
||||
|
||||
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):
|
||||
|
|
|
@ -12,6 +12,8 @@ from django.utils import unittest, six
|
|||
@override_settings(TEST='override')
|
||||
class FullyDecoratedTranTestCase(TransactionTestCase):
|
||||
|
||||
available_apps = []
|
||||
|
||||
def test_override(self):
|
||||
self.assertEqual(settings.TEST, 'override')
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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 @@ class AtomicInsideLegacyTransactionManagementTests(AtomicTests):
|
|||
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 @@ class AtomicMergeTests(TransactionTestCase):
|
|||
"'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 @@ class AtomicErrorsTests(TransactionTestCase):
|
|||
|
||||
class AtomicMiscTests(TransactionTestCase):
|
||||
|
||||
available_apps = []
|
||||
|
||||
def test_wrap_callable_instance(self):
|
||||
# Regression test for #20028
|
||||
class Callable(object):
|
||||
|
@ -322,6 +330,8 @@ class AtomicMiscTests(TransactionTestCase):
|
|||
|
||||
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 @@ class TransactionTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCas
|
|||
|
||||
|
||||
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 @@ class TransactionRollbackTests(IgnorePendingDeprecationWarningsMixin, Transactio
|
|||
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
|
||||
|
|
|
@ -10,6 +10,9 @@ from django.utils.unittest import skipIf, skipUnless
|
|||
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 @@ class TestPostgresAutocommitAndIsolation(IgnorePendingDeprecationWarningsMixin,
|
|||
|
||||
|
||||
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 @@ class TestManyToManyAddTransaction(IgnorePendingDeprecationWarningsMixin, Transa
|
|||
|
||||
class SavepointTest(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
|
||||
|
||||
available_apps = ['transactions_regress']
|
||||
|
||||
@skipIf(connection.vendor == 'sqlite',
|
||||
"SQLite doesn't support savepoints in managed mode")
|
||||
@skipUnlessDBFeature('uses_savepoints')
|
||||
|
|
|
@ -183,6 +183,8 @@ skip_selenium = not os.environ.get('DJANGO_SELENIUM_TESTS', False)
|
|||
@unittest.skipIf(skip_selenium, 'Selenium tests not requested')
|
||||
@unittest.skipUnless(firefox, 'Selenium not installed')
|
||||
class JavascriptI18nTests(LiveServerTestCase):
|
||||
|
||||
available_apps = []
|
||||
urls = 'view_tests.urls'
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in New Issue