Skip to content

Commit fac1547

Browse files
committed
refactor: update RPC client usage and service name in tests
1 parent 4e118bb commit fac1547

File tree

4 files changed

+98
-91
lines changed

4 files changed

+98
-91
lines changed

services/web/server/tests/unit/with_dbs/02/test_projects_rpc.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# pylint: disable=too-many-arguments
55

66

7-
from collections.abc import AsyncIterator, Awaitable, Callable
7+
from collections.abc import AsyncIterator
88
from uuid import UUID
99

1010
import pytest
@@ -23,7 +23,6 @@
2323
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
2424
from pytest_simcore.helpers.typing_env import EnvVarsDict
2525
from pytest_simcore.helpers.webserver_users import NewUser, UserInfoDict
26-
from servicelib.rabbitmq import RabbitMQRPCClient
2726
from servicelib.rabbitmq.rpc_interfaces.webserver.errors import (
2827
ProjectForbiddenRpcError,
2928
ProjectNotFoundRpcError,
@@ -32,7 +31,6 @@
3231
from settings_library.rabbit import RabbitSettings
3332
from simcore_service_webserver.application_settings import (
3433
ApplicationSettings,
35-
get_application_settings,
3634
)
3735
from simcore_service_webserver.projects.models import ProjectDict
3836

@@ -44,7 +42,7 @@
4442
@pytest.fixture(scope="session")
4543
def service_name() -> str:
4644
# Overrides service_name fixture needed in docker_compose_service_environment_dict fixture
47-
return "webserver"
45+
return "wb-api-server"
4846

4947

5048
@pytest.fixture
@@ -79,22 +77,6 @@ def app_environment(
7977
return new_envs
8078

8179

82-
@pytest.fixture
83-
async def webserver_rpc_client(
84-
rabbitmq_rpc_client: Callable[[str], Awaitable[RabbitMQRPCClient]],
85-
client: TestClient, # app started
86-
) -> WebServerRpcClient:
87-
88-
rpc_client = await rabbitmq_rpc_client("webserver-rpc-client")
89-
90-
app = client.app
91-
assert app
92-
93-
settings = get_application_settings(app) # nosec
94-
assert settings.WEBSERVER_RPC_NAMESPACE
95-
return WebServerRpcClient(rpc_client, settings.WEBSERVER_RPC_NAMESPACE)
96-
97-
9880
async def test_rpc_client_mark_project_as_job(
9981
product_name: ProductName,
10082
webserver_rpc_client: WebServerRpcClient,

services/web/server/tests/unit/with_dbs/04/functions/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,23 @@
4343
from sqlalchemy.ext.asyncio import AsyncEngine
4444

4545

46+
@pytest.fixture(scope="session")
47+
def service_name() -> str:
48+
# Overrides service_name fixture needed in docker_compose_service_environment_dict fixture
49+
return "wb-api-server"
50+
51+
4652
@pytest.fixture
4753
def app_environment(
4854
rabbit_service: RabbitSettings,
4955
app_environment: EnvVarsDict,
56+
docker_compose_service_environment_dict: EnvVarsDict,
5057
monkeypatch: pytest.MonkeyPatch,
5158
) -> EnvVarsDict:
5259
new_envs = setenvs_from_dict(
5360
monkeypatch,
5461
{
62+
**docker_compose_service_environment_dict,
5563
**app_environment,
5664
"RABBIT_HOST": rabbit_service.RABBIT_HOST,
5765
"RABBIT_PORT": f"{rabbit_service.RABBIT_PORT}",

services/web/server/tests/unit/with_dbs/04/functions/test_function_job_collections_controller_rpc.py

Lines changed: 60 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
)
2727
from models_library.products import ProductName
2828
from pytest_simcore.helpers.webserver_users import UserInfoDict
29-
from servicelib.rabbitmq import RabbitMQRPCClient
30-
from servicelib.rabbitmq.rpc_interfaces.webserver.functions import (
31-
functions_rpc_interface as functions_rpc,
32-
)
29+
from servicelib.rabbitmq.rpc_interfaces.webserver.v1 import WebServerRpcClient
3330

3431
pytest_simcore_core_services_selection = ["rabbit"]
3532

@@ -42,15 +39,14 @@ async def test_function_job_collection(
4239
client: TestClient,
4340
add_user_function_api_access_rights: None,
4441
mock_function_factory: Callable[[FunctionClass], Function],
45-
rpc_client: RabbitMQRPCClient,
42+
webserver_rpc_client: WebServerRpcClient,
4643
logged_user: UserInfoDict,
4744
other_logged_user: UserInfoDict,
4845
user_without_function_api_access_rights: UserInfoDict,
4946
osparc_product_name: ProductName,
5047
):
5148
# Register the function first
52-
registered_function = await functions_rpc.register_function(
53-
rabbitmq_rpc_client=rpc_client,
49+
registered_function = await webserver_rpc_client.functions.register_function(
5450
function=mock_function_factory(FunctionClass.PROJECT),
5551
user_id=logged_user["id"],
5652
product_name=osparc_product_name,
@@ -79,8 +75,7 @@ async def test_function_job_collection(
7975
job_creation_task_id=None,
8076
)
8177
# Register the function job
82-
registered_job = await functions_rpc.register_function_job(
83-
rabbitmq_rpc_client=rpc_client,
78+
registered_job = await webserver_rpc_client.functions.register_function_job(
8479
function_job=registered_function_job,
8580
user_id=logged_user["id"],
8681
product_name=osparc_product_name,
@@ -95,73 +90,69 @@ async def test_function_job_collection(
9590
)
9691

9792
# Register the function job collection
98-
registered_collection = await functions_rpc.register_function_job_collection(
99-
rabbitmq_rpc_client=rpc_client,
100-
function_job_collection=function_job_collection,
101-
user_id=logged_user["id"],
102-
product_name=osparc_product_name,
93+
registered_collection = (
94+
await webserver_rpc_client.functions.register_function_job_collection(
95+
function_job_collection=function_job_collection,
96+
user_id=logged_user["id"],
97+
product_name=osparc_product_name,
98+
)
10399
)
104100
assert registered_collection.uid is not None
105101
assert registered_collection.created_at - datetime.datetime.now(
106102
datetime.UTC
107103
) < datetime.timedelta(seconds=60)
108104

109105
# Get the function job collection
110-
retrieved_collection = await functions_rpc.get_function_job_collection(
111-
rabbitmq_rpc_client=rpc_client,
112-
function_job_collection_id=registered_collection.uid,
113-
user_id=logged_user["id"],
114-
product_name=osparc_product_name,
106+
retrieved_collection = (
107+
await webserver_rpc_client.functions.get_function_job_collection(
108+
function_job_collection_id=registered_collection.uid,
109+
user_id=logged_user["id"],
110+
product_name=osparc_product_name,
111+
)
115112
)
116113
assert retrieved_collection.uid == registered_collection.uid
117114
assert registered_collection.job_ids == function_job_ids
118115

119116
# Test denied access for another user
120117
with pytest.raises(FunctionJobCollectionReadAccessDeniedError):
121-
await functions_rpc.get_function_job_collection(
122-
rabbitmq_rpc_client=rpc_client,
118+
await webserver_rpc_client.functions.get_function_job_collection(
123119
function_job_collection_id=registered_collection.uid,
124120
user_id=other_logged_user["id"],
125121
product_name=osparc_product_name,
126122
)
127123

128124
# Test denied access for another user
129125
with pytest.raises(FunctionJobCollectionsReadApiAccessDeniedError):
130-
await functions_rpc.get_function_job_collection(
131-
rabbitmq_rpc_client=rpc_client,
126+
await webserver_rpc_client.functions.get_function_job_collection(
132127
function_job_collection_id=registered_collection.uid,
133128
user_id=user_without_function_api_access_rights["id"],
134129
product_name=osparc_product_name,
135130
)
136131

137132
# Test denied access for another product
138133
with pytest.raises(FunctionJobCollectionsReadApiAccessDeniedError):
139-
await functions_rpc.get_function_job_collection(
140-
rabbitmq_rpc_client=rpc_client,
134+
await webserver_rpc_client.functions.get_function_job_collection(
141135
function_job_collection_id=registered_collection.uid,
142136
user_id=other_logged_user["id"],
143137
product_name="this_is_not_osparc",
144138
)
145139

146140
# Attempt to delete the function job collection by another user
147141
with pytest.raises(FunctionJobCollectionWriteAccessDeniedError):
148-
await functions_rpc.delete_function_job_collection(
149-
rabbitmq_rpc_client=rpc_client,
142+
await webserver_rpc_client.functions.delete_function_job_collection(
150143
function_job_collection_id=registered_collection.uid,
151144
user_id=other_logged_user["id"],
152145
product_name=osparc_product_name,
153146
)
154147

155-
await functions_rpc.delete_function_job_collection(
156-
rabbitmq_rpc_client=rpc_client,
148+
await webserver_rpc_client.functions.delete_function_job_collection(
157149
function_job_collection_id=registered_collection.uid,
158150
user_id=logged_user["id"],
159151
product_name=osparc_product_name,
160152
)
161153
# Attempt to retrieve the deleted collection
162154
with pytest.raises(FunctionJobIDNotFoundError):
163-
await functions_rpc.get_function_job(
164-
rabbitmq_rpc_client=rpc_client,
155+
await webserver_rpc_client.functions.get_function_job(
165156
function_job_id=registered_collection.uid,
166157
user_id=logged_user["id"],
167158
product_name=osparc_product_name,
@@ -176,19 +167,20 @@ async def test_list_function_job_collections(
176167
client: TestClient,
177168
add_user_function_api_access_rights: None,
178169
mock_function_factory: Callable[[FunctionClass], Function],
179-
rpc_client: RabbitMQRPCClient,
170+
webserver_rpc_client: WebServerRpcClient,
180171
clean_functions: None,
181172
clean_function_job_collections: None,
182173
logged_user: UserInfoDict,
183174
osparc_product_name: ProductName,
184175
):
185176
# List function job collections when none are registered
186-
collections, page_meta = await functions_rpc.list_function_job_collections(
187-
rabbitmq_rpc_client=rpc_client,
188-
pagination_limit=10,
189-
pagination_offset=0,
190-
user_id=logged_user["id"],
191-
product_name=osparc_product_name,
177+
collections, page_meta = (
178+
await webserver_rpc_client.functions.list_function_job_collections(
179+
pagination_limit=10,
180+
pagination_offset=0,
181+
user_id=logged_user["id"],
182+
product_name=osparc_product_name,
183+
)
192184
)
193185

194186
# Assert the list is empty
@@ -198,8 +190,7 @@ async def test_list_function_job_collections(
198190
assert len(collections) == 0
199191

200192
# Register the function first
201-
registered_function = await functions_rpc.register_function(
202-
rabbitmq_rpc_client=rpc_client,
193+
registered_function = await webserver_rpc_client.functions.register_function(
203194
function=mock_function_factory(FunctionClass.PROJECT),
204195
user_id=logged_user["id"],
205196
product_name=osparc_product_name,
@@ -219,8 +210,7 @@ async def test_list_function_job_collections(
219210
job_creation_task_id=None,
220211
)
221212
# Register the function job
222-
registered_job = await functions_rpc.register_function_job(
223-
rabbitmq_rpc_client=rpc_client,
213+
registered_job = await webserver_rpc_client.functions.register_function_job(
224214
function_job=registered_function_job,
225215
user_id=logged_user["id"],
226216
product_name=osparc_product_name,
@@ -236,8 +226,7 @@ async def test_list_function_job_collections(
236226

237227
# Register the function job collection
238228
registered_collections = [
239-
await functions_rpc.register_function_job_collection(
240-
rabbitmq_rpc_client=rpc_client,
229+
await webserver_rpc_client.functions.register_function_job_collection(
241230
function_job_collection=function_job_collection,
242231
user_id=logged_user["id"],
243232
product_name=osparc_product_name,
@@ -250,12 +239,13 @@ async def test_list_function_job_collections(
250239
)
251240

252241
# List function job collections
253-
collections, page_params = await functions_rpc.list_function_job_collections(
254-
rabbitmq_rpc_client=rpc_client,
255-
pagination_limit=2,
256-
pagination_offset=1,
257-
user_id=logged_user["id"],
258-
product_name=osparc_product_name,
242+
collections, page_params = (
243+
await webserver_rpc_client.functions.list_function_job_collections(
244+
pagination_limit=2,
245+
pagination_offset=1,
246+
user_id=logged_user["id"],
247+
product_name=osparc_product_name,
248+
)
259249
)
260250

261251
# Assert the list contains the registered collection
@@ -278,22 +268,20 @@ async def test_list_function_job_collections(
278268
async def test_list_function_job_collections_filtered_function_id(
279269
client: TestClient,
280270
add_user_function_api_access_rights: None,
281-
rpc_client: RabbitMQRPCClient,
271+
webserver_rpc_client: WebServerRpcClient,
282272
mock_function_factory: Callable[[FunctionClass], Function],
283273
clean_functions: None,
284274
clean_function_job_collections: None,
285275
logged_user: UserInfoDict,
286276
osparc_product_name: ProductName,
287277
):
288278
# Register the function first
289-
registered_function = await functions_rpc.register_function(
290-
rabbitmq_rpc_client=rpc_client,
279+
registered_function = await webserver_rpc_client.functions.register_function(
291280
function=mock_function_factory(FunctionClass.PROJECT),
292281
user_id=logged_user["id"],
293282
product_name=osparc_product_name,
294283
)
295-
other_registered_function = await functions_rpc.register_function(
296-
rabbitmq_rpc_client=rpc_client,
284+
other_registered_function = await webserver_rpc_client.functions.register_function(
297285
function=mock_function_factory(FunctionClass.PROJECT),
298286
user_id=logged_user["id"],
299287
product_name=osparc_product_name,
@@ -318,8 +306,7 @@ async def test_list_function_job_collections_filtered_function_id(
318306
job_creation_task_id=None,
319307
)
320308
# Register the function job
321-
registered_job = await functions_rpc.register_function_job(
322-
rabbitmq_rpc_client=rpc_client,
309+
registered_job = await webserver_rpc_client.functions.register_function_job(
323310
function_job=registered_function_job,
324311
user_id=logged_user["id"],
325312
product_name=osparc_product_name,
@@ -334,24 +321,26 @@ async def test_list_function_job_collections_filtered_function_id(
334321
)
335322

336323
# Register the function job collection
337-
registered_collection = await functions_rpc.register_function_job_collection(
338-
rabbitmq_rpc_client=rpc_client,
339-
function_job_collection=function_job_collection,
340-
user_id=logged_user["id"],
341-
product_name=osparc_product_name,
324+
registered_collection = (
325+
await webserver_rpc_client.functions.register_function_job_collection(
326+
function_job_collection=function_job_collection,
327+
user_id=logged_user["id"],
328+
product_name=osparc_product_name,
329+
)
342330
)
343331
registered_collections.append(registered_collection)
344332

345333
# List function job collections with a specific function ID
346-
collections, page_meta = await functions_rpc.list_function_job_collections(
347-
rabbitmq_rpc_client=rpc_client,
348-
pagination_limit=10,
349-
pagination_offset=1,
350-
filters=FunctionJobCollectionsListFilters(
351-
has_function_id=FunctionIDString(registered_function.uid)
352-
),
353-
user_id=logged_user["id"],
354-
product_name=osparc_product_name,
334+
collections, page_meta = (
335+
await webserver_rpc_client.functions.list_function_job_collections(
336+
pagination_limit=10,
337+
pagination_offset=1,
338+
filters=FunctionJobCollectionsListFilters(
339+
has_function_id=FunctionIDString(registered_function.uid)
340+
),
341+
user_id=logged_user["id"],
342+
product_name=osparc_product_name,
343+
)
355344
)
356345

357346
# Assert the list contains the registered collection

0 commit comments

Comments
 (0)