From 86a8abdc6fcd15d8f2123f9f5269a794317329ab Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Thu, 6 Apr 2023 15:54:46 +0200 Subject: [PATCH] :art: [#2632] -- Simplify regression test --- .../data_removal/tests/test_tasks.py | 51 +++++-------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/src/openforms/data_removal/tests/test_tasks.py b/src/openforms/data_removal/tests/test_tasks.py index 89f22125a1..34b4e87ed9 100644 --- a/src/openforms/data_removal/tests/test_tasks.py +++ b/src/openforms/data_removal/tests/test_tasks.py @@ -4,6 +4,8 @@ from django.test import TestCase, tag from django.utils import timezone +from freezegun import freeze_time + from openforms.config.models import GlobalConfiguration from openforms.forms.models.form_step import FormStep from openforms.forms.tests.factories import ( @@ -63,51 +65,26 @@ def test_delete_successful_submission_with_deleted_form_step(self): config = GlobalConfiguration.get_solo() # submission to be deleted - sub = SubmissionFactory.create( - registration_status=RegistrationStatuses.success, - ) - sub.created_on = timezone.now() - timedelta( + before_limit = timezone.now() - timedelta( days=config.successful_submissions_removal_limit + 1 ) - sub.save() + with freeze_time(before_limit): + sub = SubmissionFactory.create(completed=True) - # sanity check: create one additional submission that should not be deleted - SubmissionFactory.create( - registration_status=RegistrationStatuses.pending, - ) + # create a form step to then delete which introduces the RecursionError + form_step = FormStepFactory.create(form=sub.form) + SubmissionStepFactory.create(submission=sub, form_step=form_step) - # additional setup: formsteps + submission steps - form_step_1 = FormStepFactory.create( - form=FormFactory.create( - successful_submissions_removal_method=RemovalMethods.delete_permanently, - ), - form_definition=FormDefinitionFactory.create(), - ) - form_step_2 = FormStepFactory.create( - form=FormFactory.create( - successful_submissions_removal_method=RemovalMethods.delete_permanently, - ), - form_definition=FormDefinitionFactory.create(), - ) - SubmissionStepFactory.create( - form_step=form_step_1, - submission=sub, - ) - SubmissionStepFactory.create( - form_step=form_step_2, - submission=sub, - ) + # delete form step - this causes the recursion error + form_step.delete() - # delete form step - form_steps = FormStep.objects.all() - form_steps.filter(id=form_step_1.pk).delete() + assert sub.submissionstep_set.count() == 1 + assert isinstance(sub.submissionstep_set.get().form_step, FormStep) + assert not FormStep.objects.exists() delete_submissions() - self.assertEqual(Submission.objects.count(), 1) - - with self.assertRaises(ObjectDoesNotExist): - sub.refresh_from_db() + self.assertFalse(Submission.objects.exists()) def test_successful_submissions_with_form_settings_override_global_configuration( self,