42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from openherbarium_mcp.gbif import GBIFClient
|
|
from openherbarium_mcp.http import BotanicalHTTPClient
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_gbif_match_wraps_identity_with_evidence() -> None:
|
|
async def handler(request: httpx.Request) -> httpx.Response:
|
|
if request.url.path == "/v1/species/match":
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"usageKey": 1,
|
|
"acceptedUsageKey": 2,
|
|
"scientificName": "Calathea warscewiczii (L.Mathieu ex Planch.) Planch. & Linden",
|
|
"canonicalName": "Calathea warscewiczii",
|
|
"species": "Goeppertia warscewiczii",
|
|
"family": "Marantaceae",
|
|
"genus": "Goeppertia",
|
|
"rank": "SPECIES",
|
|
"status": "SYNONYM",
|
|
"confidence": 98,
|
|
},
|
|
)
|
|
if request.url.path in {"/v1/species/2/vernacularNames", "/v1/species/2/synonyms"}:
|
|
return httpx.Response(200, json={"results": []})
|
|
raise AssertionError(f"unexpected request path: {request.url.path}")
|
|
|
|
transport = httpx.MockTransport(handler)
|
|
async with BotanicalHTTPClient(transport=transport) as http:
|
|
result = await GBIFClient(http).match_plant("Calathea warscewiczii")
|
|
|
|
assert result["usage_key"] == 2
|
|
assert result["accepted_scientific_name"]["value"] == "Goeppertia warscewiczii"
|
|
assert result["accepted_scientific_name"]["source"] == "GBIF Backbone Taxonomy"
|
|
assert result["family"]["value"] == "Marantaceae"
|
|
assert result["external_ids"]["value"]["gbif_accepted_usage_key"] == 2
|