From 9833e57ccd2f9ec2090ab1f7da97500a071664b9 Mon Sep 17 00:00:00 2001 From: Max Nanis Date: Sat, 7 Mar 2026 09:51:37 -0500 Subject: conftest type annotations. --- tests/managers/thl/test_cashout_method.py | 6 +-- tests/managers/thl/test_ledger/test_lm_accounts.py | 32 ++++++++--- tests/managers/thl/test_ledger/test_user_txs.py | 63 ++++++++++++---------- 3 files changed, 61 insertions(+), 40 deletions(-) (limited to 'tests') diff --git a/tests/managers/thl/test_cashout_method.py b/tests/managers/thl/test_cashout_method.py index fe561d3..ee52188 100644 --- a/tests/managers/thl/test_cashout_method.py +++ b/tests/managers/thl/test_cashout_method.py @@ -3,13 +3,11 @@ import pytest from generalresearch.models.thl.wallet import PayoutType from generalresearch.models.thl.wallet.cashout_method import ( CashMailCashoutMethodData, - USDeliveryAddress, PaypalCashoutMethodData, + USDeliveryAddress, ) from test_utils.managers.cashout_methods import ( EXAMPLE_TANGO_CASHOUT_METHODS, - AMT_ASSIGNMENT_CASHOUT_METHOD, - AMT_BONUS_CASHOUT_METHOD, ) @@ -34,8 +32,10 @@ class TestAMTCashoutMethods: def test_create_and_get(self, cashout_method_manager, setup_cashoutmethod_db): res = cashout_method_manager.filter(payout_types=[PayoutType.AMT]) assert len(res) == 2 + cm = [x for x in res if x.name == "AMT Assignment"][0] assert AMT_ASSIGNMENT_CASHOUT_METHOD == cm + cm = [x for x in res if x.name == "AMT Bonus"][0] assert AMT_BONUS_CASHOUT_METHOD == cm diff --git a/tests/managers/thl/test_ledger/test_lm_accounts.py b/tests/managers/thl/test_ledger/test_lm_accounts.py index e0d9b0b..be9cf5b 100644 --- a/tests/managers/thl/test_ledger/test_lm_accounts.py +++ b/tests/managers/thl/test_ledger/test_lm_accounts.py @@ -1,5 +1,6 @@ from itertools import product as iproduct from random import randint +from typing import TYPE_CHECKING, Callable from uuid import uuid4 import pytest @@ -10,11 +11,20 @@ from generalresearch.managers.thl.ledger_manager.exceptions import ( LedgerAccountDoesntExistError, ) from generalresearch.managers.thl.ledger_manager.ledger import LedgerManager -from generalresearch.models.thl.ledger import LedgerAccount, AccountType, Direction from generalresearch.models.thl.ledger import ( + AccountType, + Direction, + LedgerAccount, LedgerEntry, ) -from test_utils.managers.ledger.conftest import ledger_account + +if TYPE_CHECKING: + from generalresearch.config import GRLSettings + from generalresearch.currency import LedgerCurrency + from generalresearch.models.thl.product import Product + from generalresearch.models.thl.session import Session + from generalresearch.models.thl.user import User + from generalresearch.models.thl.wallet import PayoutType @pytest.mark.parametrize( @@ -23,13 +33,15 @@ from test_utils.managers.ledger.conftest import ledger_account iproduct( ["USD", "test", "EUR"], ["expense", "wallet", "revenue", "cash"], - [uuid4().hex for i in range(3)], + [uuid4().hex for _ in range(3)], ) ), ) class TestLedgerAccountManagerNoResults: - def test_get_account_no_results(self, currency, kind, acct_id, lm): + def test_get_account_no_results( + self, currency: "LedgerCurrency", kind, acct_id, lm + ): """Try to query for accounts that we know don't exist and confirm that we either get the expected None result or it raises the correct exception @@ -46,7 +58,9 @@ class TestLedgerAccountManagerNoResults: # (2) .get_account_if_exists is another wrapper assert lm.get_account(qualified_name=qn, raise_on_error=False) is None - def test_get_account_no_results_many(self, currency, kind, acct_id, lm): + def test_get_account_no_results_many( + self, currency: "LedgerCurrency", kind, acct_id, lm + ): qn = ":".join([currency, kind, acct_id]) # (1) .get_many_ @@ -81,7 +95,7 @@ class TestLedgerAccountManagerNoResults: class TestLedgerAccountManagerCreate: def test_create_account_error_permission( - self, currency, account_type, direction, lm + self, currency: "LedgerCurrency", account_type, direction, lm ): """Confirm that the Permission values that are set on the Ledger Manger allow the Creation action to occur. @@ -126,7 +140,7 @@ class TestLedgerAccountManagerCreate: str(excinfo.value) == "LedgerManager does not have sufficient permissions" ) - def test_create(self, currency, account_type, direction, lm): + def test_create(self, currency: "LedgerCurrency", account_type, direction, lm): """Confirm that the Permission values that are set on the Ledger Manger allow the Creation action to occur. """ @@ -149,7 +163,9 @@ class TestLedgerAccountManagerCreate: res = lm.get_account(qualified_name=qn, raise_on_error=True) assert account.uuid == res.uuid - def test_get_or_create(self, currency, account_type, direction, lm): + def test_get_or_create( + self, currency: "LedgerCurrency", account_type, direction, lm + ): """Confirm that the Permission values that are set on the Ledger Manger allow the Creation action to occur. """ diff --git a/tests/managers/thl/test_ledger/test_user_txs.py b/tests/managers/thl/test_ledger/test_user_txs.py index d81b244..ecf146f 100644 --- a/tests/managers/thl/test_ledger/test_user_txs.py +++ b/tests/managers/thl/test_ledger/test_user_txs.py @@ -1,39 +1,42 @@ -from datetime import timedelta, datetime, timezone +from datetime import datetime, timedelta, timezone from decimal import Decimal +from typing import TYPE_CHECKING, Callable from uuid import uuid4 -from generalresearch.managers.thl.payout import ( - AMT_ASSIGNMENT_CASHOUT_METHOD, - AMT_BONUS_CASHOUT_METHOD, -) +from generalresearch.managers.thl.ledger_manager.thl_ledger import ThlLedgerManager from generalresearch.managers.thl.user_compensate import user_compensate from generalresearch.models.thl.definitions import ( Status, WallAdjustedStatus, ) from generalresearch.models.thl.ledger import ( + TransactionType, UserLedgerTransactionTypesSummary, UserLedgerTransactionTypeSummary, - TransactionType, ) -from generalresearch.models.thl.session import Session -from generalresearch.models.thl.user import User -from generalresearch.models.thl.wallet import PayoutType + +if TYPE_CHECKING: + from generalresearch.config import GRLSettings + from generalresearch.models.thl.product import Product + from generalresearch.models.thl.session import Session + from generalresearch.models.thl.user import User + from generalresearch.models.thl.wallet import PayoutType def test_user_txs( - user_factory, - product_amt_true, - create_main_accounts, - thl_lm, + user_factory: Callable[..., "User"], + product_amt_true: "Product", + create_main_accounts: Callable[..., None], + thl_lm: ThlLedgerManager, lm, - delete_ledger_db, + delete_ledger_db: Callable[..., None], session_with_tx_factory, adj_to_fail_with_tx_factory, adj_to_complete_with_tx_factory, session_factory, user_payout_event_manager, - utc_now, + utc_now: datetime, + settings: "GRLSettings", ): delete_ledger_db() create_main_accounts() @@ -53,7 +56,7 @@ def test_user_txs( pe = user_payout_event_manager.create( uuid=uuid4().hex, debit_account_uuid=account.uuid, - cashout_method_uuid=AMT_ASSIGNMENT_CASHOUT_METHOD, + cashout_method_uuid=settings.amt_assignment_cashout_method_id, amount=5, created=utc_now, payout_type=PayoutType.AMT_HIT, @@ -66,7 +69,7 @@ def test_user_txs( pe = user_payout_event_manager.create( uuid=uuid4().hex, debit_account_uuid=account.uuid, - cashout_method_uuid=AMT_BONUS_CASHOUT_METHOD, + cashout_method_uuid=settings.amt_bonus_cashout_method_id, amount=127, created=utc_now, payout_type=PayoutType.AMT_BONUS, @@ -133,16 +136,16 @@ def test_user_txs( def test_user_txs_pagination( - user_factory, - product_amt_true, - create_main_accounts, - thl_lm, - lm, - delete_ledger_db, - session_with_tx_factory, + user_factory: Callable[..., "User"], + product_amt_true: "Product", + create_main_accounts: Callable[..., None], + thl_lm: "ThlLedgerManager", + lm: "LedgerManager", + delete_ledger_db: Callable[..., None], + session_with_tx_factory: Callable[..., "Session"], adj_to_fail_with_tx_factory, user_payout_event_manager, - utc_now, + utc_now: datetime, ): delete_ledger_db() create_main_accounts() @@ -212,15 +215,16 @@ def test_user_txs_pagination( def test_user_txs_rolling_balance( - user_factory, - product_amt_true, + user_factory: Callable[..., "User"], + product_amt_true: "Product", create_main_accounts, thl_lm, lm, - delete_ledger_db, + delete_ledger_db: Callable[..., None], session_with_tx_factory, adj_to_fail_with_tx_factory, user_payout_event_manager, + settings: "GRLSettings", ): """ Creates 3 $1.00 bonuses (postive), @@ -242,10 +246,11 @@ def test_user_txs_rolling_balance( amount_int=100, skip_flag_check=True, ) + pe = user_payout_event_manager.create( uuid=uuid4().hex, debit_account_uuid=account.uuid, - cashout_method_uuid=AMT_BONUS_CASHOUT_METHOD, + cashout_method_uuid=settings.amt_bonus_cashout_method_id, amount=150, payout_type=PayoutType.AMT_BONUS, request_data=dict(), -- cgit v1.2.3