Add read-only tools: loyalty points, standings, medals, titles, agents research, jump fatigue, notifications, chat channels — per character or aggregated. Closes #31. 90 tests, coverage 92%. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
"""Character profile/social tools (auth & ESI mocked)."""
|
|
|
|
import asyncio
|
|
|
|
import pytest
|
|
|
|
from conftest import route
|
|
from familiar import auth, profile
|
|
from familiar.server import mcp
|
|
|
|
CHARS = [
|
|
{"character_id": 99, "character_name": "Alpha", "scopes": []},
|
|
{"character_id": 100, "character_name": "Beta", "scopes": []},
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_auth(monkeypatch):
|
|
monkeypatch.setattr(auth, "list_characters", lambda: list(CHARS))
|
|
|
|
async def get_auth(cid, **kw):
|
|
return f"token-{cid}", cid
|
|
|
|
monkeypatch.setattr(auth, "get_auth", get_auth)
|
|
|
|
def resolve(identifier):
|
|
for c in CHARS:
|
|
if (
|
|
str(c["character_id"]) == str(identifier)
|
|
or (c["character_name"] or "").lower() == str(identifier).lower()
|
|
):
|
|
return c["character_id"]
|
|
raise auth.NotAuthenticated("no such character")
|
|
|
|
monkeypatch.setattr(auth, "resolve_character", resolve)
|
|
return CHARS
|
|
|
|
|
|
def test_loyalty_points_all(mock_esi, fake_auth):
|
|
lp = [{"corporation_id": 1000, "loyalty_points": 5000}]
|
|
mock_esi(lambda r: route(r, {"/loyalty/points/": lp}))
|
|
res = asyncio.run(profile.get_loyalty_points())
|
|
assert len(res["characters"]) == 2
|
|
assert res["characters"][0]["sample"][0]["loyalty_points"] == 5000
|
|
|
|
|
|
def test_standings_single(mock_esi, fake_auth):
|
|
st = [{"from_id": 500001, "standing": 5.0}]
|
|
mock_esi(lambda r: route(r, {"/standings/": st}))
|
|
res = asyncio.run(profile.get_standings(character="Alpha"))
|
|
assert res["characters"][0]["count"] == 1
|
|
|
|
|
|
def test_jump_fatigue(mock_esi, fake_auth):
|
|
data = {"last_jump_date": "2026-06-01T00:00:00Z", "jump_fatigue_expire_date": "2026-06-02"}
|
|
mock_esi(lambda r: route(r, {"/fatigue/": data}))
|
|
res = asyncio.run(profile.get_jump_fatigue(character=99))
|
|
assert res["characters"][0]["last_jump_date"] == "2026-06-01T00:00:00Z"
|
|
|
|
|
|
def test_notifications(mock_esi, fake_auth):
|
|
notes = [{"notification_id": 1, "type": "x"}, {"notification_id": 2, "type": "y"}]
|
|
mock_esi(lambda r: route(r, {"/notifications/": notes}))
|
|
res = asyncio.run(profile.get_notifications(character=99, limit=1))
|
|
assert res["characters"][0]["count"] == 2
|
|
assert len(res["characters"][0]["sample"]) == 1
|
|
|
|
|
|
def test_profile_tools_registered():
|
|
tools = {t.name for t in asyncio.run(mcp.list_tools())}
|
|
assert {
|
|
"get_loyalty_points",
|
|
"get_standings",
|
|
"get_medals",
|
|
"get_titles",
|
|
"get_agents_research",
|
|
"get_notifications",
|
|
"get_chat_channels",
|
|
"get_jump_fatigue",
|
|
} <= tools
|