File tree Expand file tree Collapse file tree 2 files changed +7
-29
lines changed
src/simcore_service_webserver/db Expand file tree Collapse file tree 2 files changed +7
-29
lines changed Original file line number Diff line number Diff line change 88from servicelib .aiohttp .application_keys import APP_AIOPG_ENGINE_KEY
99from servicelib .aiohttp .application_setup import ModuleCategory , app_module_setup
1010
11- from . import _aiopg
11+ from . import _aiopg , _asyncpg
1212
1313_logger = logging .getLogger (__name__ )
1414
2020is_service_enabled = _aiopg .is_service_enabled
2121
2222
23+ # asyncpg helpers
24+ get_asyncpg_engine = _asyncpg .get_async_engine
25+
26+
2327@app_module_setup (
2428 "simcore_service_webserver.db" ,
2529 ModuleCategory .ADDON ,
@@ -34,3 +38,4 @@ def setup_db(app: web.Application):
3438
3539 # init engines
3640 app .cleanup_ctx .append (_aiopg .postgres_cleanup_ctx )
41+ app .cleanup_ctx .append (_asyncpg .postgres_cleanup_ctx )
Original file line number Diff line number Diff line change 77
88import aiopg .sa
99import asyncpg
10- import pytest
1110import sqlalchemy as sa
1211import yaml
13- from aiohttp import web
1412from aiohttp .test_utils import TestServer
15- from pytest_mock import MockFixture , MockType
1613from simcore_service_webserver .application_settings import (
1714 ApplicationSettings ,
1815 get_application_settings ,
2118from simcore_service_webserver .db .plugin import (
2219 is_service_enabled ,
2320 is_service_responsive ,
24- setup_db ,
2521)
2622from simcore_service_webserver .login .storage import AsyncpgStorage , get_plugin_storage
2723from sqlalchemy .ext .asyncio import AsyncEngine
2824
2925
30- @pytest .fixture
31- def mock_asyncpg_in_setup_db (mocker : MockFixture ) -> MockType :
32-
33- original_setup = setup_db
34-
35- mock_setup_db = mocker .patch (
36- "simcore_service_webserver.application.setup_db" , autospec = True
37- )
38-
39- def _wrapper_setup_db (app : web .Application ):
40- original_setup (app )
41-
42- # NEW engine !
43- app .cleanup_ctx .append (_asyncpg .postgres_cleanup_ctx )
44-
45- mock_setup_db .side_effect = _wrapper_setup_db
46- return mock_setup_db
47-
48-
49- async def test_all_pg_engines_in_app (
50- mock_asyncpg_in_setup_db : MockType , web_server : TestServer
51- ):
52- assert mock_asyncpg_in_setup_db .called
53-
26+ async def test_all_pg_engines_in_app (web_server : TestServer ):
5427 app = web_server .app
5528 assert app
5629
You can’t perform that action at this time.
0 commit comments