feat: complete T-532 cmhub account prompt
This commit is contained in:
@@ -284,8 +284,10 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
|
||||
def test_sanitize_for_log_masks_secret_fields(self):
|
||||
payload = {
|
||||
"name": "demo",
|
||||
"email": "owner@example.com",
|
||||
"api_key": "sk-1234567890",
|
||||
"nested": {
|
||||
"support_email": "helpdesk@example.com",
|
||||
"password": "account-secret",
|
||||
"items": [
|
||||
{"provider_token": "token-secret"},
|
||||
@@ -298,6 +300,8 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
|
||||
sanitized = appconfig.sanitize_for_log(payload)
|
||||
|
||||
self.assertEqual("demo", sanitized["name"])
|
||||
self.assertEqual("o***r@example.com", sanitized["email"])
|
||||
self.assertEqual("h***k@example.com", sanitized["nested"]["support_email"])
|
||||
self.assertEqual("sk-1***7890", sanitized["api_key"])
|
||||
self.assertEqual("acco***cret", sanitized["nested"]["password"])
|
||||
self.assertEqual("toke***cret", sanitized["nested"]["items"][0]["provider_token"])
|
||||
|
||||
+76
-1
@@ -758,7 +758,11 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
"pricing_status": "priced",
|
||||
}
|
||||
]
|
||||
balance = {"user": {"id": "u1"}, "points_balance": 88}
|
||||
balance = {
|
||||
"user": "cmhub_user",
|
||||
"points_balance": 88,
|
||||
"account": {"username": "cmhub_user", "display_name": "主账号"},
|
||||
}
|
||||
|
||||
with mock.patch("app.gui.ai.fetch_cmhub_models", return_value=models) as fetch_models, \
|
||||
mock.patch("app.gui.ai.fetch_cmhub_balance", return_value=balance) as fetch_balance:
|
||||
@@ -777,6 +781,9 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertTrue(result["ok"])
|
||||
self.assertEqual(models, result["models"])
|
||||
self.assertEqual(88, result["points_balance"])
|
||||
self.assertEqual("cmhub_user", result["balance"]["user"])
|
||||
self.assertEqual("主账号", result["balance"]["account"]["display_name"])
|
||||
self.assertEqual("cmhub_user", result["balance"]["account"]["username"])
|
||||
|
||||
def test_cmhub_settings_worker_redacts_key_on_failure(self):
|
||||
worker = CMHubSettingsWorker(
|
||||
@@ -974,6 +981,74 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_settings_tab_cmhub_success_message_shows_account_name(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
cfg["ai"] = appconfig.default_config()["ai"]
|
||||
cfg["ai"]["backend"] = "cmhub"
|
||||
cfg["ai"]["cmhub"] = {
|
||||
"base_url": "https://cmhub.example.com",
|
||||
"title_alias": "",
|
||||
"image_alias": "",
|
||||
"connect_timeout": 10,
|
||||
"check_balance_before_batch": False,
|
||||
}
|
||||
statuses = []
|
||||
tab = SettingsTab(
|
||||
config=cfg,
|
||||
config_path=cfg["config_path"],
|
||||
ai_models_path=cfg["ai_models_path"],
|
||||
status_callback=statuses.append,
|
||||
)
|
||||
self.addCleanup(tab.close)
|
||||
models = [
|
||||
{"alias": "title-priced", "operation_type": "title", "pricing_status": "priced"},
|
||||
{"alias": "image-priced", "operation_type": "image", "pricing_status": "priced"},
|
||||
]
|
||||
|
||||
tab._on_cmhub_finished(
|
||||
{
|
||||
"ok": True,
|
||||
"models": models,
|
||||
"balance": {
|
||||
"user": "cmhub_user",
|
||||
"points_balance": 66,
|
||||
"account": {"username": "cmhub_user", "display_name": "主账号"},
|
||||
},
|
||||
"points_balance": 66,
|
||||
}
|
||||
)
|
||||
self.assertIn("cmhub 账号「主账号」连接成功", tab.cmhub_result_label.text())
|
||||
self.assertNotIn("cmhub 账号「cmhub_user」", tab.cmhub_result_label.text())
|
||||
self.assertIn("余额 66", tab.cmhub_result_label.text())
|
||||
self.assertEqual(tab.cmhub_result_label.text(), statuses[-1])
|
||||
|
||||
tab._on_cmhub_finished(
|
||||
{
|
||||
"ok": True,
|
||||
"models": models,
|
||||
"balance": {"user": {"name": "备用账号"}, "points_balance": 67},
|
||||
"points_balance": 67,
|
||||
}
|
||||
)
|
||||
self.assertIn("cmhub 账号「备用账号」连接成功", tab.cmhub_result_label.text())
|
||||
|
||||
tab._on_cmhub_finished(
|
||||
{
|
||||
"ok": True,
|
||||
"models": models,
|
||||
"balance": {"account": {"email": "owner@example.com"}, "points_balance": 77},
|
||||
"points_balance": 77,
|
||||
}
|
||||
)
|
||||
self.assertIn("cmhub 账号「o***r@example.com」连接成功", tab.cmhub_result_label.text())
|
||||
self.assertNotIn("owner@example.com", tab.cmhub_result_label.text())
|
||||
|
||||
tab._on_cmhub_finished({"ok": True, "models": models, "points_balance": 88})
|
||||
self.assertIn("cmhub 连接成功", tab.cmhub_result_label.text())
|
||||
self.assertNotIn("cmhub 账号", tab.cmhub_result_label.text())
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
def test_settings_tab_tracks_dirty_state_and_programmatic_cmhub_refresh_is_clean(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user