diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2016-02-12 16:41:31 -0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-02-13 06:53:39 -0500 |
| commit | fcd08c175787e909b3eb98f756317a07741c48dd (patch) | |
| tree | 3a942d750d044adb6aed65358baca5a832eb03ff /tests | |
| parent | a6f856df52d532d5537191eca237de6efdffe309 (diff) | |
Fixed #11665 -- Made TestCase check deferrable constraints after each test.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auth_tests/test_views.py | 6 | ||||
| -rw-r--r-- | tests/test_utils/test_testcase.py | 20 |
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py index 7fd493ca34..d8325d8b93 100644 --- a/tests/auth_tests/test_views.py +++ b/tests/auth_tests/test_views.py @@ -991,3 +991,9 @@ class UUIDUserTests(TestCase): self.assertEqual(row.user_id, 1) # hardcoded in CustomUserAdmin.log_change() self.assertEqual(row.object_id, str(u.pk)) self.assertEqual(row.get_change_message(), 'Changed password.') + + # The LogEntry.user column isn't altered to a UUID type so it's set to + # an integer manually in CustomUserAdmin to avoid an error. To avoid a + # constraint error, delete the entry before constraints are checked + # after the test. + row.delete() diff --git a/tests/test_utils/test_testcase.py b/tests/test_utils/test_testcase.py new file mode 100644 index 0000000000..8a367391cb --- /dev/null +++ b/tests/test_utils/test_testcase.py @@ -0,0 +1,20 @@ +from django.db import IntegrityError, transaction +from django.test import TestCase, skipUnlessDBFeature + +from .models import PossessedCar + + +class TestTestCase(TestCase): + + @skipUnlessDBFeature('can_defer_constraint_checks') + @skipUnlessDBFeature('supports_foreign_keys') + def test_fixture_teardown_checks_constraints(self): + rollback_atomics = self._rollback_atomics + self._rollback_atomics = lambda connection: None # noop + try: + car = PossessedCar.objects.create(car_id=1, belongs_to_id=1) + with self.assertRaises(IntegrityError), transaction.atomic(): + self._fixture_teardown() + car.delete() + finally: + self._rollback_atomics = rollback_atomics |
