Skip to content

Commit

Permalink
Add failsafe test
Browse files Browse the repository at this point in the history
  • Loading branch information
msj committed Jun 8, 2023
1 parent 4246e6b commit 1b9a313
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pupa/tests/clean/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,25 @@ def test_clean_command(subparsers):
for obj in expected_not_stale_objects:
was_not_deleted = type(obj).objects.filter(id=obj.id).exists()
assert was_not_deleted


@pytest.mark.django_db
def test_clean_command_failsafe(subparsers):
_ = create_jurisdiction()
o = Organization.objects.create(name="WWE", jurisdiction_id="jid")

stale_people = [
Person.objects.create(name="George Washington", family_name="Washington")
for i in range(20)
]
stale_memberships = [ # noqa
p.memberships.create(organization=o) for p in stale_people
]

a_week_from_now = datetime.now(tz=timezone.utc) + timedelta(days=7)
with freeze_time(a_week_from_now):
with pytest.raises(SystemExit):
# Should trigger failsafe exist when deleting more than 10 objects
Command(subparsers).handle(
argparse.Namespace(noinput=True, report=False, window=7), []
)

0 comments on commit 1b9a313

Please sign in to comment.