diff options
| author | Thomas Chaumeny <t.chaumeny@gmail.com> | 2014-10-18 23:01:13 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-12-03 10:37:04 -0500 |
| commit | da9fe5c717c179a9e881a40efd3bfe36a21bf4a6 (patch) | |
| tree | bdf38ea36841d93fa9260daf5b8d705b377dbd40 /tests | |
| parent | dee4d23f7e703aec2d1244e4facbf7f4c88deed5 (diff) | |
Fixed #20392 -- Added TestCase.setUpTestData()
Each TestCase is also now wrapped in a class-wide transaction.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/tests.py | 19 | ||||
| -rw-r--r-- | tests/fixtures_migration/tests.py | 4 | ||||
| -rw-r--r-- | tests/introspection/tests.py | 7 | ||||
| -rw-r--r-- | tests/model_inheritance/tests.py | 21 |
4 files changed, 32 insertions, 19 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index d47ca43d1c..db79cd0325 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -345,13 +345,14 @@ class ParameterHandlingTest(TestCase): # Unfortunately, the following tests would be a good test to run on all # backends, but it breaks MySQL hard. Until #13711 is fixed, it can't be run # everywhere (although it would be an effective test of #13711). -class LongNameTest(TestCase): +class LongNameTest(TransactionTestCase): """Long primary keys and model names can result in a sequence name that exceeds the database limits, which will result in truncation on certain databases (e.g., Postgres). The backend needs to use the correct sequence name in last_insert_id and other places, so check it is. Refs #8901. """ + available_apps = ['backends'] def test_sequence_name_length_limits_create(self): """Test creation of model with long name and long pk name doesn't error. Ref #8901""" @@ -465,7 +466,9 @@ class EscapingChecksDebug(EscapingChecks): pass -class BackendTestCase(TestCase): +class BackendTestCase(TransactionTestCase): + + available_apps = ['backends'] def create_squares_with_executemany(self, args): self.create_squares(args, 'format', True) @@ -653,9 +656,8 @@ class BackendTestCase(TestCase): """ Test the documented API of connection.queries. """ - reset_queries() - with connection.cursor() as cursor: + reset_queries() cursor.execute("SELECT 1" + connection.features.bare_select_suffix) self.assertEqual(1, len(connection.queries)) @@ -823,7 +825,9 @@ class FkConstraintsTests(TransactionTestCase): transaction.set_rollback(True) -class ThreadTests(TestCase): +class ThreadTests(TransactionTestCase): + + available_apps = ['backends'] def test_default_connection_thread_local(self): """ @@ -987,9 +991,7 @@ class MySQLPKZeroTests(TestCase): models.Square.objects.create(id=0, root=0, square=1) -class DBConstraintTestCase(TransactionTestCase): - - available_apps = ['backends'] +class DBConstraintTestCase(TestCase): def test_can_reference_existent(self): obj = models.Object.objects.create() @@ -1066,6 +1068,7 @@ class DBTestSettingsRenamedTests(IgnoreAllDeprecationWarningsMixin, TestCase): @classmethod def setUpClass(cls): + super(DBTestSettingsRenamedTests, cls).setUpClass() # Silence "UserWarning: Overriding setting DATABASES can lead to # unexpected behavior." cls.warning_classes.append(UserWarning) diff --git a/tests/fixtures_migration/tests.py b/tests/fixtures_migration/tests.py index 9a363385e6..1dcc443c85 100644 --- a/tests/fixtures_migration/tests.py +++ b/tests/fixtures_migration/tests.py @@ -1,10 +1,10 @@ -from django.test import TestCase +from django.test import TransactionTestCase from django.core import management from .models import Book -class TestNoInitialDataLoading(TestCase): +class TestNoInitialDataLoading(TransactionTestCase): """ Apps with migrations should ignore initial data. This test can be removed in Django 1.9 when migrations become required and initial data is no longer diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py index d63358dafd..bd5024a556 100644 --- a/tests/introspection/tests.py +++ b/tests/introspection/tests.py @@ -2,12 +2,15 @@ from __future__ import unicode_literals from django.db import connection from django.db.utils import DatabaseError -from django.test import TestCase, skipUnlessDBFeature +from django.test import TransactionTestCase, skipUnlessDBFeature from .models import Reporter, Article -class IntrospectionTests(TestCase): +class IntrospectionTests(TransactionTestCase): + + available_apps = ['introspection'] + def test_table_names(self): tl = connection.introspection.table_names() self.assertEqual(tl, sorted(tl)) diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py index 19d7b5650f..bf76286391 100644 --- a/tests/model_inheritance/tests.py +++ b/tests/model_inheritance/tests.py @@ -5,7 +5,7 @@ from operator import attrgetter from django.core.exceptions import FieldError from django.core.management import call_command from django.db import connection -from django.test import TestCase +from django.test import TestCase, TransactionTestCase from django.test.utils import CaptureQueriesContext from django.utils import six @@ -379,7 +379,9 @@ class ModelInheritanceTests(TestCase): s.titles.all(), []) -class InheritanceSameModelNameTests(TestCase): +class InheritanceSameModelNameTests(TransactionTestCase): + + available_apps = ['model_inheritance'] def setUp(self): # The Title model has distinct accessors for both @@ -402,14 +404,19 @@ class InheritanceSameModelNameTests(TestCase): INSTALLED_APPS={'append': ['model_inheritance.same_model_name']}): call_command('migrate', verbosity=0) from .same_model_name.models import Copy + copy = self.title.attached_same_model_name_copy_set.create( + content='The Web framework for perfectionists with deadlines.', + url='http://www.djangoproject.com/', + title='Django Rocks' + ) self.assertEqual( - self.title.attached_same_model_name_copy_set.create( - content='The Web framework for perfectionists with deadlines.', - url='http://www.djangoproject.com/', - title='Django Rocks' - ), Copy.objects.get( + copy, + Copy.objects.get( content='The Web framework for perfectionists with deadlines.', )) + # We delete the copy manually so that it doesn't block the flush + # command under Oracle (which does not cascade deletions). + copy.delete() def test_related_name_attribute_exists(self): # The Post model doesn't have an attribute called 'attached_%(app_label)s_%(class)s_set'. |
