Initial commit: iOS Build Server
- FastAPI backend with build queue, WebSocket logs, task management - Vue 3 frontend with build/config/history views - Xcode project build automation with IPA export - Fix: initialize build_dir before try block to ensure cleanup on early failure
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
"""配置管理接口测试"""
|
||||
import json
|
||||
|
||||
|
||||
def test_get_full_config(client, tmp_config):
|
||||
resp = client.get("/api/config")
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert "apps" in data
|
||||
assert "schemes" in data
|
||||
assert "branches" in data
|
||||
|
||||
|
||||
# ---- Apps ----
|
||||
|
||||
def test_get_apps(client, tmp_config):
|
||||
resp = client.get("/api/config/apps")
|
||||
assert resp.status_code == 200
|
||||
assert "1" in resp.json()
|
||||
|
||||
|
||||
def test_create_app(client, tmp_config):
|
||||
resp = client.post("/api/config/apps", json={"name": "新App", "AppGuid": "new-guid"})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["id"] == "2"
|
||||
|
||||
# 验证已创建
|
||||
apps = client.get("/api/config/apps").json()
|
||||
assert "2" in apps
|
||||
assert apps["2"]["name"] == "新App"
|
||||
|
||||
|
||||
def test_update_app(client, tmp_config):
|
||||
resp = client.put("/api/config/apps/1", json={"name": "改名App", "AppGuid": "test-guid"})
|
||||
assert resp.status_code == 200
|
||||
assert client.get("/api/config/apps").json()["1"]["name"] == "改名App"
|
||||
|
||||
|
||||
def test_delete_app(client, tmp_config):
|
||||
resp = client.delete("/api/config/apps/1")
|
||||
assert resp.status_code == 200
|
||||
assert "1" not in client.get("/api/config/apps").json()
|
||||
|
||||
|
||||
def test_update_nonexistent_app(client, tmp_config):
|
||||
resp = client.put("/api/config/apps/999", json={"name": "x"})
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
# ---- Schemes ----
|
||||
|
||||
def test_get_schemes(client, tmp_config):
|
||||
resp = client.get("/api/config/schemes")
|
||||
assert resp.status_code == 200
|
||||
assert "1" in resp.json()
|
||||
|
||||
|
||||
def test_create_scheme(client, tmp_config):
|
||||
resp = client.post("/api/config/schemes", json={"name": "newScheme", "ossFloder": "new"})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["id"] == "2"
|
||||
|
||||
|
||||
def test_delete_scheme(client, tmp_config):
|
||||
resp = client.delete("/api/config/schemes/1")
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
# ---- Branches ----
|
||||
|
||||
def test_get_branches(client, tmp_config):
|
||||
resp = client.get("/api/config/branches")
|
||||
assert resp.status_code == 200
|
||||
branches = resp.json()
|
||||
assert "main" in branches
|
||||
assert "dev" in branches
|
||||
|
||||
|
||||
def test_add_branch(client, tmp_config):
|
||||
resp = client.post("/api/config/branches", json={"name": "release/1.0"})
|
||||
assert resp.status_code == 200
|
||||
branches = client.get("/api/config/branches").json()
|
||||
assert "release/1.0" in branches
|
||||
|
||||
|
||||
def test_add_duplicate_branch(client, tmp_config):
|
||||
resp = client.post("/api/config/branches", json={"name": "main"})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_add_empty_branch(client, tmp_config):
|
||||
resp = client.post("/api/config/branches", json={"name": ""})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_delete_branch(client, tmp_config):
|
||||
resp = client.delete("/api/config/branches/dev")
|
||||
assert resp.status_code == 200
|
||||
branches = client.get("/api/config/branches").json()
|
||||
assert "dev" not in branches
|
||||
|
||||
|
||||
def test_delete_nonexistent_branch(client, tmp_config):
|
||||
resp = client.delete("/api/config/branches/notexist")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
# ---- Servers ----
|
||||
|
||||
def test_get_servers(client, tmp_config):
|
||||
resp = client.get("/api/config/servers")
|
||||
assert resp.status_code == 200
|
||||
assert "测试环境" in resp.json()
|
||||
|
||||
|
||||
def test_create_server(client, tmp_config):
|
||||
resp = client.post("/api/config/servers", json={
|
||||
"name": "新环境",
|
||||
"api": "https://new.api.com",
|
||||
"assDom": "applinks:new.com",
|
||||
"universalLink": "https://new.com",
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert "新环境" in client.get("/api/config/servers").json()
|
||||
|
||||
|
||||
def test_delete_server_in_use(client, tmp_config):
|
||||
# 测试环境被 App 1 使用,应该删除失败
|
||||
resp = client.delete("/api/config/servers/测试环境")
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
# ---- Build Settings ----
|
||||
|
||||
def test_get_build_settings(client, tmp_config):
|
||||
resp = client.get("/api/config/build")
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert "max_concurrent_builds" in data
|
||||
assert "build_dir_retention_hours" in data
|
||||
|
||||
|
||||
def test_update_build_settings(client, tmp_config):
|
||||
resp = client.put("/api/config/build", json={"max_concurrent_builds": 4})
|
||||
assert resp.status_code == 200
|
||||
assert client.get("/api/config/build").json()["max_concurrent_builds"] == 4
|
||||
Reference in New Issue
Block a user