Add read-only corp tools: members, member tracking, divisions, titles, medals, standings (corp-level, need corp roles), plus the character's own corp roles. Closes #32. 95 tests, coverage 91%. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""Corp organization tools (auth & ESI mocked)."""
|
|
|
|
import asyncio
|
|
|
|
import pytest
|
|
|
|
from conftest import route
|
|
from familiar import auth, corp
|
|
from familiar.server import mcp
|
|
|
|
CHARS = [{"character_id": 99, "character_name": "Alpha", "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)
|
|
monkeypatch.setattr(auth, "resolve_character", lambda i: 99)
|
|
return CHARS
|
|
|
|
|
|
def test_corp_members_resolves_corp(mock_esi, fake_auth):
|
|
fixtures = {"/members/": [1, 2, 3], "/characters/": {"corporation_id": 2000}}
|
|
mock_esi(lambda r: route(r, fixtures))
|
|
res = asyncio.run(corp.get_corp_members())
|
|
entry = res["characters"][0]
|
|
assert entry["corporation_id"] == 2000
|
|
assert entry["count"] == 3
|
|
|
|
|
|
def test_corp_divisions(mock_esi, fake_auth):
|
|
fixtures = {
|
|
"/divisions/": {"hangar": [{"division": 1, "name": "Ore"}], "wallet": []},
|
|
"/characters/": {"corporation_id": 2000},
|
|
}
|
|
mock_esi(lambda r: route(r, fixtures))
|
|
res = asyncio.run(corp.get_corp_divisions())
|
|
assert res["characters"][0]["hangar"][0]["name"] == "Ore"
|
|
|
|
|
|
def test_corp_medals_paginated(mock_esi, fake_auth):
|
|
fixtures = {"/medals/": [{"medal_id": 1}], "/characters/": {"corporation_id": 2000}}
|
|
mock_esi(lambda r: route(r, fixtures))
|
|
res = asyncio.run(corp.get_corp_medals())
|
|
assert res["characters"][0]["count"] == 1
|
|
|
|
|
|
def test_my_corp_roles(mock_esi, fake_auth):
|
|
mock_esi(lambda r: route(r, {"/roles/": {"roles": ["Director", "Accountant"]}}))
|
|
res = asyncio.run(corp.get_my_corp_roles())
|
|
assert "Director" in res["characters"][0]["roles"]
|
|
|
|
|
|
def test_corp_tools_registered():
|
|
tools = {t.name for t in asyncio.run(mcp.list_tools())}
|
|
assert {
|
|
"get_corp_members",
|
|
"get_corp_member_tracking",
|
|
"get_corp_divisions",
|
|
"get_corp_titles",
|
|
"get_corp_medals",
|
|
"get_corp_standings",
|
|
"get_my_corp_roles",
|
|
} <= tools
|