T-580 精简设置页更新执行配置

This commit is contained in:
chengma
2026-07-10 10:12:15 +08:00
parent c078e68e98
commit e70e831afa
12 changed files with 259 additions and 287 deletions
+66 -3
View File
@@ -29,7 +29,8 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
self.assertFalse(appconfig.ai_config(config)["generate_cover"])
self.assertEqual("title", appconfig.ai_generate_mode(config))
self.assertEqual("title", appconfig.shopee_update_config(config)["update_mode"])
self.assertFalse(appconfig.shopee_update_config(config)["allow_cover_update"])
self.assertNotIn("allow_cover_update", appconfig.shopee_update_config(config))
self.assertEqual(1, appconfig.shopee_update_config(config)["max_parallel_accounts"])
updated = appconfig.update_config(
{"ai": {"resolution": "2k"}},
@@ -48,7 +49,7 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
self.assertEqual("title_cover", appconfig.ai_generate_mode(legacy))
self.assertTrue(appconfig.ai_config(legacy)["generate_cover"])
self.assertEqual("title_cover", appconfig.shopee_update_config(legacy)["update_mode"])
self.assertTrue(appconfig.shopee_update_config(legacy)["allow_cover_update"])
self.assertNotIn("allow_cover_update", appconfig.shopee_update_config(legacy))
cover_only = appconfig.save_config(
{
@@ -60,7 +61,69 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
self.assertEqual("cover", appconfig.ai_generate_mode(cover_only))
self.assertTrue(appconfig.ai_config(cover_only)["generate_cover"])
self.assertEqual("cover", appconfig.shopee_update_config(cover_only)["update_mode"])
self.assertTrue(appconfig.shopee_update_config(cover_only)["allow_cover_update"])
self.assertNotIn("allow_cover_update", appconfig.shopee_update_config(cover_only))
self.assert_removed(temp_dir)
def test_shopee_update_legacy_parallel_config_is_migrated(self):
with self.make_temp_dir() as temp_dir:
config_path = os.path.join(temp_dir, "config.json")
with open(config_path, "w", encoding="utf-8") as fh:
json.dump(
{
"shopee_update": {
"allow_real_submit": False,
"allow_cover_update": True,
"close_success_tab": False,
"parallel_accounts": False,
"max_parallel_accounts": 2,
}
},
fh,
)
loaded = appconfig.load_config(config_path)
update_cfg = appconfig.shopee_update_config(loaded)
self.assertEqual("title_cover", update_cfg["update_mode"])
self.assertEqual(1, update_cfg["max_parallel_accounts"])
for key in (
"allow_real_submit",
"allow_cover_update",
"close_success_tab",
"parallel_accounts",
):
self.assertNotIn(key, update_cfg)
saved = appconfig.save_config(loaded, path=config_path)
with open(config_path, "r", encoding="utf-8") as fh:
persisted = json.load(fh)
persisted_update = persisted["shopee_update"]
self.assertEqual(1, saved["shopee_update"]["max_parallel_accounts"])
for key in (
"allow_real_submit",
"allow_cover_update",
"close_success_tab",
"parallel_accounts",
):
self.assertNotIn(key, persisted_update)
with open(config_path, "w", encoding="utf-8") as fh:
json.dump(
{
"shopee_update": {
"parallel_accounts": True,
"max_parallel_accounts": 16,
}
},
fh,
)
loaded_parallel = appconfig.load_config(config_path)
self.assertEqual(
5,
appconfig.shopee_update_config(loaded_parallel)["max_parallel_accounts"],
)
self.assert_removed(temp_dir)