Skip to content

Commit

Permalink
🎨 Simplify regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Apr 6, 2023
1 parent 8532cde commit c721d6f
Showing 1 changed file with 14 additions and 37 deletions.
51 changes: 14 additions & 37 deletions src/openforms/data_removal/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c721d6f

Please sign in to comment.