mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-14 01:47:57 +00:00
Merge pull request #3945 from lonvia/fix-starlette-tests
Update Starlette tests to using their TestClient
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of Nominatim. (https://nominatim.org)
|
# This file is part of Nominatim. (https://nominatim.org)
|
||||||
#
|
#
|
||||||
# Copyright (C) 2025 by the Nominatim developer community.
|
# Copyright (C) 2026 by the Nominatim developer community.
|
||||||
# For a full list of authors see the git log.
|
# For a full list of authors see the git log.
|
||||||
"""
|
"""
|
||||||
Various helper classes for running Nominatim commands.
|
Various helper classes for running Nominatim commands.
|
||||||
@@ -54,15 +54,14 @@ class APIRunner:
|
|||||||
def create_engine_starlette(self, environ):
|
def create_engine_starlette(self, environ):
|
||||||
import nominatim_api.server.starlette.server
|
import nominatim_api.server.starlette.server
|
||||||
from asgi_lifespan import LifespanManager
|
from asgi_lifespan import LifespanManager
|
||||||
import httpx
|
from starlette.testclient import TestClient
|
||||||
|
|
||||||
async def _request(endpoint, params, http_headers):
|
async def _request(endpoint, params, http_headers):
|
||||||
app = nominatim_api.server.starlette.server.get_application(None, environ)
|
app = nominatim_api.server.starlette.server.get_application(None, environ)
|
||||||
|
|
||||||
async with LifespanManager(app):
|
async with LifespanManager(app):
|
||||||
async with httpx.AsyncClient(app=app, base_url="http://nominatim.test") as client:
|
client = TestClient(app, base_url="http://nominatim.test")
|
||||||
response = await client.get("/" + endpoint, params=params,
|
response = client.get("/" + endpoint, params=params, headers=http_headers)
|
||||||
headers=http_headers)
|
|
||||||
|
|
||||||
return APIResponse(endpoint, response.status_code,
|
return APIResponse(endpoint, response.status_code,
|
||||||
response.text, response.headers)
|
response.text, response.headers)
|
||||||
|
|||||||
Reference in New Issue
Block a user