Skip to content

Commit 64293f0

Browse files
GitHKAndrei Neagu
authored andcommitted
🎨 pydantic2 migration: fixed unit-tests for payments (#6553)
Co-authored-by: Andrei Neagu <[email protected]>
1 parent c2b4983 commit 64293f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+531
-279
lines changed

packages/models-library/src/models_library/api_schemas_payments/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from pydantic.errors import PydanticErrorMixin
1+
from common_library.errors_classes import OsparcErrorMixin
22

33

4-
class _BaseRpcApiError(PydanticErrorMixin, ValueError):
4+
class _BaseRpcApiError(OsparcErrorMixin, ValueError):
55
@classmethod
66
def get_full_class_name(cls) -> str:
77
# Can be used as unique code identifier

packages/postgres-database/tests/test_models_payments_transactions.py

Lines changed: 18 additions & 8 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,14 +44,25 @@ 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-
values.pop("state")
53-
values.pop("completed_at")
64+
values = _remove_not_required(random_payment_transaction(payment_id=payment_id))
65+
5466
# init successful: set timestamp
5567
values["initiated_at"] = utcnow()
5668

@@ -180,10 +192,8 @@ def create_fake_user_transactions(connection: SAConnection, user_id: int) -> Cal
180192
async def _go(expected_total=5):
181193
payment_ids = []
182194
for _ in range(expected_total):
183-
values = random_payment_transaction(user_id=user_id)
184-
# remove states
185-
values.pop("state")
186-
values.pop("completed_at")
195+
values = _remove_not_required(random_payment_transaction(user_id=user_id))
196+
187197
payment_id = await insert_init_payment_transaction(connection, **values)
188198
assert payment_id
189199
payment_ids.append(payment_id)

packages/pytest-simcore/src/pytest_simcore/helpers/faker_factories.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ def random_payment_transaction(
301301
"initiated_at": utcnow(),
302302
"state": PaymentTransactionState.PENDING,
303303
"completed_at": None,
304+
"invoice_url": None,
305+
"stripe_invoice_id": None,
306+
"invoice_pdf_url": None,
307+
"state_message": None,
304308
}
305309
# state is not added on purpose
306310
assert set(data.keys()).issubset({c.name for c in payments_transactions.columns})

packages/settings-library/src/settings_library/utils_cli.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ def print_as_envfile(
6767

6868

6969
def print_as_json(
70-
settings_obj, *, compact=False, show_secrets, **pydantic_export_options
70+
settings_obj,
71+
*,
72+
compact: bool = False,
73+
show_secrets: bool,
74+
json_serializer,
75+
**pydantic_export_options,
7176
):
7277
typer.echo(
73-
json.dumps(
78+
json_serializer(
7479
model_dump_with_secrets(
7580
settings_obj, show_secrets=show_secrets, **pydantic_export_options
7681
),
@@ -80,7 +85,9 @@ def print_as_json(
8085

8186

8287
def create_settings_command(
83-
settings_cls: type[BaseCustomSettings], logger: logging.Logger | None = None
88+
settings_cls: type[BaseCustomSettings],
89+
logger: logging.Logger | None = None,
90+
json_serializer=json.dumps,
8491
) -> Callable:
8592
"""Creates typer command function for settings"""
8693

@@ -145,6 +152,7 @@ def settings(
145152
settings_obj,
146153
compact=compact,
147154
show_secrets=show_secrets,
155+
json_serializer=json_serializer,
148156
**pydantic_export_options,
149157
)
150158
else:

packages/settings-library/tests/test_utils_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ class FakeSettings(BaseCustomSettings):
434434
assert "secret" not in captured.out
435435
assert "Some info" not in captured.out
436436

437-
print_as_json(settings_obj, compact=True, show_secrets=False)
437+
print_as_json(
438+
settings_obj, compact=True, show_secrets=False, json_serializer=json.dumps
439+
)
438440
captured = capsys.readouterr()
439441
assert "secret" not in captured.out
440442
assert "**" in captured.out

0 commit comments

Comments
 (0)