-
Notifications
You must be signed in to change notification settings - Fork 32
🎨 release license seats on issues #6980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matusdrobuliak66
merged 7 commits into
ITISFoundation:master
from
matusdrobuliak66:introduce-vip-models-pricing-8-part
Dec 19, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4790ab3
release seats on issues
matusdrobuliak66 e9dd8e5
Merge branch 'master' into introduce-vip-models-pricing-8-part
matusdrobuliak66 ae14a78
release seats on issues
matusdrobuliak66 1ba77c0
Merge branch 'introduce-vip-models-pricing-8-part' of github.com:matu…
matusdrobuliak66 0d07303
Merge branch 'master' into introduce-vip-models-pricing-8-part
matusdrobuliak66 8b6b38c
Merge branch 'master' into introduce-vip-models-pricing-8-part
matusdrobuliak66 42071a0
add force release of license seats on stop event
matusdrobuliak66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
services/resource-usage-tracker/tests/unit/with_dbs/test_licensed_items_checkouts_db.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| # pylint:disable=unused-variable | ||
| # pylint:disable=unused-argument | ||
| # pylint:disable=redefined-outer-name | ||
| # pylint:disable=too-many-arguments | ||
|
|
||
|
|
||
| from datetime import UTC, datetime | ||
| from typing import Generator | ||
| from unittest import mock | ||
|
|
||
| import pytest | ||
| import sqlalchemy as sa | ||
| from models_library.basic_types import IDStr | ||
| from models_library.rest_ordering import OrderBy | ||
| from simcore_postgres_database.models.resource_tracker_licensed_items_checkouts import ( | ||
| resource_tracker_licensed_items_checkouts, | ||
| ) | ||
| from simcore_postgres_database.models.resource_tracker_service_runs import ( | ||
| resource_tracker_service_runs, | ||
| ) | ||
| from simcore_service_resource_usage_tracker.models.licensed_items_checkouts import ( | ||
| CreateLicensedItemCheckoutDB, | ||
| ) | ||
| from simcore_service_resource_usage_tracker.services.modules.db import ( | ||
| licensed_items_checkouts_db, | ||
| ) | ||
|
|
||
| pytest_simcore_core_services_selection = [ | ||
| "postgres", | ||
| ] | ||
| pytest_simcore_ops_services_selection = [ | ||
| "adminer", | ||
| ] | ||
|
|
||
|
|
||
| _USER_ID_1 = 1 | ||
| _WALLET_ID = 6 | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def resource_tracker_service_run_id( | ||
| postgres_db: sa.engine.Engine, random_resource_tracker_service_run | ||
| ) -> Generator[str, None, None]: | ||
| with postgres_db.connect() as con: | ||
| result = con.execute( | ||
| resource_tracker_service_runs.insert() | ||
| .values( | ||
| **random_resource_tracker_service_run( | ||
| user_id=_USER_ID_1, wallet_id=_WALLET_ID | ||
| ) | ||
| ) | ||
| .returning(resource_tracker_service_runs.c.service_run_id) | ||
| ) | ||
| row = result.first() | ||
| assert row | ||
|
|
||
| yield row[0] | ||
|
|
||
| con.execute(resource_tracker_licensed_items_checkouts.delete()) | ||
| con.execute(resource_tracker_service_runs.delete()) | ||
|
|
||
|
|
||
| async def test_licensed_items_checkouts_db__force_release_license_seats_by_run_id( | ||
| mocked_redis_server: None, | ||
| mocked_setup_rabbitmq: mock.Mock, | ||
| resource_tracker_service_run_id, | ||
| initialized_app, | ||
| ): | ||
| engine = initialized_app.state.engine | ||
|
|
||
| # SETUP | ||
| _create_license_item_checkout_db_1 = CreateLicensedItemCheckoutDB( | ||
| licensed_item_id="beb16d18-d57d-44aa-a638-9727fa4a72ef", | ||
| wallet_id=_WALLET_ID, | ||
| user_id=_USER_ID_1, | ||
| user_email="[email protected]", | ||
| product_name="osparc", | ||
| service_run_id=resource_tracker_service_run_id, | ||
| started_at=datetime.now(tz=UTC), | ||
| num_of_seats=1, | ||
| ) | ||
| await licensed_items_checkouts_db.create( | ||
| engine, data=_create_license_item_checkout_db_1 | ||
| ) | ||
|
|
||
| _create_license_item_checkout_db_2 = _create_license_item_checkout_db_1.model_dump() | ||
| _create_license_item_checkout_db_2[ | ||
| "licensed_item_id" | ||
| ] = "b1b96583-333f-44d6-b1e0-5c0a8af555bf" | ||
| await licensed_items_checkouts_db.create( | ||
| engine, | ||
| data=CreateLicensedItemCheckoutDB.model_construct( | ||
| **_create_license_item_checkout_db_2 | ||
| ), | ||
| ) | ||
|
|
||
| _create_license_item_checkout_db_3 = _create_license_item_checkout_db_1.model_dump() | ||
| _create_license_item_checkout_db_3[ | ||
| "licensed_item_id" | ||
| ] = "38a5ce59-876f-482a-ace1-d3b2636feac6" | ||
| checkout = await licensed_items_checkouts_db.create( | ||
| engine, | ||
| data=CreateLicensedItemCheckoutDB.model_construct( | ||
| **_create_license_item_checkout_db_3 | ||
| ), | ||
| ) | ||
|
|
||
| _helper_time = datetime.now(UTC) | ||
| await licensed_items_checkouts_db.update( | ||
| engine, | ||
| licensed_item_checkout_id=checkout.licensed_item_checkout_id, | ||
| product_name="osparc", | ||
| stopped_at=_helper_time, | ||
| ) | ||
|
|
||
| # TEST FORCE RELEASE LICENSE SEATS | ||
| await licensed_items_checkouts_db.force_release_license_seats_by_run_id( | ||
| engine, service_run_id=resource_tracker_service_run_id | ||
| ) | ||
|
|
||
| # ASSERT | ||
| total, items = await licensed_items_checkouts_db.list_( | ||
| engine, | ||
| product_name="osparc", | ||
| filter_wallet_id=_WALLET_ID, | ||
| offset=0, | ||
| limit=5, | ||
| order_by=OrderBy(field=IDStr("started_at")), | ||
| ) | ||
| assert total == 3 | ||
| assert len(items) == 3 | ||
|
|
||
| _helper_count = 0 | ||
| for item in items: | ||
| assert isinstance(item.stopped_at, datetime) | ||
| if item.stopped_at > _helper_time: | ||
| _helper_count += 1 | ||
|
|
||
| assert _helper_count == 2 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.