Skip to content

Commit

Permalink
RUT unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 committed Dec 10, 2024
1 parent f5de79b commit acd4c88
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""add cols to licensed_items_purchases table
Revision ID: 8fa15c4c3977
Revises: 38c9ac332c58
Revises: 4d007819e61a
Create Date: 2024-12-10 06:42:23.319239+00:00
"""
Expand All @@ -10,7 +10,7 @@

# revision identifiers, used by Alembic.
revision = "8fa15c4c3977"
down_revision = "38c9ac332c58"
down_revision = "4d007819e61a"
branch_labels = None
depends_on = None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""add cols to licensed_items_purchases table 2
Revision ID: d68b8128c23b
Revises: 8fa15c4c3977
Create Date: 2024-12-10 10:24:28.071216+00:00
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "d68b8128c23b"
down_revision = "8fa15c4c3977"
branch_labels = None
depends_on = None


def upgrade():
op.drop_column("resource_tracker_licensed_items_purchases", "licensed_item_id")
op.add_column(
"resource_tracker_licensed_items_purchases",
sa.Column("licensed_item_id", postgresql.UUID(as_uuid=True), nullable=False),
)


def downgrade():
...
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
),
sa.Column(
"licensed_item_id",
sa.BigInteger,
UUID(as_uuid=True),
nullable=False,
),
sa.Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def create(
data: CreateLicensedItemsPurchasesDB,
) -> LicensedItemsPurchasesDB:
async with transaction_context(engine, connection) as conn:
result = await conn.stream(
result = await conn.execute(
resource_tracker_licensed_items_purchases.insert()
.values(
product_name=data.product_name,
Expand All @@ -67,7 +67,7 @@ async def create(
)
.returning(*_SELECTION_ARGS)
)
row = await result.first()
row = result.first()
return LicensedItemsPurchasesDB.model_validate(row)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# pylint:disable=redefined-outer-name
# pylint:disable=too-many-arguments

from datetime import datetime, timezone
from datetime import UTC, datetime
from decimal import Decimal

# # Remove the environment variable
Expand All @@ -12,6 +12,7 @@
import sqlalchemy as sa
from models_library.api_schemas_resource_usage_tracker.licensed_items_purchases import (
LicensedItemPurchaseGet,
LicensedItemsPurchasesPage,
)
from models_library.resource_tracker_licensed_items_purchases import (
LicensedItemsPurchasesCreate,
Expand Down Expand Up @@ -73,7 +74,9 @@ async def test_rpc_licensed_items_purchases_workflow(
result = await licensed_items_purchases.get_licensed_items_purchases_page(
rpc_client, product_name="osparc", wallet_id=1
)
assert isinstance(result, list) # nosec
assert isinstance(result, LicensedItemsPurchasesPage) # nosec
assert result.items == []
assert result.total == 0

_create_data = LicensedItemsPurchasesCreate(
product_name="osparc",
Expand All @@ -82,26 +85,29 @@ async def test_rpc_licensed_items_purchases_workflow(
wallet_name="My Wallet",
pricing_unit_cost_id=1,
pricing_unit_cost=Decimal(10),
start_at=datetime.now(tz=timezone.utc),
expire_at=datetime.now(tz=timezone.utc),
start_at=datetime.now(tz=UTC),
expire_at=datetime.now(tz=UTC),
num_of_seats=1,
purchased_by_user=1,
purchased_at=datetime.now(tz=timezone.utc),
purchased_at=datetime.now(tz=UTC),
)

result = await licensed_items_purchases.create_licensed_item_purchase(
created_item = await licensed_items_purchases.create_licensed_item_purchase(
rpc_client, data=_create_data
)
assert isinstance(result, LicensedItemPurchaseGet) # nosec

result = await licensed_items_purchases.get_licensed_item_purchase(
rpc_client,
product_name="osparc",
licensed_item_purchase_id=result.licensed_item_purchase_id,
licensed_item_purchase_id=created_item.licensed_item_purchase_id,
)
assert isinstance(result, LicensedItemPurchaseGet) # nosec
assert result.licensed_item_purchase_id == created_item.licensed_item_purchase_id

result = await licensed_items_purchases.get_licensed_items_purchases_page(
rpc_client, product_name="osparc", wallet_id=_create_data.wallet_id
)
assert isinstance(result, list) # nosec
assert isinstance(result, LicensedItemsPurchasesPage) # nosec
assert len(result.items) == 1
assert result.total == 1

0 comments on commit acd4c88

Please sign in to comment.