diff --git a/tests/test_scrub_staging.py b/tests/test_scrub_staging.py index 58bf2d7..f4622dc 100644 --- a/tests/test_scrub_staging.py +++ b/tests/test_scrub_staging.py @@ -2,12 +2,18 @@ from datetime import timedelta from django.contrib.sessions.models import Session as DjangoSession from django.core.management import call_command -from django.test import TestCase +from django.test import TransactionTestCase from django.utils.timezone import now from django_q.models import Schedule -class ScrubStagingTest(TestCase): +class ScrubStagingTest(TransactionTestCase): + # TransactionTestCase flushes the DB before each test instead of wrapping + # in a savepoint. Required here because scrub_staging deletes all sessions + # — a TestCase savepoint rollback would restore any sessions committed by + # earlier tests (e.g. force_login in test_paths_return_200) and leak state + # into the e2e live-server tests that follow. + def test_scrub_removes_sessions_and_schedules(self): DjangoSession.objects.create( session_key="copied-from-prod", @@ -29,7 +35,6 @@ class ScrubStagingTest(TestCase): self.assertEqual(Schedule.objects.count(), 0) def test_scrub_is_safe_on_empty_database(self): - # Should not raise when there is nothing to remove (fresh staging DB). call_command("scrub_staging") self.assertEqual(DjangoSession.objects.count(), 0)