-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extra test for user suspension special cases, and document and si…
…mplify suspension logic (closes: #1293) Main change is that users only get suspended/deleted at the configured number of days after their last warning, and are eligible for deletion at the configured number of days after suspension, even if the allowed_inactive_period_days config var changes after the warning is sent. This allow us to steadily decrease allowed_inactive_period_days from the current (large) value to the agreed value of 1 year, without all users getting deleted before they can act on their warnings, or before the suspension grace period has passed. Closes: #1293
- Loading branch information
1 parent
164b817
commit e4b21b2
Showing
3 changed files
with
70 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,3 +84,42 @@ def test_schedule(self): | |
self.assertListEqual(["[email protected]"], results["warning_deleted_notifications"]) | ||
self.assertListEqual(["[email protected]"], results["deleted_notifications"]) | ||
self.assertEqual(3, len(outbox)) | ||
|
||
def test_schedule_changed_config(self): | ||
mail = self.app.mail | ||
|
||
# run suspend cron job | ||
results = suspend_users(self.app) | ||
self.assertListEqual(["[email protected]"], results["warning_suspend_notifications"]) | ||
self.assertListEqual(["[email protected]"], results["suspended_notifications"]) | ||
self.assertListEqual(["[email protected]"], results["warning_deleted_notifications"]) | ||
self.assertListEqual(["[email protected]"], results["deleted_notifications"]) | ||
|
||
# now we change the config | ||
# this causes the last active date of all suspended users to shift past the deletion date | ||
self.app.app_config.retention.allowed_inactive_period_days -= ( | ||
self.app.app_config.retention.remove_suspended_users_period_days | ||
+ 1) | ||
# now run suspend cron job again; nothing should change! | ||
with mail.record_messages() as outbox: | ||
results = suspend_users(self.app) | ||
self.assertListEqual([], results["warning_suspend_notifications"]) | ||
self.assertListEqual([], results["suspended_notifications"]) | ||
self.assertListEqual([], results["warning_deleted_notifications"]) | ||
self.assertListEqual([], results["deleted_notifications"]) | ||
self.assertListEqual([], outbox) | ||
|
||
# now fast-forward time past the waiting window | ||
retention = self.app.app_config.retention | ||
newdate = (dt_now() | ||
+ timedelta(retention.reminder_suspend_period_days) | ||
+ timedelta(retention.remove_suspended_users_period_days)) | ||
with freeze_time(newdate): | ||
with mail.record_messages() as outbox: | ||
# now users should be suspended/reminede again because their notifications are older than the threshold | ||
results = suspend_users(self.app) | ||
self.assertListEqual([], results["warning_suspend_notifications"]) | ||
self.assertListEqual(["[email protected]"], results["suspended_notifications"]) | ||
self.assertListEqual(["[email protected]"], results["warning_deleted_notifications"]) | ||
self.assertListEqual(["[email protected]"], results["deleted_notifications"]) | ||
self.assertEqual(3, len(outbox)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters