feat: improve responsive admin experience

This commit is contained in:
2026-08-04 16:47:14 +08:00
parent c71b1351d6
commit 631a362501
20 changed files with 522 additions and 801 deletions
+45
View File
@@ -82,6 +82,51 @@ class EmailAuthenticationTest(unittest.TestCase):
data["csrf_token"] = self.csrf(page)
return client.post(path, data=data)
def login_as(self, client, user: User) -> None:
with client.session_transaction() as state:
state["_user_id"] = str(user.id)
state["_fresh"] = True
state["auth_version"] = user.auth_version
def test_admin_user_list_is_paginated_and_searchable(self):
with TemporaryDirectory() as directory:
app = self.create_app(directory)
with app.app_context():
admin = User(
username="Admin",
email="admin@example.com",
is_admin=True,
is_active_account=True,
)
admin.set_password("Password-1234!")
db.session.add(admin)
for index in range(21):
user = User(
username=f"User{index:02d}",
email=f"user{index:02d}@example.com",
is_active_account=True,
)
user.set_password("Password-1234!")
db.session.add(user)
db.session.commit()
admin_id = admin.id
client = app.test_client()
with app.app_context():
self.login_as(client, db.session.get(User, admin_id))
response = client.get("/admin?user_page=2")
html = response.get_data(as_text=True)
self.assertEqual(response.status_code, 200)
self.assertIn("共 21 位用户,第 2 / 2 页", html)
self.assertIn("User00", html)
self.assertNotIn("User20", html)
response = client.get("/admin?q=user20@example.com")
html = response.get_data(as_text=True)
self.assertIn("共 1 位用户,第 1 / 1 页", html)
self.assertIn("User20", html)
@patch("app.routes.send_transactional_email")
@patch("app.routes.secrets.randbelow", return_value=123456)
def test_registration_requires_and_consumes_email_code(self, _random, _send):