Skip to content

Commit 162c35e

Browse files
author
Andrei Neagu
committed
refactor test
1 parent e27b59a commit 162c35e

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

packages/postgres-database/tests/test_models_payments_transactions.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import decimal
88
from collections.abc import Callable
9+
from typing import Any
910

1011
import pytest
1112
import sqlalchemy as sa
@@ -43,21 +44,24 @@ async def test_numerics_precission_and_scale(connection: SAConnection):
4344
assert float(got) == expected
4445

4546

47+
def _remove_not_required(data: dict[str, Any]) -> dict[str, Any]:
48+
for to_remove in (
49+
"completed_at",
50+
"invoice_url",
51+
"invoice_pdf_url",
52+
"state",
53+
"state_message",
54+
"stripe_invoice_id",
55+
):
56+
data.pop(to_remove)
57+
return data
58+
59+
4660
@pytest.fixture
4761
def init_transaction(connection: SAConnection):
4862
async def _init(payment_id: str):
4963
# get payment_id from payment-gateway
50-
values = random_payment_transaction(payment_id=payment_id)
51-
# remove states
52-
for to_remove in (
53-
"completed_at",
54-
"invoice_url",
55-
"invoice_pdf_url",
56-
"state",
57-
"state_message",
58-
"stripe_invoice_id",
59-
):
60-
values.pop(to_remove)
64+
values = _remove_not_required(random_payment_transaction(payment_id=payment_id))
6165

6266
# init successful: set timestamp
6367
values["initiated_at"] = utcnow()
@@ -188,10 +192,8 @@ def create_fake_user_transactions(connection: SAConnection, user_id: int) -> Cal
188192
async def _go(expected_total=5):
189193
payment_ids = []
190194
for _ in range(expected_total):
191-
values = random_payment_transaction(user_id=user_id)
192-
# remove states
193-
values.pop("state")
194-
values.pop("completed_at")
195+
values = _remove_not_required(random_payment_transaction(user_id=user_id))
196+
195197
payment_id = await insert_init_payment_transaction(connection, **values)
196198
assert payment_id
197199
payment_ids.append(payment_id)

0 commit comments

Comments
 (0)