diff options
| author | Tim Graham <timograham@gmail.com> | 2018-12-05 15:21:09 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-12-05 15:30:23 -0500 |
| commit | 4c7c608a1deee37055d4a2b8a71e34def04a2a1f (patch) | |
| tree | f1bd8c1300f3ece897fd22b6820987460f014f84 /tests | |
| parent | 734ce71824180740f2318750ae2436f4b60c30b1 (diff) | |
Reverted "Fixed #25251 -- Made data migrations available in TransactionTestCase when using --keepdb."
This reverts commits b3b1d3d45fc066367f4fcacf0b06f72fcd00a9c6 and
9fa0d3786febf36c87ef059a39115aa1ce3326e8 due to reverse build failures
for which a solution isn't forthcoming.
Diffstat (limited to 'tests')
5 files changed, 1 insertions, 178 deletions
diff --git a/tests/test_discovery_sample3/__init__.py b/tests/test_discovery_sample3/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/test_discovery_sample3/__init__.py +++ /dev/null diff --git a/tests/test_discovery_sample3/tests_transaction_test_case_mixed.py b/tests/test_discovery_sample3/tests_transaction_test_case_mixed.py deleted file mode 100644 index 13059bbb87..0000000000 --- a/tests/test_discovery_sample3/tests_transaction_test_case_mixed.py +++ /dev/null @@ -1,50 +0,0 @@ -from unittest import TestCase - -from django.test import ( - TestCase as DjangoTestCase, TransactionTestCase, skipUnlessDBFeature, -) - - -class TestVanillaUnittest(TestCase): - def test_sample(self): - self.assertEqual(1, 1) - - -class TestDjangoTestCase(DjangoTestCase): - def test_sample(self): - self.assertEqual(1, 1) - - -class TestTransactionTestCase1(TransactionTestCase): - available_apps = ['test_discovery_sample3'] - serialized_rollback = False - - def test_sample(self): - self.assertEqual(1, 1) - - -class TestTransactionTestCase2(TransactionTestCase): - available_apps = ['test_discovery_sample3'] - serialized_rollback = True - - def test_sample(self): - self.assertEqual(1, 1) - - -# django.test.runner.reorder_postprocess() ignores this skipped test when -# assigning _next_serialized_rollback. -@skipUnlessDBFeature('nonexistent') -class TestTransactionTestCase3(TransactionTestCase): - available_apps = ['test_discovery_sample3'] - serialized_rollback = True - - def test_sample(self): - self.assertEqual(1, 1) - - -class TestTransactionTestCase4(TransactionTestCase): - available_apps = ['test_discovery_sample3'] - serialized_rollback = False - - def test_sample(self): - self.assertEqual(1, 1) diff --git a/tests/test_discovery_sample3/tests_transaction_test_case_ordering.py b/tests/test_discovery_sample3/tests_transaction_test_case_ordering.py deleted file mode 100644 index 8d79bc08a6..0000000000 --- a/tests/test_discovery_sample3/tests_transaction_test_case_ordering.py +++ /dev/null @@ -1,28 +0,0 @@ -from unittest import TestCase - -from django.test import ( - SimpleTestCase, TestCase as DjangoTestCase, TransactionTestCase, -) - - -class TestDjangoTestCase(DjangoTestCase): - def test_sample(self): - self.assertEqual(1, 1) - - -class TestVanillaUnittest(TestCase): - def test_sample(self): - self.assertEqual(1, 1) - - -class TestZimpleTestCase(SimpleTestCase): - # Z gets this test to appear after Vanilla in the default suite. - def test_sample(self): - self.assertEqual(1, 1) - - -class TestTransactionTestCase(TransactionTestCase): - available_apps = ['test_discovery_sample3'] - - def test_sample(self): - self.assertEqual(1, 1) diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py index efc055978d..d7569fc111 100644 --- a/tests/test_runner/test_discover_runner.py +++ b/tests/test_runner/test_discover_runner.py @@ -223,32 +223,3 @@ class DiscoverRunnerTests(SimpleTestCase): with captured_stdout() as stdout: runner.build_suite(['test_runner_apps.tagged.tests']) self.assertIn('Excluding test tag(s): bar, foo.\n', stdout.getvalue()) - - def test_transaction_test_case_before_simple_test_case(self): - runner = DiscoverRunner() - suite = runner.build_suite(['test_discovery_sample3.tests_transaction_test_case_ordering']) - suite = tuple(suite) - # TransactionTestCase is second after TestCase. - self.assertIn('TestTransactionTestCase', suite[1].id()) - - def test_transaction_test_case_next_serialized_rollback_option(self): - runner = DiscoverRunner() - suite = runner.build_suite(['test_discovery_sample3.tests_transaction_test_case_mixed']) - django_test_case, first_transaction_test_case, second_transaction_test_case, \ - third_transaction_test_case, fourth_transaction_test_case, vanilla_test_case = suite - # TransactionTestCase1._next_serialized_rollback is - # TransactionTestCase2.serialize_rollback. - self.assertEqual( - first_transaction_test_case._next_serialized_rollback, - second_transaction_test_case.serialized_rollback - ) - # TransactionTestCase2._next_serialized_rollback is - # TransactionTestCase4.serialize_rollback because TransactionTestCase3 - # is skipped. - self.assertEqual( - second_transaction_test_case._next_serialized_rollback, - fourth_transaction_test_case.serialized_rollback - ) - # The last TransactionTestCase of the suite has - # _next_serialized_rollback = True. - self.assertIs(fourth_transaction_test_case._next_serialized_rollback, True) diff --git a/tests/test_utils/test_transactiontestcase.py b/tests/test_utils/test_transactiontestcase.py index 193a4e299e..40c9b7576f 100644 --- a/tests/test_utils/test_transactiontestcase.py +++ b/tests/test_utils/test_transactiontestcase.py @@ -1,44 +1,10 @@ -import json from unittest import mock -from django.apps import apps from django.db import connections from django.test import TestCase, TransactionTestCase, override_settings -from .models import Car - -class TestSerializedContentMockMixin: - """ - Use this mixin on each test involving TransactionTestCase and - serialized_rollback = True option to avoid test dependencies. It mocks what - would be serialized after initial data migrations and restores it at the - end of the test. - """ - initial_data_migration = '[]' - _connections_test_serialized_content = {} - - def _pre_setup(self): - for db_name in self._databases_names(include_mirrors=False): - self._connections_test_serialized_content[db_name] = connections[db_name]._test_serialized_contents - connections[db_name]._test_serialized_contents = self.initial_data_migration - super()._pre_setup() - - def _post_teardown(self): - super()._post_teardown() - for db_name in self._databases_names(include_mirrors=False): - connections[db_name]._test_serialized_contents = self._connections_test_serialized_content[db_name] - - @classmethod - def tearDownClass(cls): - super().tearDownClass() - # Clean up any data that has been created by the class. - for data in json.loads(cls.initial_data_migration): - model = apps.get_model(*data['model'].split('.')) - model.objects.filter(pk=data['pk']).delete() - - -class TestSerializedRollbackInhibitsPostMigrate(TestSerializedContentMockMixin, TransactionTestCase): +class TestSerializedRollbackInhibitsPostMigrate(TransactionTestCase): """ TransactionTestCase._fixture_teardown() inhibits the post_migrate signal for test classes with serialized_rollback=True. @@ -78,39 +44,3 @@ class TransactionTestCaseMultiDbTests(TestCase): """ for alias in connections: self.assertEqual(len(connections[alias].queries_log), 0, 'Failed for alias %s' % alias) - - -class TestDataRestoredOnTearDownIfSerializedRollback(TestSerializedContentMockMixin, TransactionTestCase): - """ - Initial data is recreated in TransactionTestCase._fixture_teardown() - after the database is flushed so it's available in next test. - """ - available_apps = ['test_utils'] - _next_serialized_rollback = True - initial_data_migration = '[{"model": "test_utils.car", "pk": 666, "fields": {"name": "K 2000"}}]' - - def _post_teardown(self): - super()._post_teardown() - # Won't be True if running the tests with --reverse. - if self._next_serialized_rollback: - self.assertTrue(Car.objects.exists()) - - def test(self): - pass # Should be the only one in this class. - - -class TestDataNotRestoredOnTearDownIfNotSerializedRollback(TestSerializedContentMockMixin, TransactionTestCase): - """ - Initial data isn't recreated in TransactionTestCase._fixture_teardown() - if _next_serialized_rollback is False. - """ - available_apps = ['test_utils'] - _next_serialized_rollback = False - initial_data_migration = '[{"model": "test_utils.car", "pk": 666, "fields": {"name": "K 2000"}}]' - - def _post_teardown(self): - super()._post_teardown() - self.assertFalse(Car.objects.exists()) - - def test(self): - pass # Should be the only one in this class. |
