feat: 按环境前缀生成 Apps ID

This commit is contained in:
shenlei
2026-07-20 16:24:13 +09:00
parent 8747792a4b
commit de33b3d4b2
5 changed files with 159 additions and 21 deletions
+2 -1
View File
@@ -54,7 +54,8 @@ def tmp_config(tmp_path, monkeypatch):
"1": {"name": "readoor31", "ossFloder": "test"}
},
"servers": {
"测试环境": {"api": "https://test.api.com", "assDom": "applinks:test.com", "universalLink": "https://test.com"}
"测试环境": {"api": "https://test.api.com", "assDom": "applinks:test.com", "universalLink": "https://test.com"},
"正式环境": {"api": "https://prod.api.com", "assDom": "applinks:prod.com", "universalLink": "https://prod.com"}
},
"branches": ["main", "dev"],
}))
+29 -5
View File
@@ -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):
+3 -1
View File
@@ -54,7 +54,9 @@ def test_config_routes_limit_regular_users_to_apps_and_versions(client, tmp_conf
headers = {"Authorization": f"Bearer {token}"}
assert client.get("/api/config/apps", headers=headers).status_code == 200
assert client.post("/api/config/apps", json={"name": "普通用户 App"}, headers=headers).status_code == 200
assert client.post("/api/config/apps", json={
"name": "普通用户 App", "server": "测试环境",
}, headers=headers).status_code == 200
assert client.get("/api/config/versions", headers=headers).status_code == 200
versions = client.put("/api/config/versions", json={"app_ver": "2.196.0"}, headers=headers)
assert versions.status_code == 200