MpakoImageAIbot/tests/test_comfy.py

72 lines
2.0 KiB
Python

from __future__ import annotations
import httpx
from comfy_client import ComfyClient, _format_api_error
def test_format_node_errors() -> None:
message = _format_api_error(
{
"error": {"message": "Prompt outputs failed validation"},
"node_errors": {
"20": {
"errors": [
{"message": "Required input is missing", "details": "image"}
]
}
},
}
)
assert "Prompt outputs failed validation" in message
assert "узел 20" in message
assert "image" in message
def test_find_output_image() -> None:
entry = {
"outputs": {
"9": {
"images": [
{"filename": "result.png", "subfolder": "", "type": "output"}
]
}
}
}
image = ComfyClient.find_output_image(None, entry) # type: ignore[arg-type]
assert image is not None
assert image["filename"] == "result.png"
def test_find_output_image_empty() -> None:
assert ComfyClient.find_output_image(None, {}) is None # type: ignore[arg-type]
def test_find_output_text() -> None:
entry = {"outputs": {"3": {"text": ["A red apple"]}}}
text = ComfyClient.find_output_text(None, entry) # type: ignore[arg-type]
assert text == "A red apple"
async def test_delete_history_posts_prompt_id() -> None:
seen: dict[str, object] = {}
def handler(request: httpx.Request) -> httpx.Response:
seen["path"] = request.url.path
seen["json"] = request.content.decode()
return httpx.Response(200)
client = ComfyClient("http://comfy", "ws://comfy")
await client.close()
client._client = httpx.AsyncClient( # type: ignore[attr-defined]
transport=httpx.MockTransport(handler),
base_url="http://comfy",
)
try:
await client.delete_history("prompt-1")
finally:
await client.close()
assert seen["path"] == "/history"
assert '"prompt-1"' in str(seen["json"])