Skip to content

Commit f453521

Browse files
committed
improved test
1 parent 818f25b commit f453521

File tree

1 file changed

+34
-7
lines changed
  • services/web/server/tests/unit/with_dbs/01

1 file changed

+34
-7
lines changed

services/web/server/tests/unit/with_dbs/01/test_db.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from pathlib import Path
77

88
import aiopg.sa
9+
import asyncpg
10+
import sqlalchemy as sa
911
import yaml
1012
from aiohttp.test_utils import TestServer
1113
from simcore_service_webserver.application_settings import (
@@ -18,26 +20,51 @@
1820
is_service_enabled,
1921
is_service_responsive,
2022
)
23+
from simcore_service_webserver.login.storage import AsyncpgStorage, get_plugin_storage
2124
from sqlalchemy.ext.asyncio import AsyncEngine
2225

2326

24-
def test_engines_in_app_state(web_server: TestServer):
27+
async def test_all_pg_engines_in_app(web_server: TestServer):
2528
app = web_server.app
2629
assert app
27-
settings: ApplicationSettings = get_application_settings(app)
2830

29-
# same as host
31+
settings: ApplicationSettings = get_application_settings(app)
3032
assert settings.WEBSERVER_DB
3133
assert settings.WEBSERVER_DB.POSTGRES_CLIENT_NAME
3234

33-
engine: AsyncEngine = get_asyncpg_engine(app)
34-
assert engine
35-
assert isinstance(engine, AsyncEngine)
36-
35+
# (1) aiopg engine (deprecated)
3736
aiopg_engine = get_aiopg_engine(app)
3837
assert aiopg_engine
3938
assert isinstance(aiopg_engine, aiopg.sa.Engine)
4039

40+
# (2) asyncpg engine via sqlalchemy.ext.asyncio (new)
41+
asyncpg_engine: AsyncEngine = get_asyncpg_engine(app)
42+
assert asyncpg_engine
43+
assert isinstance(asyncpg_engine, AsyncEngine)
44+
45+
# (3) low-level asyncpg Pool (deprecated)
46+
# Will be replaced by (2)
47+
login_storage: AsyncpgStorage = get_plugin_storage(app)
48+
assert login_storage.pool
49+
assert isinstance(login_storage.pool, asyncpg.Pool)
50+
51+
# they ALL point to the SAME database
52+
assert aiopg_engine.dsn
53+
assert asyncpg_engine.url
54+
55+
query = sa.text('SELECT "version_num" FROM "alembic_version"')
56+
async with login_storage.pool.acquire() as conn:
57+
result_pool = await conn.fetchval(str(query))
58+
59+
async with asyncpg_engine.connect() as conn:
60+
result_asyncpg = (await conn.execute(query)).scalar_one_or_none()
61+
62+
async with aiopg_engine.acquire() as conn:
63+
result_aiopg = await (await conn.execute(query)).scalar()
64+
65+
assert result_pool == result_asyncpg
66+
assert result_pool == result_aiopg
67+
4168

4269
def test_uses_same_postgres_version(
4370
docker_compose_file: Path, osparc_simcore_root_dir: Path

0 commit comments

Comments
 (0)