X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/16b6484c650eef161e64153f748643ca61553753..1f0796778754d8df0dfab9dd01302e26a397f064:/test/python/api/test_api_connection.py diff --git a/test/python/api/test_api_connection.py b/test/python/api/test_api_connection.py index 5609cb03..f62b0d9e 100644 --- a/test/python/api/test_api_connection.py +++ b/test/python/api/test_api_connection.py @@ -2,52 +2,41 @@ # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2023 by the Nominatim developer community. +# Copyright (C) 2024 by the Nominatim developer community. # For a full list of authors see the git log. """ Tests for enhanced connection class for API functions. """ from pathlib import Path import pytest -import pytest_asyncio import sqlalchemy as sa -from nominatim.api import NominatimAPIAsync - -@pytest_asyncio.fixture -async def apiobj(temp_db): - """ Create an asynchronous SQLAlchemy engine for the test DB. - """ - api = NominatimAPIAsync(Path('/invalid'), {}) - yield api - await api.close() - @pytest.mark.asyncio -async def test_run_scalar(apiobj, table_factory): +async def test_run_scalar(api, table_factory): table_factory('foo', definition='that TEXT', content=(('a', ),)) - async with apiobj.begin() as conn: + async with api.begin() as conn: assert await conn.scalar(sa.text('SELECT * FROM foo')) == 'a' @pytest.mark.asyncio -async def test_run_execute(apiobj, table_factory): +async def test_run_execute(api, table_factory): table_factory('foo', definition='that TEXT', content=(('a', ),)) - async with apiobj.begin() as conn: + async with api.begin() as conn: result = await conn.execute(sa.text('SELECT * FROM foo')) assert result.fetchone()[0] == 'a' @pytest.mark.asyncio -async def test_get_property_existing_cached(apiobj, table_factory): +async def test_get_property_existing_cached(api, table_factory): table_factory('nominatim_properties', definition='property TEXT, value TEXT', content=(('dbv', '96723'), )) - async with apiobj.begin() as conn: + async with api.begin() as conn: assert await conn.get_property('dbv') == '96723' await conn.execute(sa.text('TRUNCATE nominatim_properties')) @@ -56,12 +45,12 @@ async def test_get_property_existing_cached(apiobj, table_factory): @pytest.mark.asyncio -async def test_get_property_existing_uncached(apiobj, table_factory): +async def test_get_property_existing_uncached(api, table_factory): table_factory('nominatim_properties', definition='property TEXT, value TEXT', content=(('dbv', '96723'), )) - async with apiobj.begin() as conn: + async with api.begin() as conn: assert await conn.get_property('dbv') == '96723' await conn.execute(sa.text("UPDATE nominatim_properties SET value = '1'")) @@ -71,23 +60,23 @@ async def test_get_property_existing_uncached(apiobj, table_factory): @pytest.mark.asyncio @pytest.mark.parametrize('param', ['foo', 'DB:server_version']) -async def test_get_property_missing(apiobj, table_factory, param): +async def test_get_property_missing(api, table_factory, param): table_factory('nominatim_properties', definition='property TEXT, value TEXT') - async with apiobj.begin() as conn: + async with api.begin() as conn: with pytest.raises(ValueError): await conn.get_property(param) @pytest.mark.asyncio -async def test_get_db_property_existing(apiobj): - async with apiobj.begin() as conn: +async def test_get_db_property_existing(api): + async with api.begin() as conn: assert await conn.get_db_property('server_version') > 0 @pytest.mark.asyncio -async def test_get_db_property_existing(apiobj): - async with apiobj.begin() as conn: +async def test_get_db_property_existing(api): + async with api.begin() as conn: with pytest.raises(ValueError): await conn.get_db_property('dfkgjd.rijg')