146 lines
4.5 KiB
Python
146 lines
4.5 KiB
Python
import pytest
|
|
|
|
from app.core.plugin_http_client import PluginHttpClient
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_plugin_http_client_uses_creo_open_model_endpoint_and_payload(monkeypatch):
|
|
client = PluginHttpClient()
|
|
captured = {}
|
|
|
|
def fake_post_json(url, payload, timeout):
|
|
captured["url"] = url
|
|
captured["payload"] = payload
|
|
captured["timeout"] = timeout
|
|
return {"status": "success"}
|
|
|
|
monkeypatch.setattr(PluginHttpClient, "_post_json", staticmethod(fake_post_json))
|
|
|
|
response = await client.submit_task(
|
|
"creo",
|
|
"open_model",
|
|
{
|
|
"model_path": r"C:\\models\\part.prt",
|
|
"task_params": {},
|
|
"execution_id": "exec-1",
|
|
"batch_id": "batch-1",
|
|
"item_id": "item-1",
|
|
"callback_url": "http://localhost/callback",
|
|
"attempt": 0,
|
|
},
|
|
)
|
|
|
|
assert response["status"] == "success"
|
|
assert captured["url"].endswith("/api/model/open")
|
|
assert captured["payload"]["filePath"].endswith("part.prt")
|
|
assert captured["payload"]["execution_id"] == "exec-1"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_plugin_http_client_uses_pdms_open_project_payload(monkeypatch):
|
|
client = PluginHttpClient()
|
|
captured = {}
|
|
|
|
def fake_post_json(url, payload, timeout):
|
|
captured["url"] = url
|
|
captured["payload"] = payload
|
|
return {"status": "success"}
|
|
|
|
monkeypatch.setattr(PluginHttpClient, "_post_json", staticmethod(fake_post_json))
|
|
|
|
response = await client.submit_task(
|
|
"pdms",
|
|
"open_project",
|
|
{
|
|
"model_path": "",
|
|
"task_params": {
|
|
"projectName": "SAM",
|
|
"username": "SYSTEM",
|
|
"password": "XXXXXX",
|
|
"systemName": "CATA",
|
|
},
|
|
"execution_id": "exec-2",
|
|
"batch_id": "batch-2",
|
|
"item_id": "item-2",
|
|
"callback_url": "http://localhost/callback",
|
|
"attempt": 0,
|
|
},
|
|
)
|
|
|
|
assert response["status"] == "success"
|
|
assert captured["url"].endswith("/api/project/open")
|
|
assert captured["payload"]["projectName"] == "SAM"
|
|
assert captured["payload"]["execution_id"] == "exec-2"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_plugin_http_client_uses_creo_close_model_payload(monkeypatch):
|
|
client = PluginHttpClient()
|
|
captured = {}
|
|
|
|
def fake_post_json(url, payload, timeout):
|
|
captured["url"] = url
|
|
captured["payload"] = payload
|
|
return {"success": True, "data": {"model_name": "x.prt"}, "error": None}
|
|
|
|
monkeypatch.setattr(PluginHttpClient, "_post_json", staticmethod(fake_post_json))
|
|
|
|
response = await client.submit_task(
|
|
"creo",
|
|
"close_model",
|
|
{
|
|
"model_path": r"C:\\models\\part.prt",
|
|
"task_params": {"force_close": True, "software_type": "wrong_value_ignored"},
|
|
"execution_id": "exec-close",
|
|
"batch_id": "batch-close",
|
|
"item_id": "item-close",
|
|
"callback_url": "http://localhost/callback",
|
|
"attempt": 0,
|
|
},
|
|
)
|
|
|
|
assert response["success"] is True
|
|
assert captured["url"].endswith("/api/model/close")
|
|
assert captured["payload"] == {"software_type": "creo", "force_close": True}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_plugin_http_client_uses_revit_close_model_empty_payload(monkeypatch):
|
|
client = PluginHttpClient()
|
|
captured = {}
|
|
|
|
def fake_post_json(url, payload, timeout):
|
|
captured["url"] = url
|
|
captured["payload"] = payload
|
|
return {
|
|
"success": True,
|
|
"code": 200,
|
|
"message": "文件关闭成功",
|
|
"data": {
|
|
"result": "文件关闭成功",
|
|
"fileName": "xxx.rvt",
|
|
"filePath": r"C:\\path\\xxx.rvt",
|
|
},
|
|
"timestamp": "2026-03-01T08:00:00Z",
|
|
}
|
|
|
|
monkeypatch.setattr(PluginHttpClient, "_post_json", staticmethod(fake_post_json))
|
|
|
|
response = await client.submit_task(
|
|
"revit",
|
|
"close_model",
|
|
{
|
|
"model_path": r"C:\\models\\a.rvt",
|
|
"task_params": {"ignored": True},
|
|
"execution_id": "exec-revit-close",
|
|
"batch_id": "batch-revit-close",
|
|
"item_id": "item-revit-close",
|
|
"callback_url": "http://localhost/callback",
|
|
"attempt": 0,
|
|
},
|
|
)
|
|
|
|
assert response["success"] is True
|
|
assert captured["url"].endswith("/api/close")
|
|
assert captured["payload"] == {}
|