Skip to content

Commit

Permalink
list/get checkouts
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 committed Dec 20, 2024
1 parent 3eb5d61 commit 53364d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def list_licensed_item_checkouts_for_wallet(request: web.Request):
],
)

page = Page[LicensedItemCheckoutRestGetPage].model_validate(
page = Page[LicensedItemCheckoutRestGet].model_validate(
paginate_data(
chunk=get_page.items,
request_url=request.url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
from servicelib.aiohttp.application_setup import ModuleCategory, app_module_setup

from ..rabbitmq import setup_rabbitmq
from . import _licensed_items_handlers, _licensed_items_purchases_handlers, _rpc
from . import (
_licensed_items_checkouts_handlers,
_licensed_items_handlers,
_licensed_items_purchases_handlers,
_rpc,
)

_logger = logging.getLogger(__name__)

Expand All @@ -26,6 +31,7 @@ def setup_licenses(app: web.Application):
# routes
app.router.add_routes(_licensed_items_handlers.routes)
app.router.add_routes(_licensed_items_purchases_handlers.routes)
app.router.add_routes(_licensed_items_checkouts_handlers.routes)

setup_rabbitmq(app)
if app[APP_SETTINGS_KEY].WEBSERVER_RABBITMQ:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,42 @@

import pytest
from aiohttp.test_utils import TestClient
from models_library.api_schemas_resource_usage_tracker import (
licensed_items_checkouts as rut_licensed_items_checkouts,
from models_library.api_schemas_resource_usage_tracker.licensed_items_checkouts import (
LicensedItemCheckoutGet,
LicensedItemsCheckoutsPage,
)
from models_library.api_schemas_webserver.licensed_items_purchases import (
LicensedItemPurchaseGet,
from models_library.api_schemas_webserver.licensed_items_checkouts import (
LicensedItemCheckoutRestGet,
)
from pytest_mock.plugin import MockerFixture
from pytest_simcore.helpers.assert_checks import assert_status
from pytest_simcore.helpers.webserver_login import UserInfoDict
from servicelib.aiohttp import status
from simcore_service_webserver.db.models import UserRole

_LICENSED_ITEM_CHECKOUT_GET = (
rut_licensed_items_checkouts.LicensedItemCheckoutGet.model_validate({})
_LICENSED_ITEM_CHECKOUT_GET = LicensedItemCheckoutGet.model_validate(
LicensedItemCheckoutGet.model_config["json_schema_extra"]["examples"][0]
)

_LICENSED_ITEM_CHECKOUT_PAGE = rut_licensed_items_checkouts.LicensedItemsCheckoutsPage(
_LICENSED_ITEM_CHECKOUT_PAGE = LicensedItemsCheckoutsPage(
items=[_LICENSED_ITEM_CHECKOUT_GET],
total=1,
)


@pytest.fixture
def mock_get_licensed_items_purchases_page(mocker: MockerFixture) -> tuple:
def mock_get_licensed_items_checkouts_page(mocker: MockerFixture) -> tuple:
return mocker.patch(
"simcore_service_webserver.licenses._licensed_items_checkouts_api.licensed_items_checkouts_api.get_licensed_items_purchases_page",
"simcore_service_webserver.licenses._licensed_items_checkouts_api.licensed_items_checkouts.get_licensed_items_checkouts_page",
spec=True,
return_value=_LICENSED_ITEM_CHECKOUT_PAGE,
)


@pytest.fixture
def mock_get_licensed_item_purchase(mocker: MockerFixture) -> tuple:
def mock_get_licensed_item_checkout(mocker: MockerFixture) -> tuple:
return mocker.patch(
"simcore_service_webserver.licenses._licensed_items_checkouts_api.licensed_items_purchases.get_licensed_item_purchase",
"simcore_service_webserver.licenses._licensed_items_checkouts_api.licensed_items_checkouts.get_licensed_item_checkout",
spec=True,
return_value=_LICENSED_ITEM_CHECKOUT_GET,
)
Expand All @@ -60,25 +61,25 @@ async def test_licensed_items_checkouts_handlers(
client: TestClient,
logged_user: UserInfoDict,
expected: HTTPStatus,
mock_get_licensed_items_purchases_page: MockerFixture,
mock_get_licensed_item_purchase: MockerFixture,
mock_get_licensed_items_checkouts_page: MockerFixture,
mock_get_licensed_item_checkout: MockerFixture,
mock_get_wallet_by_user: MockerFixture,
):
assert client.app

# list
url = client.app.router["list_wallet_licensed_items_purchases"].url_for(
url = client.app.router["list_licensed_item_checkouts_for_wallet"].url_for(
wallet_id="1"
)
resp = await client.get(f"{url}")
data, _ = await assert_status(resp, status.HTTP_200_OK)
assert len(data) == 1
assert LicensedItemPurchaseGet(**data[0])
assert LicensedItemCheckoutRestGet(**data[0])

# get
url = client.app.router["get_licensed_item_purchase"].url_for(
licensed_item_purchase_id=f"{_LICENSED_ITEM_PURCHASE_PAGE.items[0].licensed_item_purchase_id}"
url = client.app.router["get_licensed_item_checkout"].url_for(
licensed_item_checkout_id=f"{_LICENSED_ITEM_CHECKOUT_PAGE.items[0].licensed_item_checkout_id}"
)
resp = await client.get(f"{url}")
data, _ = await assert_status(resp, status.HTTP_200_OK)
assert LicensedItemPurchaseGet(**data)
assert LicensedItemCheckoutRestGet(**data)

0 comments on commit 53364d0

Please sign in to comment.