From 40e3a7dfdde31b05d420f4afe25dea05025e73d5 Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 23 Nov 2026 16:23:04 +0300 Subject: [PATCH] test(accounts): the first-login audit test leaves the checkout's admin password file test_the_first_login_password_change made the last forced password change with the real BASE_DIR, so the view deleted data/admin_password of the checkout the tests ran in. It now runs under a temporary BASE_DIR, as the other first-login tests do. --- accounts/tests/test_audit_rows.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/accounts/tests/test_audit_rows.py b/accounts/tests/test_audit_rows.py index 57764be5..f8284adf 100644 --- a/accounts/tests/test_audit_rows.py +++ b/accounts/tests/test_audit_rows.py @@ -1,7 +1,10 @@ """Changes to a user's own account, VM ownership, OTP mails and SSH keys write rows on the Logs page.""" +import tempfile +from pathlib import Path + from django.contrib.auth import get_user_model -from django.test import TestCase +from django.test import TestCase, override_settings from django.urls import reverse from accounts.models import UserAttributes @@ -38,8 +41,10 @@ class OwnAccountRowTests(TestCase): def test_the_first_login_password_change(self): self.bob.user_permissions.clear() UserAttributes.objects.update_or_create(user=self.bob, defaults={"must_change_password": True}) - self.client.post(reverse("accounts:change_password"), { - "old_password": "Bob-pass-2026", "new_password1": "Bob-new-pass-1", "new_password2": "Bob-new-pass-1"}) + # the last forced change deletes data/admin_password: not this checkout's + with tempfile.TemporaryDirectory() as base, override_settings(BASE_DIR=Path(base)): + self.client.post(reverse("accounts:change_password"), { + "old_password": "Bob-pass-2026", "new_password1": "Bob-new-pass-1", "new_password2": "Bob-new-pass-1"}) self.assertEqual(rows(), [("User bob: change password", True)])