Files
trello-mcp/tests/test_get_attachment_tool.py
maxerton b4cabbf146 trello-tools: плагин и маркетплейс gp-tools для Claude Code
Сервер запускается через uv run --script, ключи запрашиваются
при установке плагина (userConfig) вместо .env.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 14:14:29 +00:00

79 lines
2.2 KiB
Python

import sys
from pathlib import Path
import pytest
from mcp.server.mcpserver import Image
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import server # noqa: E402
def _fake_attachment(monkeypatch, **fields):
attachment = {
"id": "a1",
"name": "f",
"kind": "file",
"mime": None,
"size": 0,
"date": None,
"url": "https://trello.com/1/x",
**fields,
}
async def fake_get_attachment(card_id, attachment_id):
return dict(attachment)
monkeypatch.setattr(server.trello, "get_attachment", fake_get_attachment)
@pytest.mark.asyncio
async def test_png_returned_as_image(monkeypatch):
_fake_attachment(monkeypatch, kind="image", mime="image/png", data=b"\x89PNG", path="/tmp/x.png")
meta, image = await server.trello_get_attachment("card1", "a1")
assert isinstance(image, Image)
assert "data" not in meta and meta["path"] == "/tmp/x.png"
@pytest.mark.asyncio
async def test_svg_only_path(monkeypatch):
_fake_attachment(monkeypatch, kind="image", mime="image/svg+xml", data=b"<svg/>", path="/tmp/x.svg")
result = await server.trello_get_attachment("card1", "a1")
assert isinstance(result, dict) and result["path"] == "/tmp/x.svg"
@pytest.mark.asyncio
async def test_small_text_file_inlined(monkeypatch):
_fake_attachment(monkeypatch, mime="text/plain", data="ошибка 500".encode(), path="/tmp/x.txt")
result = await server.trello_get_attachment("card1", "a1")
assert result["text"] == "ошибка 500"
@pytest.mark.asyncio
async def test_pdf_only_path(monkeypatch):
_fake_attachment(monkeypatch, mime="application/pdf", data=b"%PDF", path="/tmp/x.pdf")
result = await server.trello_get_attachment("card1", "a1")
assert "text" not in result and "data" not in result
@pytest.mark.asyncio
async def test_linked_card_fetched(monkeypatch):
_fake_attachment(monkeypatch, kind="card", url="https://trello.com/c/zzz/1-x")
async def fake_get_card(url):
return {"id": "linked", "url": url}
monkeypatch.setattr(server.trello, "get_card", fake_get_card)
result = await server.trello_get_attachment("card1", "a1")
assert result["card"] == {"id": "linked", "url": "https://trello.com/c/zzz/1-x"}