|
| 1 | +from collections.abc import AsyncIterator |
| 2 | + |
| 3 | +# pylint: disable=redefined-outer-name |
| 4 | +# pylint: disable=unused-argument |
| 5 | +# pylint: disable=unused-variable |
| 6 | +# pylint: disable=too-many-arguments |
| 7 | +# pylint: disable=too-many-statements |
| 8 | +from http import HTTPStatus |
| 9 | + |
| 10 | +import pytest |
| 11 | +from aiohttp.test_utils import TestClient |
| 12 | +from models_library.license_goods import ( |
| 13 | + LicenseGoodDB, |
| 14 | + LicenseGoodUpdateDB, |
| 15 | + LicenseResourceType, |
| 16 | +) |
| 17 | +from models_library.rest_ordering import OrderBy |
| 18 | +from pytest_simcore.helpers.webserver_login import UserInfoDict |
| 19 | +from servicelib.aiohttp import status |
| 20 | +from simcore_service_webserver.db.models import UserRole |
| 21 | +from simcore_service_webserver.licenses import _license_goods_db |
| 22 | +from simcore_service_webserver.licenses.errors import LicenseGoodNotFoundError |
| 23 | +from simcore_service_webserver.projects.models import ProjectDict |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.parametrize("user_role,expected", [(UserRole.USER, status.HTTP_200_OK)]) |
| 27 | +async def test_license_goods_db_crud( |
| 28 | + client: TestClient, |
| 29 | + logged_user: UserInfoDict, |
| 30 | + user_project: ProjectDict, |
| 31 | + osparc_product_name: str, |
| 32 | + expected: HTTPStatus, |
| 33 | + workspaces_clean_db: AsyncIterator[None], |
| 34 | +): |
| 35 | + assert client.app |
| 36 | + |
| 37 | + output: tuple[int, list[LicenseGoodDB]] = await _license_goods_db.list_( |
| 38 | + client.app, |
| 39 | + product_name=osparc_product_name, |
| 40 | + offset=0, |
| 41 | + limit=10, |
| 42 | + order_by=OrderBy(field="modified"), |
| 43 | + ) |
| 44 | + assert output[0] == 0 |
| 45 | + |
| 46 | + license_good_db = await _license_goods_db.create( |
| 47 | + client.app, |
| 48 | + product_name=osparc_product_name, |
| 49 | + name="Model A", |
| 50 | + license_resource_type=LicenseResourceType.VIP_MODEL, |
| 51 | + pricing_plan_id=1, |
| 52 | + ) |
| 53 | + _license_good_id = license_good_db.license_good_id |
| 54 | + |
| 55 | + output: tuple[int, list[LicenseGoodDB]] = await _license_goods_db.list_( |
| 56 | + client.app, |
| 57 | + product_name=osparc_product_name, |
| 58 | + offset=0, |
| 59 | + limit=10, |
| 60 | + order_by=OrderBy(field="modified"), |
| 61 | + ) |
| 62 | + assert output[0] == 1 |
| 63 | + |
| 64 | + license_good_db = await _license_goods_db.get( |
| 65 | + client.app, |
| 66 | + license_good_id=_license_good_id, |
| 67 | + product_name=osparc_product_name, |
| 68 | + ) |
| 69 | + assert license_good_db.name == "Model A" |
| 70 | + |
| 71 | + await _license_goods_db.update( |
| 72 | + client.app, |
| 73 | + license_good_id=_license_good_id, |
| 74 | + product_name=osparc_product_name, |
| 75 | + updates=LicenseGoodUpdateDB(name="Model B"), |
| 76 | + ) |
| 77 | + |
| 78 | + license_good_db = await _license_goods_db.get( |
| 79 | + client.app, |
| 80 | + license_good_id=_license_good_id, |
| 81 | + product_name=osparc_product_name, |
| 82 | + ) |
| 83 | + assert license_good_db.name == "Model B" |
| 84 | + |
| 85 | + license_good_db = await _license_goods_db.delete( |
| 86 | + client.app, |
| 87 | + license_good_id=_license_good_id, |
| 88 | + product_name=osparc_product_name, |
| 89 | + ) |
| 90 | + |
| 91 | + with pytest.raises(LicenseGoodNotFoundError): |
| 92 | + await _license_goods_db.get( |
| 93 | + client.app, |
| 94 | + license_good_id=_license_good_id, |
| 95 | + product_name=osparc_product_name, |
| 96 | + ) |
0 commit comments