Skip to content

Commit

Permalink
✅(project) update default warning and deletion periods
Browse files Browse the repository at this point in the history
Default warning and deletion period should reflect the FUN's timeframe of 5
years.
Tests have been updated accordingly to ensure compatibility with new defaults.
  • Loading branch information
wilbrdt committed Nov 25, 2024
1 parent ce9ff46 commit 9f886db
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/app/mork/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Settings(BaseSettings):
API_KEYS: list[str] = ["APIKeyToBeChanged"]

# Warning task configuration
WARNING_PERIOD: timedelta = "P3Y30D"
WARNING_PERIOD: timedelta = "P5Y30D"

# Deletion task configuration
DELETION_PERIOD: timedelta = "P3Y"
DELETION_PERIOD: timedelta = "P5Y"
DELETE_MAX_RETRIES: int = 3

# Edx forum configuration
Expand Down
29 changes: 15 additions & 14 deletions src/app/mork/tests/celery/tasks/test_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
mark_user_for_deletion,
remove_email_status,
)
from mork.conf import settings
from mork.edx.mysql.factories.auth import EdxAuthUserFactory
from mork.exceptions import UserDeleteError
from mork.factories.tasks import EmailStatusFactory
Expand All @@ -28,22 +29,22 @@

def test_delete_inactive_users(edx_mysql_db, monkeypatch):
"""Test the `delete_inactive_users` function."""
# 2 users that did not log in for 3 years
# 2 users that did not log in for more than the deletion period
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.DELETION_PERIOD),
email="johndoe1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.DELETION_PERIOD),
email="johndoe2@example.com",
)
# 2 users that logged in recently
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(start_date="-3y"),
last_login=Faker().date_time_between(start_date=-settings.DELETION_PERIOD),
email="janedah1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(start_date="-3y"),
last_login=Faker().date_time_between(start_date=-settings.DELETION_PERIOD),
email="janedah2@example.com",
)

Expand All @@ -68,13 +69,13 @@ def test_delete_inactive_users(edx_mysql_db, monkeypatch):

def test_delete_inactive_users_with_limit(edx_mysql_db, monkeypatch):
"""Test the `delete_inactive_users` function with limit."""
# 2 users that did not log in for 3 years
# 2 users that did not log in for more than the deletion period
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.DELETION_PERIOD),
email="johndoe1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.DELETION_PERIOD),
email="johndoe2@example.com",
)

Expand All @@ -98,13 +99,13 @@ def test_delete_inactive_users_with_limit(edx_mysql_db, monkeypatch):

def test_delete_inactive_users_with_batch_size(edx_mysql_db, monkeypatch):
"""Test the `warn_inactive_users` function with batch size."""
# 2 users that did not log in for 3 years
# 2 users that did not log in for more than the deletion period
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.DELETION_PERIOD),
email="johndoe1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.DELETION_PERIOD),
email="johndoe2@example.com",
)

Expand Down Expand Up @@ -144,13 +145,13 @@ def test_delete_inactive_users_with_batch_size(edx_mysql_db, monkeypatch):

def test_delete_inactive_users_with_dry_run(edx_mysql_db, monkeypatch):
"""Test the `delete_inactive_users` function with dry run activated (by default)."""
# 2 users that did not log in for 3 years
# 2 users that did not log in for more than the deletion period
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.DELETION_PERIOD),
email="johndoe1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.DELETION_PERIOD),
email="johndoe2@example.com",
)

Expand Down
29 changes: 15 additions & 14 deletions src/app/mork/tests/celery/tasks/test_emailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,33 @@
warn_inactive_users,
warn_user,
)
from mork.conf import settings
from mork.edx.mysql.factories.auth import EdxAuthUserFactory
from mork.exceptions import EmailAlreadySent, EmailSendError
from mork.factories.tasks import EmailStatusFactory


def test_warn_inactive_users(edx_mysql_db, monkeypatch):
"""Test the `warn_inactive_users` function."""
# 2 users that did not log in for 3 years
# 2 users that did not log in for more than the warning period
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.WARNING_PERIOD),
username="JohnDoe1",
email="johndoe1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.WARNING_PERIOD),
username="JohnDoe2",
email="johndoe2@example.com",
)
# 2 users that logged in recently
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(start_date="-3y"),
last_login=Faker().date_time_between(start_date=-settings.WARNING_PERIOD),
username="JaneDah1",
email="janedah1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(start_date="-3y"),
last_login=Faker().date_time_between(start_date=-settings.WARNING_PERIOD),
username="JaneDah2",
email="janedah2@example.com",
)
Expand Down Expand Up @@ -66,14 +67,14 @@ def test_warn_inactive_users(edx_mysql_db, monkeypatch):

def test_warn_inactive_users_with_limit(edx_mysql_db, monkeypatch):
"""Test the `warn_inactive_users` function with limit."""
# 2 users that did not log in for 3 years
# 2 users that did not log in for more than the warning period
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.WARNING_PERIOD),
username="JohnDoe1",
email="johndoe1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.WARNING_PERIOD),
username="JohnDoe2",
email="johndoe2@example.com",
)
Expand All @@ -100,14 +101,14 @@ def test_warn_inactive_users_with_limit(edx_mysql_db, monkeypatch):

def test_warn_inactive_users_with_batch_size(edx_mysql_db, monkeypatch):
"""Test the `warn_inactive_users` function with batch size."""
# 2 users that did not log in for 3 years
# 2 users that did not log in for more than the warning period
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.WARNING_PERIOD),
username="JohnDoe1",
email="johndoe1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.WARNING_PERIOD),
username="JohnDoe2",
email="johndoe2@example.com",
)
Expand Down Expand Up @@ -152,14 +153,14 @@ def test_warn_inactive_users_with_batch_size(edx_mysql_db, monkeypatch):

def test_warn_inactive_users_with_dry_run(edx_mysql_db, monkeypatch):
"""Test the `warn_inactive_users` function with dry run activated (by default)."""
# 2 users that did not log in for 3 years
# 2 users that did not log in for more than the warning period
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.WARNING_PERIOD),
username="JohnDoe1",
email="johndoe1@example.com",
)
EdxAuthUserFactory.create(
last_login=Faker().date_time_between(end_date="-3y"),
last_login=Faker().date_time_between(end_date=-settings.WARNING_PERIOD),
username="JohnDoe2",
email="johndoe2@example.com",
)
Expand Down

0 comments on commit 9f886db

Please sign in to comment.