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,114 @@
|
||||
"""任务接口测试"""
|
||||
from unittest.mock import patch, AsyncMock
|
||||
|
||||
|
||||
def test_list_tasks_empty(client, tmp_config):
|
||||
resp = client.get("/api/tasks")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json() == []
|
||||
|
||||
|
||||
@patch("backend.services.build_queue.build_queue")
|
||||
def test_create_task(mock_queue, client, tmp_config):
|
||||
mock_queue.submit = AsyncMock()
|
||||
resp = client.post("/api/tasks", json={
|
||||
"app_id": "1",
|
||||
"build_type": "Ad_Hoc",
|
||||
"scheme_id": "1",
|
||||
"obfuscation": True,
|
||||
"branch": "main",
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["status"] == "pending"
|
||||
assert data["app_name"] == "测试App"
|
||||
assert data["scheme_name"] == "testScheme"
|
||||
assert data["branch"] == "main"
|
||||
assert data["build_type"] == "Ad_Hoc"
|
||||
|
||||
|
||||
@patch("backend.services.build_queue.build_queue")
|
||||
def test_create_task_default_branch(mock_queue, client, tmp_config):
|
||||
mock_queue.submit = AsyncMock()
|
||||
resp = client.post("/api/tasks", json={
|
||||
"app_id": "1",
|
||||
"build_type": "Ad_Hoc",
|
||||
"scheme_id": "1",
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["branch"] == "main"
|
||||
|
||||
|
||||
@patch("backend.services.build_queue.build_queue")
|
||||
def test_create_task_invalid_app(mock_queue, client, tmp_config):
|
||||
mock_queue.submit = AsyncMock()
|
||||
resp = client.post("/api/tasks", json={
|
||||
"app_id": "999",
|
||||
"build_type": "Ad_Hoc",
|
||||
"scheme_id": "1",
|
||||
})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@patch("backend.services.build_queue.build_queue")
|
||||
def test_create_task_invalid_scheme(mock_queue, client, tmp_config):
|
||||
mock_queue.submit = AsyncMock()
|
||||
resp = client.post("/api/tasks", json={
|
||||
"app_id": "1",
|
||||
"build_type": "Ad_Hoc",
|
||||
"scheme_id": "999",
|
||||
})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@patch("backend.services.build_queue.build_queue")
|
||||
def test_list_tasks_after_create(mock_queue, client, tmp_config):
|
||||
mock_queue.submit = AsyncMock()
|
||||
client.post("/api/tasks", json={
|
||||
"app_id": "1",
|
||||
"build_type": "Ad_Hoc",
|
||||
"scheme_id": "1",
|
||||
})
|
||||
tasks = client.get("/api/tasks").json()
|
||||
assert len(tasks) == 1
|
||||
assert tasks[0]["app_name"] == "测试App"
|
||||
|
||||
|
||||
@patch("backend.services.build_queue.build_queue")
|
||||
def test_get_task_detail(mock_queue, client, tmp_config):
|
||||
mock_queue.submit = AsyncMock()
|
||||
create_resp = client.post("/api/tasks", json={
|
||||
"app_id": "1",
|
||||
"build_type": "Ad_Hoc",
|
||||
"scheme_id": "1",
|
||||
})
|
||||
task_id = create_resp.json()["id"]
|
||||
|
||||
resp = client.get(f"/api/tasks/{task_id}")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["id"] == task_id
|
||||
|
||||
|
||||
def test_get_nonexistent_task(client, tmp_config):
|
||||
resp = client.get("/api/tasks/nonexistent")
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@patch("backend.services.build_queue.build_queue")
|
||||
def test_cancel_task(mock_queue, client, tmp_config):
|
||||
mock_queue.submit = AsyncMock()
|
||||
mock_queue.cancel = lambda x: None
|
||||
|
||||
create_resp = client.post("/api/tasks", json={
|
||||
"app_id": "1",
|
||||
"build_type": "Ad_Hoc",
|
||||
"scheme_id": "1",
|
||||
})
|
||||
task_id = create_resp.json()["id"]
|
||||
|
||||
resp = client.delete(f"/api/tasks/{task_id}")
|
||||
assert resp.status_code == 200
|
||||
|
||||
# 验证状态已更新
|
||||
task = client.get(f"/api/tasks/{task_id}").json()
|
||||
assert task["status"] == "cancelled"
|
||||
Reference in New Issue
Block a user