feat: 按环境前缀生成 Apps ID
This commit is contained in:
@@ -20,14 +20,32 @@ def test_get_apps(client, tmp_config):
|
||||
|
||||
|
||||
def test_create_app(client, tmp_config):
|
||||
resp = client.post("/api/config/apps", json={"name": "新App", "AppGuid": "new-guid"})
|
||||
resp = client.post("/api/config/apps", json={
|
||||
"name": "新App", "server": "测试环境", "AppGuid": "new-guid",
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["id"] == "2"
|
||||
assert resp.json()["id"] == "100"
|
||||
|
||||
# 验证已创建
|
||||
apps = client.get("/api/config/apps").json()
|
||||
assert "2" in apps
|
||||
assert apps["2"]["name"] == "新App"
|
||||
assert "100" in apps
|
||||
assert apps["100"]["name"] == "新App"
|
||||
|
||||
|
||||
def test_create_app_uses_environment_prefix_and_dictionary_exception(client, tmp_config):
|
||||
official = client.post("/api/config/apps", json={"name": "正式 App", "server": "正式环境"})
|
||||
dictionary = client.post("/api/config/apps", json={"name": "英汉大词典", "server": "正式环境"})
|
||||
|
||||
assert official.status_code == 200
|
||||
assert official.json()["id"] == "200"
|
||||
assert dictionary.status_code == 200
|
||||
assert dictionary.json()["id"] == "100"
|
||||
|
||||
|
||||
def test_create_app_rejects_unknown_environment_id_rule(client, tmp_config):
|
||||
resp = client.post("/api/config/apps", json={"name": "新 App", "server": "未知环境"})
|
||||
assert resp.status_code == 400
|
||||
assert "ID 规则" in resp.json()["detail"]
|
||||
|
||||
|
||||
def test_update_app(client, tmp_config):
|
||||
@@ -121,7 +139,13 @@ def test_create_server(client, tmp_config):
|
||||
"universalLink": "https://new.com",
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert "新环境" in client.get("/api/config/servers").json()
|
||||
servers = client.get("/api/config/servers").json()
|
||||
assert servers["新环境"]["app_id_prefix"] == 3
|
||||
|
||||
client.delete("/api/config/servers/新环境")
|
||||
second = client.post("/api/config/servers", json={"name": "第二环境", "api": "https://second.api.com"})
|
||||
assert second.status_code == 200
|
||||
assert client.get("/api/config/servers").json()["第二环境"]["app_id_prefix"] == 4
|
||||
|
||||
|
||||
def test_delete_server_in_use(client, tmp_config):
|
||||
|
||||
Reference in New Issue
Block a user