更新
This commit is contained in:
@@ -4,7 +4,7 @@ from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
from PySide6.QtCore import QSettings
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from PySide6.QtWidgets import QApplication, QDialogButtonBox, QMessageBox
|
||||
|
||||
from doctor_workstation import app as app_module
|
||||
from doctor_workstation.app import ApplicationController
|
||||
@@ -232,11 +232,28 @@ def test_real_demo_login_reaches_success_without_widget_adapter(
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_remembered_account_survives_a_new_login_window(tmp_path: Any) -> None:
|
||||
def test_remembered_password_survives_a_new_login_window(tmp_path: Any) -> None:
|
||||
application = QApplication.instance() or QApplication([])
|
||||
settings_path = tmp_path / "remember-account.ini"
|
||||
settings_path = tmp_path / "remember-password.ini"
|
||||
secrets: dict[tuple[str, str], str] = {}
|
||||
|
||||
def load_password(*, account: str, scope: str) -> str | None:
|
||||
return secrets.get((account, scope.rstrip("/")))
|
||||
|
||||
def save_password(password: str, *, account: str, scope: str) -> bool:
|
||||
secrets[(account, scope.rstrip("/"))] = password
|
||||
return True
|
||||
|
||||
def clear_password(*, account: str, scope: str) -> None:
|
||||
secrets.pop((account, scope.rstrip("/")), None)
|
||||
|
||||
credentials = SimpleNamespace(
|
||||
load_password=load_password,
|
||||
save_password=save_password,
|
||||
clear_password=clear_password,
|
||||
)
|
||||
config = SimpleNamespace(
|
||||
api_base_url="",
|
||||
api_base_url="https://example.test/adminapi",
|
||||
request_timeout=30,
|
||||
verify_ssl=True,
|
||||
demo_mode=False,
|
||||
@@ -246,8 +263,9 @@ def test_remembered_account_survives_a_new_login_window(tmp_path: Any) -> None:
|
||||
object(),
|
||||
config=config,
|
||||
settings=QSettings(str(settings_path), QSettings.Format.IniFormat),
|
||||
credential_store=credentials,
|
||||
)
|
||||
first._on_login_success({}, "admin", True)
|
||||
first._on_login_success({}, "admin", True, "secret-value")
|
||||
first.close()
|
||||
application.processEvents()
|
||||
|
||||
@@ -255,12 +273,28 @@ def test_remembered_account_survives_a_new_login_window(tmp_path: Any) -> None:
|
||||
object(),
|
||||
config=config,
|
||||
settings=QSettings(str(settings_path), QSettings.Format.IniFormat),
|
||||
credential_store=credentials,
|
||||
)
|
||||
assert restored.account_edit.text() == "admin"
|
||||
assert restored.password_edit.text() == "secret-value"
|
||||
assert restored.remember_check.text() == "记住密码"
|
||||
assert restored.remember_check.isChecked()
|
||||
|
||||
restored._on_login_success({}, "admin", False, "secret-value")
|
||||
restored.close()
|
||||
application.processEvents()
|
||||
|
||||
forgotten = LoginWindow(
|
||||
object(),
|
||||
config=config,
|
||||
settings=QSettings(str(settings_path), QSettings.Format.IniFormat),
|
||||
credential_store=credentials,
|
||||
)
|
||||
assert forgotten.password_edit.text() == ""
|
||||
assert not forgotten.remember_check.isChecked()
|
||||
forgotten.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_server_settings_panel_keeps_controls_separated_at_minimum_window(
|
||||
tmp_path: Any,
|
||||
@@ -386,6 +420,37 @@ def test_certificate_error_explains_self_signed_server_setting() -> None:
|
||||
assert "服务器设置" in message
|
||||
|
||||
|
||||
def test_qt_standard_dialog_buttons_are_localized_to_chinese() -> None:
|
||||
application = QApplication.instance() or QApplication([])
|
||||
app_module._install_chinese_translations(application)
|
||||
|
||||
question = QMessageBox()
|
||||
question.setStandardButtons(
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel
|
||||
)
|
||||
assert question.button(QMessageBox.StandardButton.Yes).text() == "是"
|
||||
assert question.button(QMessageBox.StandardButton.Cancel).text() == "取消"
|
||||
|
||||
buttons = QDialogButtonBox(
|
||||
QDialogButtonBox.StandardButton.Ok
|
||||
| QDialogButtonBox.StandardButton.Save
|
||||
| QDialogButtonBox.StandardButton.Close
|
||||
)
|
||||
assert buttons.button(QDialogButtonBox.StandardButton.Ok).text() == "确定"
|
||||
assert buttons.button(QDialogButtonBox.StandardButton.Save).text() == "保存"
|
||||
assert buttons.button(QDialogButtonBox.StandardButton.Close).text() == "关闭"
|
||||
|
||||
|
||||
def test_friendly_error_hides_english_technical_messages() -> None:
|
||||
message = friendly_error(
|
||||
TypeError("invoke() takes 2 positional arguments but 3 were given")
|
||||
)
|
||||
assert message == "程序执行失败,请重试;若问题持续出现,请联系管理员。"
|
||||
assert friendly_error(RuntimeError("API response envelope must be an object")) == (
|
||||
"服务器返回的数据格式不正确,请联系管理员检查接口。"
|
||||
)
|
||||
|
||||
|
||||
def test_certificate_error_opens_server_settings(tmp_path: Any) -> None:
|
||||
application = QApplication.instance() or QApplication([])
|
||||
settings = QSettings(str(tmp_path / "certificate-error.ini"), QSettings.Format.IniFormat)
|
||||
|
||||
Reference in New Issue
Block a user