66from collections .abc import AsyncIterable , Awaitable , Callable
77
88import pytest
9- from aiohttp .test_utils import TestServer
9+ from aiohttp .test_utils import TestClient , TestServer
1010from faker import Faker
1111from models_library .basic_types import IDStr
1212from models_library .products import ProductName
1515from pytest_simcore .helpers .monkeypatch_envs import setenvs_from_dict
1616from pytest_simcore .helpers .typing_env import EnvVarsDict
1717from pytest_simcore .helpers .webserver_login import UserInfoDict
18- from servicelib .rabbitmq import RabbitMQRPCClient
18+ from servicelib .rabbitmq import RabbitMQRPCClient , RPCNamespace
1919from servicelib .rabbitmq .rpc_interfaces .webserver .auth .api_keys import (
2020 create_api_key ,
2121 delete_api_key_by_key ,
2727from simcore_service_webserver .api_keys .errors import ApiKeyNotFoundError
2828from simcore_service_webserver .api_keys .models import ApiKey
2929from simcore_service_webserver .application_settings import ApplicationSettings
30+ from simcore_service_webserver .rabbitmq import get_rpc_namespace
3031
3132pytest_simcore_core_services_selection = [
3233 "rabbit" ,
@@ -104,15 +105,23 @@ async def rpc_client(
104105 return await rabbitmq_rpc_client ("client" )
105106
106107
108+ @pytest .fixture
109+ async def app_rpc_namespace (client : TestClient ) -> RPCNamespace :
110+ assert client .app is not None
111+ return get_rpc_namespace (client .app )
112+
113+
107114async def test_get_api_key (
108115 fake_user_api_keys : list [ApiKey ],
109116 rpc_client : RabbitMQRPCClient ,
110117 osparc_product_name : ProductName ,
111118 logged_user : UserInfoDict ,
119+ app_rpc_namespace : RPCNamespace ,
112120):
113121 for api_key in fake_user_api_keys :
114122 result = await get_api_key (
115123 rpc_client ,
124+ app_rpc_namespace ,
116125 user_id = logged_user ["id" ],
117126 product_name = osparc_product_name ,
118127 api_key_id = IDStr (api_key .id ),
@@ -121,17 +130,18 @@ async def test_get_api_key(
121130
122131
123132async def test_api_keys_workflow (
124- web_server : TestServer ,
125133 rpc_client : RabbitMQRPCClient ,
126134 osparc_product_name : ProductName ,
127135 logged_user : UserInfoDict ,
136+ app_rpc_namespace : RPCNamespace ,
128137 faker : Faker ,
129138):
130139 key_name = faker .pystr ()
131140
132141 # creating a key
133142 created_api_key = await create_api_key (
134143 rpc_client ,
144+ app_rpc_namespace ,
135145 user_id = logged_user ["id" ],
136146 product_name = osparc_product_name ,
137147 api_key = ApiKeyCreate (display_name = key_name , expiration = None ),
@@ -141,6 +151,7 @@ async def test_api_keys_workflow(
141151 # query the key is still present
142152 queried_api_key = await get_api_key (
143153 rpc_client ,
154+ app_rpc_namespace ,
144155 product_name = osparc_product_name ,
145156 user_id = logged_user ["id" ],
146157 api_key_id = created_api_key .id ,
@@ -155,6 +166,7 @@ async def test_api_keys_workflow(
155166 # remove the key
156167 await delete_api_key_by_key (
157168 rpc_client ,
169+ app_rpc_namespace ,
158170 user_id = logged_user ["id" ],
159171 product_name = osparc_product_name ,
160172 api_key = created_api_key .api_key ,
@@ -164,6 +176,7 @@ async def test_api_keys_workflow(
164176 # key no longer present
165177 await get_api_key (
166178 rpc_client ,
179+ app_rpc_namespace ,
167180 product_name = osparc_product_name ,
168181 user_id = logged_user ["id" ],
169182 api_key_id = created_api_key .id ,
0 commit comments