feat(firmware): support rocking-horse workbench delivery
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import json
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import urllib.request
|
||||
import zipfile
|
||||
from http.server import ThreadingHTTPServer
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from cognitive_agent.application.firmware_workbench import FirmwareWorkbenchService
|
||||
from cognitive_agent.auth import AuthConfig, AuthRuntime
|
||||
@@ -75,8 +80,14 @@ class TestFirmwareWorkbenchApi:
|
||||
with urllib.request.urlopen(request, timeout=5) as response:
|
||||
return response.status, json.loads(response.read().decode())
|
||||
|
||||
def test_real_http_task_publish_detail_and_download_flow(self) -> None:
|
||||
instruction = "增加位置控制、座椅通风和座椅加热功能"
|
||||
@pytest.mark.parametrize("instruction,capabilities", [
|
||||
("增加位置控制、座椅通风和座椅加热功能", ["时间控制", "位置控制", "座椅通风", "座椅加热"]),
|
||||
("增加动态木马功能", ["时间控制", "位置控制", "动态木马"]),
|
||||
("增加动态木马、座椅通风和座椅加热功能", ["时间控制", "位置控制", "座椅通风", "座椅加热", "动态木马"]),
|
||||
])
|
||||
def test_real_http_task_publish_detail_and_download_flow(
|
||||
self, instruction: str, capabilities: list[str], monkeypatch
|
||||
) -> None:
|
||||
status, created = self.post(
|
||||
"/api/firmware-workbench/tasks", {"instruction": instruction}
|
||||
)
|
||||
@@ -135,6 +146,26 @@ class TestFirmwareWorkbenchApi:
|
||||
assert response.headers["Content-Type"] == "application/zip"
|
||||
assert "attachment" in response.headers["Content-Disposition"]
|
||||
assert len(package) == artifact["size_bytes"]
|
||||
assert artifact["capabilities"] == capabilities
|
||||
with zipfile.ZipFile(io.BytesIO(package)) as archive:
|
||||
assert json.loads(archive.read("manifest.json"))["capabilities"] == capabilities
|
||||
|
||||
frames = []
|
||||
|
||||
def publish(frame):
|
||||
frames.append(frame)
|
||||
return {"status": "published"}
|
||||
|
||||
monkeypatch.setattr(
|
||||
SeatDemoHandler, "service", SimpleNamespace(publish_firmware_notification=publish)
|
||||
)
|
||||
notify_status, notified = self.post(
|
||||
f"/api/firmware-workbench/artifacts/{artifact_id}/notify", {}
|
||||
)
|
||||
assert notify_status == 200
|
||||
assert notified["published_count"] == 3
|
||||
assert [frame["sequence"] for frame in frames] == [1, 2, 3]
|
||||
assert all(frame["firmware"]["release_id"] == release_id for frame in frames)
|
||||
|
||||
delete_request = urllib.request.Request(
|
||||
f"{self.base_url}/api/firmware-workbench/artifacts/{artifact_id}",
|
||||
|
||||
Reference in New Issue
Block a user