From cf9c896f518d97ee6abea7566f1634fb0784a640 Mon Sep 17 00:00:00 2001 From: "ievgenii.v" Date: Fri, 24 Oct 2025 16:34:43 +0300 Subject: [PATCH] feature: adds test for diff reactivated users --- .../lib/rc_commands/test_inactive_users.py | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/rhodecode/tests/lib/rc_commands/test_inactive_users.py b/rhodecode/tests/lib/rc_commands/test_inactive_users.py index 69bb6d14..a1f6ccbd 100644 --- a/rhodecode/tests/lib/rc_commands/test_inactive_users.py +++ b/rhodecode/tests/lib/rc_commands/test_inactive_users.py @@ -1,8 +1,10 @@ +import csv +import tempfile from datetime import datetime, timedelta import pytest -from rhodecode.lib.rc_commands.inactive_users import find_inactive_users +from rhodecode.lib.rc_commands.inactive_users import find_inactive_users, filter_reactivated_users from rhodecode.model.db import User @@ -62,4 +64,44 @@ class TestFilterInactiveUsers(object): assert len(inactive_users_without_email) == 1 assert len(inactive_users_with_email) == 0 - assert inactive_users_without_email[0].user_id == user_id \ No newline at end of file + assert inactive_users_without_email[0].user_id == user_id + + def test_diff__previously_inactive_user_reactivated(self, user_util): + prev_inactive_user = user_util.create_user(username="user_to_be_removed") + activity_long_ago = datetime.now() - timedelta(days=300) + prev_inactive_user.last_activity = activity_long_ago + user_id = prev_inactive_user.user_id + + with tempfile.NamedTemporaryFile(mode="w", newline="", encoding="utf-8", delete=False) as tmp: + path = tmp.name + w = csv.writer(tmp) + w.writerow(["user_id"]) + w.writerows([[user_id]]) + + # reactivate user + inactive_user = User.get(user_id=user_id) + inactive_user.last_activity = datetime.now() + + inactive_users, reactivated_users = filter_reactivated_users(path) + + assert len(reactivated_users) == 1 + assert len(inactive_users) == 0 + assert reactivated_users[0].user_id == user_id + + def test_diff__previously_inactive_user_remain_inactive(self, user_util): + prev_inactive_user = user_util.create_user(username="user_to_be_removed") + activity_long_ago = datetime.now() - timedelta(days=300) + prev_inactive_user.last_activity = activity_long_ago + user_id = prev_inactive_user.user_id + + with tempfile.NamedTemporaryFile(mode="w", newline="", encoding="utf-8", delete=False) as tmp: + path = tmp.name + w = csv.writer(tmp) + w.writerow(["user_id"]) + w.writerows([[user_id]]) + + inactive_users, reactivated_users = filter_reactivated_users(path) + + assert len(reactivated_users) == 0 + assert len(inactive_users) == 1 + assert inactive_users[0].user_id == user_id