|
10 | 10 |
|
11 | 11 | import pytest |
12 | 12 | from aiohttp.test_utils import TestClient |
13 | | -from models_library.api_schemas_webserver.product import GetProduct |
| 13 | +from models_library.api_schemas_webserver.product import ProductGet |
14 | 14 | from models_library.products import ProductName |
15 | 15 | from pytest_simcore.helpers.assert_checks import assert_status |
16 | 16 | from pytest_simcore.helpers.webserver_login import UserInfoDict |
17 | 17 | from servicelib.aiohttp import status |
18 | 18 | from servicelib.rest_constants import X_PRODUCT_NAME_HEADER |
| 19 | +from servicelib.status_codes_utils import is_2xx_success |
19 | 20 | from simcore_postgres_database.constants import QUANTIZE_EXP_ARG |
20 | 21 | from simcore_service_webserver.db.models import UserRole |
21 | 22 | from simcore_service_webserver.groups.api import auto_add_user_to_product_group |
@@ -99,17 +100,62 @@ async def test_get_product( |
99 | 100 | response = await client.get("/v0/products/current", headers=current_project_headers) |
100 | 101 | data, error = await assert_status(response, status.HTTP_200_OK) |
101 | 102 |
|
102 | | - got_product = GetProduct(**data) |
| 103 | + got_product = ProductGet(**data) |
103 | 104 | assert got_product.name == product_name |
104 | 105 | assert got_product.credits_per_usd == expected_credits_per_usd |
105 | 106 | assert not error |
106 | 107 |
|
107 | 108 | response = await client.get(f"/v0/products/{product_name}") |
108 | 109 | data, error = await assert_status(response, status.HTTP_200_OK) |
109 | | - assert got_product == GetProduct(**data) |
| 110 | + assert got_product == ProductGet(**data) |
110 | 111 | assert not error |
111 | 112 |
|
112 | | - response = await client.get("/v0/product/invalid") |
| 113 | + response = await client.get("/v0/products/invalid") |
113 | 114 | data, error = await assert_status(response, status.HTTP_404_NOT_FOUND) |
114 | 115 | assert not data |
115 | 116 | assert error |
| 117 | + |
| 118 | + |
| 119 | +@pytest.mark.parametrize( |
| 120 | + "user_role, expected_status_code", |
| 121 | + [ |
| 122 | + (UserRole.ANONYMOUS, status.HTTP_401_UNAUTHORIZED), |
| 123 | + (UserRole.GUEST, status.HTTP_403_FORBIDDEN), |
| 124 | + (UserRole.USER, status.HTTP_200_OK), |
| 125 | + (UserRole.TESTER, status.HTTP_200_OK), |
| 126 | + (UserRole.PRODUCT_OWNER, status.HTTP_200_OK), |
| 127 | + (UserRole.ADMIN, status.HTTP_200_OK), |
| 128 | + ], |
| 129 | +) |
| 130 | +async def test_get_current_product_ui( |
| 131 | + product_name: ProductName, |
| 132 | + logged_user: UserInfoDict, |
| 133 | + client: TestClient, |
| 134 | + user_role: UserRole, |
| 135 | + expected_status_code: int, |
| 136 | +): |
| 137 | + assert logged_user["role"] == f"{user_role}" |
| 138 | + |
| 139 | + # give access to user to this product |
| 140 | + assert client.app |
| 141 | + await auto_add_user_to_product_group( |
| 142 | + client.app, user_id=logged_user["id"], product_name=product_name |
| 143 | + ) |
| 144 | + |
| 145 | + current_project_headers = {X_PRODUCT_NAME_HEADER: product_name} |
| 146 | + response = await client.get( |
| 147 | + "/v0/products/current/ui", headers=current_project_headers |
| 148 | + ) |
| 149 | + |
| 150 | + data, error = await assert_status(response, expected_status_code) |
| 151 | + |
| 152 | + if is_2xx_success(expected_status_code): |
| 153 | + # ui is something owned and fully controlled by the front-end |
| 154 | + # Will be something like the data stored in this file |
| 155 | + # https://github.com/itisfoundation/osparc-simcore/blob/1dcd369717959348099cc6241822a1f0aff0382c/services/static-webserver/client/source/resource/osparc/new_studies.json |
| 156 | + assert not error |
| 157 | + assert data is not None |
| 158 | + assert isinstance(data, dict) |
| 159 | + else: |
| 160 | + assert error |
| 161 | + assert not data |
0 commit comments