2121from servicelib .rabbitmq import RabbitMQClient , RabbitMQRPCClient
2222from servicelib .rabbitmq .rpc_interfaces .resource_usage_tracker import (
2323 credit_transactions ,
24+ service_runs ,
2425)
2526from simcore_postgres_database .models .resource_tracker_credit_transactions import (
2627 resource_tracker_credit_transactions ,
2728)
2829from simcore_postgres_database .models .resource_tracker_service_runs import (
2930 resource_tracker_service_runs ,
3031)
32+ from simcore_service_resource_usage_tracker .services .service_runs import ServiceRunPage
3133from starlette import status
3234from yarl import URL
3335
@@ -166,15 +168,17 @@ def resource_tracker_setup_db(
166168 stopped_at = datetime .now (tz = UTC ),
167169 project_id = project_id ,
168170 service_run_status = ServiceRunStatus .SUCCESS ,
171+ wallet_id = _WALLET_ID ,
169172 ),
170173 random_resource_tracker_service_run (
171174 user_id = _USER_ID_2 , # <-- different user
172175 service_run_id = _SERVICE_RUN_ID_2 ,
173176 product_name = product_name ,
174177 started_at = datetime .now (tz = UTC ) - timedelta (hours = 1 ),
175- stopped_at = datetime . now ( tz = UTC ) ,
178+ stopped_at = None ,
176179 project_id = project_id ,
177- service_run_status = ServiceRunStatus .SUCCESS ,
180+ service_run_status = ServiceRunStatus .RUNNING , # <-- Runnin status
181+ wallet_id = _WALLET_ID ,
178182 ),
179183 random_resource_tracker_service_run (
180184 user_id = _USER_ID_1 ,
@@ -184,6 +188,7 @@ def resource_tracker_setup_db(
184188 stopped_at = datetime .now (tz = UTC ),
185189 project_id = project_id ,
186190 service_run_status = ServiceRunStatus .SUCCESS ,
191+ wallet_id = _WALLET_ID ,
187192 ),
188193 random_resource_tracker_service_run (
189194 user_id = _USER_ID_1 ,
@@ -193,6 +198,7 @@ def resource_tracker_setup_db(
193198 stopped_at = datetime .now (tz = UTC ),
194199 project_id = faker .uuid4 (), # <-- different project
195200 service_run_status = ServiceRunStatus .SUCCESS ,
201+ wallet_id = _WALLET_ID ,
196202 ),
197203 ]
198204 )
@@ -210,6 +216,7 @@ def resource_tracker_setup_db(
210216 user_id = _USER_ID_1 ,
211217 service_run_id = _SERVICE_RUN_ID_1 ,
212218 product_name = product_name ,
219+ payment_transaction_id = None ,
213220 osparc_credits = - 50 ,
214221 transaction_status = CreditTransactionStatus .BILLED ,
215222 transaction_classification = CreditClassification .DEDUCT_SERVICE_RUN ,
@@ -219,8 +226,9 @@ def resource_tracker_setup_db(
219226 user_id = _USER_ID_2 , # <-- different user
220227 service_run_id = _SERVICE_RUN_ID_2 ,
221228 product_name = product_name ,
229+ payment_transaction_id = None ,
222230 osparc_credits = - 70 ,
223- transaction_status = CreditTransactionStatus .BILLED ,
231+ transaction_status = CreditTransactionStatus .PENDING , # <-- Pending status
224232 transaction_classification = CreditClassification .DEDUCT_SERVICE_RUN ,
225233 wallet_id = _WALLET_ID ,
226234 ),
@@ -229,6 +237,7 @@ def resource_tracker_setup_db(
229237 osparc_credits = - 100 ,
230238 service_run_id = _SERVICE_RUN_ID_3 ,
231239 product_name = product_name ,
240+ payment_transaction_id = None ,
232241 transaction_status = CreditTransactionStatus .IN_DEBT , # <-- IN DEBT
233242 transaction_classification = CreditClassification .DEDUCT_SERVICE_RUN ,
234243 wallet_id = _WALLET_ID ,
@@ -238,6 +247,7 @@ def resource_tracker_setup_db(
238247 osparc_credits = - 90 ,
239248 service_run_id = _SERVICE_RUN_ID_4 ,
240249 product_name = product_name ,
250+ payment_transaction_id = None ,
241251 transaction_status = CreditTransactionStatus .BILLED ,
242252 transaction_classification = CreditClassification .DEDUCT_SERVICE_RUN ,
243253 wallet_id = _WALLET_ID ,
@@ -248,6 +258,7 @@ def resource_tracker_setup_db(
248258 osparc_credits = 50 , # <-- Not enough credits to pay the DEBT (-100)
249259 service_run_id = None ,
250260 product_name = product_name ,
261+ payment_transaction_id = "INVITATION" ,
251262 transaction_status = CreditTransactionStatus .BILLED ,
252263 transaction_classification = CreditClassification .ADD_WALLET_TOP_UP ,
253264 wallet_id = _WALLET_ID_FOR_PAYING_DEBT__NOT_ENOUGH_CREDITS ,
@@ -451,3 +462,56 @@ async def test_pay_project_debt(
451462 == total_wallet_credits_for_wallet_in_debt_in_beginning .available_osparc_credits
452463 + 100 # <-- 100 was added to the original wallet
453464 )
465+
466+
467+ async def test_list_service_runs_with_transaction_status_filter (
468+ mocked_redis_server : None ,
469+ resource_tracker_setup_db : None ,
470+ rpc_client : RabbitMQRPCClient ,
471+ project_id : ProjectID ,
472+ product_name : ProductName ,
473+ ):
474+ result = await service_runs .get_service_run_page (
475+ rpc_client ,
476+ user_id = _USER_ID_1 ,
477+ product_name = product_name ,
478+ wallet_id = _WALLET_ID ,
479+ access_all_wallet_usage = True ,
480+ project_id = project_id ,
481+ transaction_status = CreditTransactionStatus .PENDING ,
482+ offset = 0 ,
483+ limit = 1 ,
484+ )
485+ assert isinstance (result , ServiceRunPage )
486+ assert len (result .items ) == 1
487+ assert result .total == 1
488+
489+ result = await service_runs .get_service_run_page (
490+ rpc_client ,
491+ user_id = _USER_ID_1 ,
492+ product_name = product_name ,
493+ wallet_id = _WALLET_ID ,
494+ access_all_wallet_usage = True ,
495+ project_id = project_id ,
496+ transaction_status = CreditTransactionStatus .IN_DEBT ,
497+ offset = 0 ,
498+ limit = 1 ,
499+ )
500+ assert isinstance (result , ServiceRunPage )
501+ assert len (result .items ) == 1
502+ assert result .total == 1
503+
504+ result = await service_runs .get_service_run_page (
505+ rpc_client ,
506+ user_id = _USER_ID_1 ,
507+ product_name = product_name ,
508+ wallet_id = _WALLET_ID ,
509+ access_all_wallet_usage = True ,
510+ project_id = project_id ,
511+ transaction_status = CreditTransactionStatus .BILLED ,
512+ offset = 0 ,
513+ limit = 1 ,
514+ )
515+ assert isinstance (result , ServiceRunPage )
516+ assert len (result .items ) == 1
517+ assert result .total == 1
0 commit comments