46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from openherbarium_mcp.http import BotanicalHTTPClient
|
|
from openherbarium_mcp.wikimedia import WikimediaClient
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_wikimedia_image_sources_include_license_author_and_url() -> None:
|
|
async def handler(request: httpx.Request) -> httpx.Response:
|
|
assert request.url.path == "/w/api.php"
|
|
return httpx.Response(
|
|
200,
|
|
json={
|
|
"query": {
|
|
"pages": {
|
|
"123": {
|
|
"pageid": 123,
|
|
"title": "File:Plant.jpg",
|
|
"imageinfo": [
|
|
{
|
|
"url": "https://upload.wikimedia.org/Plant.jpg",
|
|
"descriptionurl": "https://commons.wikimedia.org/wiki/File:Plant.jpg",
|
|
"user": "Example author",
|
|
"extmetadata": {
|
|
"LicenseShortName": {"value": "CC BY-SA 4.0"},
|
|
"Artist": {"value": "Example artist"},
|
|
},
|
|
}
|
|
],
|
|
}
|
|
}
|
|
}
|
|
},
|
|
)
|
|
|
|
transport = httpx.MockTransport(handler)
|
|
async with BotanicalHTTPClient(transport=transport) as http:
|
|
records = await WikimediaClient(http).image_sources("Goeppertia warscewiczii")
|
|
|
|
assert records[0]["image_url"]["value"].endswith("Plant.jpg")
|
|
assert records[0]["license"]["value"] == "CC BY-SA 4.0"
|
|
assert records[0]["author"]["value"] == "Example artist"
|