|
15 | 15 | from models_library.api_schemas_webserver.licensed_items import ( |
16 | 16 | LicensedItemGetPage as _LicensedItemGetPage, |
17 | 17 | ) |
| 18 | +from models_library.api_schemas_webserver.licensed_items_checkouts import ( |
| 19 | + LicensedItemCheckoutRpcGet, |
| 20 | +) |
| 21 | +from models_library.licensed_items import LicensedItemID |
| 22 | +from models_library.services_types import ServiceRunID |
18 | 23 | from models_library.users import UserID |
19 | 24 | from models_library.wallets import WalletID |
20 | 25 | from pydantic import TypeAdapter |
|
26 | 31 | get_wb_api_rpc_client, |
27 | 32 | ) |
28 | 33 | from simcore_service_api_server.models.pagination import Page |
| 34 | +from simcore_service_api_server.models.schemas.licensed_items import ( |
| 35 | + LicensedItemCheckoutData, |
| 36 | +) |
29 | 37 | from simcore_service_api_server.models.schemas.model_adapter import LicensedItemGet |
30 | 38 | from simcore_service_api_server.services_rpc.wb_api_server import WbApiRpcClient |
31 | 39 |
|
@@ -145,3 +153,55 @@ async def side_effect( |
145 | 153 | f"{API_VTAG}/wallets/{_wallet_id}/licensed-items", auth=auth |
146 | 154 | ) |
147 | 155 | assert resp.status_code == expected_api_server_status_code |
| 156 | + |
| 157 | + |
| 158 | +@pytest.mark.parametrize( |
| 159 | + "exception_to_raise,expected_api_server_status_code", |
| 160 | + [ |
| 161 | + (None, status.HTTP_200_OK), |
| 162 | + ], |
| 163 | +) |
| 164 | +async def test_get_licensed_items_checkout( |
| 165 | + mock_wb_api_server_rcp: MockerFixture, |
| 166 | + client: AsyncClient, |
| 167 | + auth: BasicAuth, |
| 168 | + exception_to_raise: Exception | None, |
| 169 | + expected_api_server_status_code: int, |
| 170 | + faker: Faker, |
| 171 | +): |
| 172 | + _wallet_id = faker.pyint(min_value=1) |
| 173 | + _licensed_item_id = faker.uuid4() |
| 174 | + |
| 175 | + async def side_effect( |
| 176 | + rabbitmq_rpc_client: RabbitMQRPCClient, |
| 177 | + product_name: str, |
| 178 | + user_id: UserID, |
| 179 | + wallet_id: WalletID, |
| 180 | + licensed_item_id: LicensedItemID, |
| 181 | + num_of_seats: int, |
| 182 | + service_run_id: ServiceRunID, |
| 183 | + ) -> LicensedItemCheckoutRpcGet: |
| 184 | + if exception_to_raise is not None: |
| 185 | + raise exception_to_raise |
| 186 | + extra = LicensedItemCheckoutRpcGet.model_config.get("json_schema_extra") |
| 187 | + assert isinstance(extra, dict) |
| 188 | + examples = extra.get("examples") |
| 189 | + assert isinstance(examples, list) |
| 190 | + assert len(examples) > 0 |
| 191 | + example = examples[0] |
| 192 | + assert isinstance(example, dict) |
| 193 | + return LicensedItemCheckoutRpcGet.model_validate(example) |
| 194 | + |
| 195 | + mock_wb_api_server_rcp.patch( |
| 196 | + "simcore_service_api_server.services_rpc.wb_api_server._checkout_licensed_item_for_wallet", |
| 197 | + side_effect, |
| 198 | + ) |
| 199 | + body = LicensedItemCheckoutData( |
| 200 | + number_of_seats=faker.pyint(min_value=1), service_run_id="myservice" |
| 201 | + ) |
| 202 | + resp = await client.post( |
| 203 | + f"{API_VTAG}/wallets/{_wallet_id}/licensed-items/{_licensed_item_id}/checkout", |
| 204 | + auth=auth, |
| 205 | + content=body.model_dump_json(), |
| 206 | + ) |
| 207 | + assert resp.status_code == expected_api_server_status_code |
0 commit comments