feat(settings): rename custom gateway models
This commit is contained in:
@@ -565,6 +565,48 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_rename_ai_model_preserves_fields_and_rejects_invalid_name(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
models_path = os.path.join(temp_dir, "ai_models.json")
|
||||
appconfig.add_ai_model(
|
||||
{
|
||||
"name": "Text 2",
|
||||
"category": "text",
|
||||
"enabled": False,
|
||||
"url": "https://example.invalid/v1/chat/completions",
|
||||
"model": "demo-model",
|
||||
"api_key": "sk-1234567890",
|
||||
"api_type": "chat",
|
||||
"connect_timeout_seconds": 12,
|
||||
"timeout_seconds": 45,
|
||||
"extra_body": {"temperature": 0},
|
||||
},
|
||||
path=models_path,
|
||||
)
|
||||
before = appconfig.get_model("Text 2", path=models_path)
|
||||
|
||||
renamed = appconfig.rename_ai_model(
|
||||
"Text 2",
|
||||
" 文本模型 ",
|
||||
path=models_path,
|
||||
)
|
||||
|
||||
self.assertEqual("文本模型", renamed["name"])
|
||||
self.assertEqual(
|
||||
{**before, "name": "文本模型"},
|
||||
appconfig.get_model("文本模型", path=models_path),
|
||||
)
|
||||
with self.assertRaisesRegex(appconfig.ConfigError, "模型名称不能为空"):
|
||||
appconfig.rename_ai_model("文本模型", " ", path=models_path)
|
||||
with self.assertRaisesRegex(appconfig.ConfigError, "模型名称已存在"):
|
||||
appconfig.rename_ai_model(
|
||||
"文本模型",
|
||||
"GPT-5.5 文本",
|
||||
path=models_path,
|
||||
)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_ai_model_constraints_and_connection_validation(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
models_path = os.path.join(temp_dir, "ai_models.json")
|
||||
|
||||
Reference in New Issue
Block a user