|
| 1 | +import re |
| 2 | + |
| 3 | +import pytest |
| 4 | +from aiohttp.test_utils import TestClient |
| 5 | +from aioresponses import aioresponses as AioResponsesMock |
| 6 | +from common_library.users_enums import UserRole |
| 7 | +from pytest_simcore.helpers.webserver_login import UserInfoDict |
| 8 | +from servicelib.aiohttp import status |
| 9 | +from simcore_service_webserver.catalog.catalog_service import ( |
| 10 | + get_services_for_user_in_product, |
| 11 | + is_catalog_service_responsive, |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.parametrize( |
| 16 | + "user_role", |
| 17 | + [UserRole.USER], |
| 18 | +) |
| 19 | +async def test_server_responsive( |
| 20 | + client: TestClient, logged_user: UserInfoDict, aioresponses_mocker: AioResponsesMock |
| 21 | +): |
| 22 | + aioresponses_mocker.get( |
| 23 | + "http://catalog:8000", |
| 24 | + status=status.HTTP_200_OK, |
| 25 | + ) |
| 26 | + |
| 27 | + assert client.app |
| 28 | + assert await is_catalog_service_responsive(app=client.app) == True |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.parametrize( |
| 32 | + "user_role", |
| 33 | + [UserRole.USER], |
| 34 | +) |
| 35 | +@pytest.mark.parametrize( |
| 36 | + "backend_status_code", [status.HTTP_200_OK, status.HTTP_404_NOT_FOUND] |
| 37 | +) |
| 38 | +async def test_get_services_for_user_in_product( |
| 39 | + client: TestClient, |
| 40 | + logged_user: UserInfoDict, |
| 41 | + aioresponses_mocker: AioResponsesMock, |
| 42 | + backend_status_code: int, |
| 43 | +): |
| 44 | + url_pattern = re.compile(r"http://catalog:8000/.*") |
| 45 | + aioresponses_mocker.get( |
| 46 | + url_pattern, |
| 47 | + status=backend_status_code, |
| 48 | + ) |
| 49 | + assert client.app |
| 50 | + _ = await get_services_for_user_in_product( |
| 51 | + app=client.app, |
| 52 | + user_id=logged_user["id"], |
| 53 | + product_name="osparc", |
| 54 | + only_key_versions=False, |
| 55 | + ) |
0 commit comments