|
1 | | -from collections.abc import Iterator |
| 1 | +from collections.abc import Callable, Iterator |
2 | 2 | from datetime import UTC, datetime, timedelta |
3 | 3 | from decimal import Decimal |
4 | | -from typing import Callable |
5 | 4 |
|
6 | 5 | import httpx |
7 | 6 | import pytest |
|
32 | 31 | from simcore_postgres_database.models.resource_tracker_service_runs import ( |
33 | 32 | resource_tracker_service_runs, |
34 | 33 | ) |
| 34 | +from simcore_service_resource_usage_tracker.services.modules.db import ( |
| 35 | + credit_transactions_db, |
| 36 | +) |
35 | 37 | from simcore_service_resource_usage_tracker.services.service_runs import ServiceRunPage |
36 | 38 | from starlette import status |
37 | 39 | from yarl import URL |
@@ -520,3 +522,32 @@ async def test_list_service_runs_with_transaction_status_filter( |
520 | 522 | assert isinstance(result, ServiceRunPage) |
521 | 523 | assert len(result.items) == 1 |
522 | 524 | assert result.total == 1 |
| 525 | + |
| 526 | + |
| 527 | +async def test_sum_wallet_credits_db( |
| 528 | + mocked_redis_server: None, |
| 529 | + resource_tracker_setup_db: None, |
| 530 | + rpc_client: RabbitMQRPCClient, |
| 531 | + product_name: ProductName, |
| 532 | + initialized_app, |
| 533 | +): |
| 534 | + engine = initialized_app.state.engine |
| 535 | + output_including_pending_transaction = ( |
| 536 | + await credit_transactions_db.sum_wallet_credits( |
| 537 | + engine, product_name=product_name, wallet_id=_WALLET_ID |
| 538 | + ) |
| 539 | + ) |
| 540 | + assert output_including_pending_transaction.available_osparc_credits == Decimal( |
| 541 | + "-310.00" |
| 542 | + ) |
| 543 | + output_excluding_pending_transaction = ( |
| 544 | + await credit_transactions_db.sum_wallet_credits( |
| 545 | + engine, |
| 546 | + product_name=product_name, |
| 547 | + wallet_id=_WALLET_ID, |
| 548 | + include_pending_transactions=False, |
| 549 | + ) |
| 550 | + ) |
| 551 | + assert output_excluding_pending_transaction.available_osparc_credits == Decimal( |
| 552 | + "-240.00" |
| 553 | + ) |
0 commit comments