From cf978e23aa787a002d66403866140cc4be2617fe Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Sat, 4 Dec 2021 00:51:33 -0800 Subject: [PATCH] fix(python): use S argument to decide Suspended Signed-off-by: Kevin Morris --- aurweb/users/update.py | 4 ++-- test/test_accounts_routes.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/aurweb/users/update.py b/aurweb/users/update.py index 60a6184e..fd42a194 100644 --- a/aurweb/users/update.py +++ b/aurweb/users/update.py @@ -12,7 +12,7 @@ def simple(U: str = str(), E: str = str(), H: bool = False, BE: str = str(), R: str = str(), HP: str = str(), I: str = str(), K: str = str(), J: bool = False, CN: bool = False, UN: bool = False, ON: bool = False, - user: models.User = None, + S: bool = False, user: models.User = None, **kwargs) -> None: now = int(datetime.utcnow().timestamp()) with db.begin(): @@ -24,7 +24,7 @@ def simple(U: str = str(), E: str = str(), H: bool = False, user.Homepage = HP or user.Homepage user.IRCNick = I or user.IRCNick user.PGPKey = K or user.PGPKey - user.Suspended = strtobool(J) + user.Suspended = strtobool(S) user.InactivityTS = now * int(strtobool(J)) user.CommentNotify = strtobool(CN) user.UpdateNotify = strtobool(UN) diff --git a/test/test_accounts_routes.py b/test/test_accounts_routes.py index 348a6994..d3435089 100644 --- a/test/test_accounts_routes.py +++ b/test/test_accounts_routes.py @@ -814,7 +814,6 @@ def test_post_account_edit_inactivity(client: TestClient, user: User): assert resp.status_code == int(HTTPStatus.OK) # Make sure the user record got updated correctly. - assert user.Suspended assert user.InactivityTS > 0 post_data.update({"J": False}) @@ -823,10 +822,37 @@ def test_post_account_edit_inactivity(client: TestClient, user: User): cookies=cookies) assert resp.status_code == int(HTTPStatus.OK) - assert not user.Suspended assert user.InactivityTS == 0 +def test_post_account_edit_suspended(client: TestClient, user: User): + with db.begin(): + user.AccountTypeID = TRUSTED_USER_ID + assert not user.Suspended + + cookies = {"AURSID": user.login(Request(), "testPassword")} + post_data = { + "U": "test", + "E": "test@example.org", + "S": True, + "passwd": "testPassword" + } + endpoint = f"/account/{user.Username}/edit" + with client as request: + resp = request.post(endpoint, data=post_data, cookies=cookies) + assert resp.status_code == int(HTTPStatus.OK) + + # Make sure the user record got updated correctly. + assert user.Suspended + + post_data.update({"S": False}) + with client as request: + resp = request.post(endpoint, data=post_data, cookies=cookies) + assert resp.status_code == int(HTTPStatus.OK) + + assert not user.Suspended + + def test_post_account_edit_error_unauthorized(client: TestClient, user: User): request = Request() sid = user.login(request, "testPassword")