import httpx import respx from helpers import load_fixture from serp import query_arxiv ARXIV_XML = load_fixture("arxiv_response.xml") async def test_query_arxiv_parses_the_atom_feed(): with respx.mock: respx.get("https://export.arxiv.org/api/query").mock( return_value=httpx.Response(200, text=ARXIV_XML, headers={"content-type": "application/atom+xml"}) ) async with httpx.AsyncClient() as client: results = await query_arxiv(client, "widgets", 2) assert results == [ { "title": "A Study of Widgets", "href": "http://arxiv.org/pdf/2401.00001v1", "body": "This paper studies widgets in depth.", "id": "http://arxiv.org/abs/2401.00001v1", }, { "title": "Gadgets and Their Applications", "href": "http://arxiv.org/pdf/2401.00002v1", "body": "An overview of gadgets.", "id": "http://arxiv.org/abs/2401.00002v1", }, ]