aboutsummaryrefslogtreecommitdiff
path: root/test_utils/managers
diff options
context:
space:
mode:
Diffstat (limited to 'test_utils/managers')
-rw-r--r--test_utils/managers/cashout_methods.py48
-rw-r--r--test_utils/managers/conftest.py44
-rw-r--r--test_utils/managers/contest/conftest.py72
-rw-r--r--test_utils/managers/ledger/conftest.py270
4 files changed, 245 insertions, 189 deletions
diff --git a/test_utils/managers/cashout_methods.py b/test_utils/managers/cashout_methods.py
index c338676..96d33cf 100644
--- a/test_utils/managers/cashout_methods.py
+++ b/test_utils/managers/cashout_methods.py
@@ -49,28 +49,28 @@ EXAMPLE_TANGO_CASHOUT_METHODS = [
),
]
-AMT_ASSIGNMENT_CASHOUT_METHOD = CashoutMethod(
- id=uuid4().hex,
- last_updated="2021-06-23T20:45:38.239182Z",
- is_live=True,
- type=PayoutType.AMT,
- ext_id=None,
- name="AMT Assignment",
- data=AmtCashoutMethodData(),
- user=None,
- min_value=1,
- max_value=5,
-)
+# AMT_ASSIGNMENT_CASHOUT_METHOD = CashoutMethod(
+# id=uuid4().hex,
+# last_updated="2021-06-23T20:45:38.239182Z",
+# is_live=True,
+# type=PayoutType.AMT,
+# ext_id=None,
+# name="AMT Assignment",
+# data=AmtCashoutMethodData(),
+# user=None,
+# min_value=1,
+# max_value=5,
+# )
-AMT_BONUS_CASHOUT_METHOD = CashoutMethod(
- id=uuid4().hex,
- last_updated="2021-06-23T20:45:38.239182Z",
- is_live=True,
- type=PayoutType.AMT,
- ext_id=None,
- name="AMT Bonus",
- data=AmtCashoutMethodData(),
- user=None,
- min_value=7,
- max_value=4000,
-)
+# AMT_BONUS_CASHOUT_METHOD = CashoutMethod(
+# id=uuid4().hex,
+# last_updated="2021-06-23T20:45:38.239182Z",
+# is_live=True,
+# type=PayoutType.AMT,
+# ext_id=None,
+# name="AMT Bonus",
+# data=AmtCashoutMethodData(),
+# user=None,
+# min_value=7,
+# max_value=4000,
+# )
diff --git a/test_utils/managers/conftest.py b/test_utils/managers/conftest.py
index 3a237d1..f1f774e 100644
--- a/test_utils/managers/conftest.py
+++ b/test_utils/managers/conftest.py
@@ -1,4 +1,4 @@
-from typing import Callable, TYPE_CHECKING
+from typing import TYPE_CHECKING, Callable
import pymysql
import pytest
@@ -7,8 +7,6 @@ from generalresearch.managers.base import Permission
from generalresearch.models import Source
from test_utils.managers.cashout_methods import (
EXAMPLE_TANGO_CASHOUT_METHODS,
- AMT_ASSIGNMENT_CASHOUT_METHOD,
- AMT_BONUS_CASHOUT_METHOD,
)
if TYPE_CHECKING:
@@ -21,26 +19,18 @@ if TYPE_CHECKING:
from generalresearch.grliq.managers.forensic_results import (
GrlIqCategoryResultsReader,
)
- from generalresearch.managers.thl.userhealth import AuditLogManager
- from generalresearch.managers.thl.payout import (
- BusinessPayoutEventManager,
- )
- from generalresearch.managers.thl.maxmind.basic import (
- MaxmindBasicManager,
- )
-
from generalresearch.managers.gr.authentication import (
- GRUserManager,
GRTokenManager,
+ GRUserManager,
)
from generalresearch.managers.gr.business import (
- BusinessManager,
BusinessAddressManager,
BusinessBankAccountManager,
+ BusinessManager,
)
from generalresearch.managers.gr.team import (
- TeamManager,
MembershipManager,
+ TeamManager,
)
from generalresearch.managers.thl.contest_manager import ContestManager
from generalresearch.managers.thl.ipinfo import (
@@ -49,22 +39,28 @@ if TYPE_CHECKING:
IPInformationManager,
)
from generalresearch.managers.thl.ledger_manager.ledger import (
- LedgerTransactionManager,
- LedgerManager,
LedgerAccountManager,
+ LedgerManager,
+ LedgerTransactionManager,
)
from generalresearch.managers.thl.ledger_manager.thl_ledger import (
ThlLedgerManager,
)
from generalresearch.managers.thl.maxmind import MaxmindManager
- from generalresearch.managers.thl.payout import PayoutEventManager
+ from generalresearch.managers.thl.maxmind.basic import (
+ MaxmindBasicManager,
+ )
from generalresearch.managers.thl.payout import (
+ BrokerageProductPayoutEventManager,
+ BusinessPayoutEventManager,
PayoutEventManager,
UserPayoutEventManager,
- BrokerageProductPayoutEventManager,
)
from generalresearch.managers.thl.product import ProductManager
from generalresearch.managers.thl.session import SessionManager
+ from generalresearch.managers.thl.task_adjustment import (
+ TaskAdjustmentManager,
+ )
from generalresearch.managers.thl.user_manager.user_manager import (
UserManager,
)
@@ -73,18 +69,14 @@ if TYPE_CHECKING:
)
from generalresearch.managers.thl.userhealth import (
AuditLogManager,
- IPRecordManager,
- UserIpHistoryManager,
IPGeonameManager,
IPInformationManager,
IPRecordManager,
+ UserIpHistoryManager,
)
from generalresearch.managers.thl.wall import (
- WallManager,
WallCacheManager,
- )
- from generalresearch.managers.thl.task_adjustment import (
- TaskAdjustmentManager,
+ WallManager,
)
@@ -539,7 +531,9 @@ def delete_cashoutmethod_db(thl_web_rw) -> Callable:
@pytest.fixture(scope="session")
-def setup_cashoutmethod_db(cashout_method_manager, delete_cashoutmethod_db):
+def setup_cashoutmethod_db(settings, cashout_method_manager, delete_cashoutmethod_db):
+ settings.amt_
+
delete_cashoutmethod_db()
for x in EXAMPLE_TANGO_CASHOUT_METHODS:
cashout_method_manager.create(x)
diff --git a/test_utils/managers/contest/conftest.py b/test_utils/managers/contest/conftest.py
index c2d4ef6..0a25185 100644
--- a/test_utils/managers/contest/conftest.py
+++ b/test_utils/managers/contest/conftest.py
@@ -1,6 +1,6 @@
from datetime import datetime, timezone
from decimal import Decimal
-from typing import Callable, TYPE_CHECKING
+from typing import TYPE_CHECKING, Callable
from uuid import uuid4
import pytest
@@ -8,29 +8,27 @@ import pytest
from generalresearch.currency import USDCent
if TYPE_CHECKING:
- from generalresearch.models.thl.contest.contest import Contest
+ from generalresearch.managers.thl.contest_manager import ContestManager
from generalresearch.models.thl.contest import (
- ContestPrize,
ContestEndCondition,
+ ContestPrize,
)
-
+ from generalresearch.models.thl.contest.contest import Contest
from generalresearch.models.thl.contest.definitions import (
- ContestType,
ContestPrizeKind,
+ ContestType,
)
from generalresearch.models.thl.contest.io import contest_create_to_contest
from generalresearch.models.thl.contest.leaderboard import (
LeaderboardContestCreate,
)
from generalresearch.models.thl.contest.milestone import (
- MilestoneContestCreate,
ContestEntryTrigger,
+ MilestoneContestCreate,
MilestoneContestEndCondition,
)
from generalresearch.models.thl.contest.raffle import (
ContestEntryType,
- )
- from generalresearch.models.thl.contest.raffle import (
RaffleContestCreate,
)
from generalresearch.models.thl.product import Product
@@ -39,19 +37,17 @@ if TYPE_CHECKING:
@pytest.fixture
def raffle_contest_create() -> "RaffleContestCreate":
- from generalresearch.models.thl.contest.raffle import (
- RaffleContestCreate,
- )
from generalresearch.models.thl.contest import (
- ContestPrize,
ContestEndCondition,
+ ContestPrize,
)
from generalresearch.models.thl.contest.definitions import (
- ContestType,
ContestPrizeKind,
+ ContestType,
)
from generalresearch.models.thl.contest.raffle import (
ContestEntryType,
+ RaffleContestCreate,
)
# This is what we'll get from the fastapi endpoint
@@ -74,7 +70,7 @@ def raffle_contest_create() -> "RaffleContestCreate":
def raffle_contest_in_db(
product_user_wallet_yes: "Product",
raffle_contest_create: "RaffleContestCreate",
- contest_manager,
+ contest_manager: "ContestManager",
) -> "Contest":
return contest_manager.create(
product_id=product_user_wallet_yes.uuid, contest_create=raffle_contest_create
@@ -96,16 +92,17 @@ def raffle_contest(
def raffle_contest_factory(
product_user_wallet_yes: "Product",
raffle_contest_create: "RaffleContestCreate",
- contest_manager,
-) -> Callable:
- def _create_contest(**kwargs):
+ contest_manager: "ContestManager",
+) -> Callable[..., "Contest"]:
+
+ def _inner(**kwargs):
raffle_contest_create.update(**kwargs)
return contest_manager.create(
product_id=product_user_wallet_yes.uuid,
contest_create=raffle_contest_create,
)
- return _create_contest
+ return _inner
@pytest.fixture
@@ -114,12 +111,12 @@ def milestone_contest_create() -> "MilestoneContestCreate":
ContestPrize,
)
from generalresearch.models.thl.contest.definitions import (
- ContestType,
ContestPrizeKind,
+ ContestType,
)
from generalresearch.models.thl.contest.milestone import (
- MilestoneContestCreate,
ContestEntryTrigger,
+ MilestoneContestCreate,
MilestoneContestEndCondition,
)
@@ -154,7 +151,7 @@ def milestone_contest_create() -> "MilestoneContestCreate":
def milestone_contest_in_db(
product_user_wallet_yes: "Product",
milestone_contest_create: "MilestoneContestCreate",
- contest_manager,
+ contest_manager: "ContestManager",
) -> "Contest":
return contest_manager.create(
product_id=product_user_wallet_yes.uuid, contest_create=milestone_contest_create
@@ -177,31 +174,32 @@ def milestone_contest(
def milestone_contest_factory(
product_user_wallet_yes: "Product",
milestone_contest_create: "MilestoneContestCreate",
- contest_manager,
-) -> Callable:
- def _create_contest(**kwargs):
+ contest_manager: "ContestManager",
+) -> Callable[..., "Contest"]:
+
+ def _inner(**kwargs):
milestone_contest_create.update(**kwargs)
return contest_manager.create(
product_id=product_user_wallet_yes.uuid,
contest_create=milestone_contest_create,
)
- return _create_contest
+ return _inner
@pytest.fixture
def leaderboard_contest_create(
product_user_wallet_yes: "Product",
) -> "LeaderboardContestCreate":
- from generalresearch.models.thl.contest.leaderboard import (
- LeaderboardContestCreate,
- )
from generalresearch.models.thl.contest import (
ContestPrize,
)
from generalresearch.models.thl.contest.definitions import (
- ContestType,
ContestPrizeKind,
+ ContestType,
+ )
+ from generalresearch.models.thl.contest.leaderboard import (
+ LeaderboardContestCreate,
)
# This is what we'll get from the fastapi endpoint
@@ -232,7 +230,7 @@ def leaderboard_contest_create(
def leaderboard_contest_in_db(
product_user_wallet_yes: "Product",
leaderboard_contest_create: "LeaderboardContestCreate",
- contest_manager,
+ contest_manager: "ContestManager",
) -> "Contest":
return contest_manager.create(
product_id=product_user_wallet_yes.uuid,
@@ -257,21 +255,25 @@ def leaderboard_contest(
def leaderboard_contest_factory(
product_user_wallet_yes: "Product",
leaderboard_contest_create: "LeaderboardContestCreate",
- contest_manager,
-) -> Callable:
- def _create_contest(**kwargs):
+ contest_manager: "ContestManager",
+) -> Callable[..., "Contest"]:
+
+ def _inner(**kwargs):
leaderboard_contest_create.update(**kwargs)
return contest_manager.create(
product_id=product_user_wallet_yes.uuid,
contest_create=leaderboard_contest_create,
)
- return _create_contest
+ return _inner
@pytest.fixture
def user_with_money(
- request, user_factory, product_user_wallet_yes: "Product", thl_lm
+ request,
+ user_factory: Callable[..., "User"],
+ product_user_wallet_yes: "Product",
+ thl_lm,
) -> "User":
from generalresearch.models.thl.user import User
diff --git a/test_utils/managers/ledger/conftest.py b/test_utils/managers/ledger/conftest.py
index b96d612..aafdaf7 100644
--- a/test_utils/managers/ledger/conftest.py
+++ b/test_utils/managers/ledger/conftest.py
@@ -1,25 +1,26 @@
from datetime import datetime
from decimal import Decimal
from random import randint
-from typing import Optional, Dict, Callable, TYPE_CHECKING
+from typing import TYPE_CHECKING, Callable, Dict, Optional
from uuid import uuid4
import pytest
from generalresearch.currency import USDCent
+from generalresearch.managers.base import PostgresManager
from test_utils.models.conftest import (
- product_factory,
- user,
+ payout_config,
product,
- user_factory,
- product_user_wallet_no,
- wall,
product_amt_true,
+ product_factory,
+ product_user_wallet_no,
product_user_wallet_yes,
- session_factory,
session,
+ session_factory,
+ user,
+ user_factory,
+ wall,
wall_factory,
- payout_config,
)
_ = (
@@ -35,24 +36,36 @@ _ = (
)
if TYPE_CHECKING:
+ from datetime import datetime, timedelta
+
from generalresearch.currency import LedgerCurrency
+ from generalresearch.managers.thl.ledger_manager.ledger import LedgerManager
+ from generalresearch.managers.thl.ledger_manager.thl_ledger import (
+ ThlLedgerManager,
+ )
from generalresearch.models.thl.ledger import (
- Direction,
AccountType,
+ Direction,
+ LedgerAccount,
+ LedgerEntry,
LedgerTransaction,
)
- from generalresearch.models.thl.ledger import (
- LedgerEntry,
- LedgerAccount,
+ from generalresearch.models.thl.payout import (
+ BrokerageProductPayoutEvent,
+ UserPayoutEvent,
)
- from generalresearch.models.thl.payout import UserPayoutEvent
+ from generalresearch.models.thl.product import Product
+ from generalresearch.models.thl.session import Session
+ from generalresearch.models.thl.user import User
-@pytest.fixture(scope="function")
-def ledger_account(request, lm, currency) -> "LedgerAccount":
+@pytest.fixture
+def ledger_account(
+ request, lm: "LedgerManager", currency: "LedgerCurrency"
+) -> "LedgerAccount":
from generalresearch.models.thl.ledger import (
- Direction,
AccountType,
+ Direction,
LedgerAccount,
)
@@ -73,19 +86,22 @@ def ledger_account(request, lm, currency) -> "LedgerAccount":
return lm.create_account(account=acct_model)
-@pytest.fixture(scope="function")
-def ledger_account_factory(request, thl_lm, lm, currency) -> Callable:
+@pytest.fixture
+def ledger_account_factory(
+ request, thl_lm: "ThlLedgerManager", lm: "LedgerManager", currency: "LedgerCurrency"
+) -> Callable[..., "LedgerAccount"]:
+
from generalresearch.models.thl.ledger import (
- Direction,
AccountType,
+ Direction,
LedgerAccount,
)
- def _ledger_account_factory(
- product,
+ def _inner(
+ product: "Product",
account_type: AccountType = AccountType.CASH,
direction: Direction = Direction.CREDIT,
- ):
+ ) -> "LedgerAccount":
thl_lm.get_account_or_create_bp_wallet(product=product)
acct_uuid = uuid4().hex
qn = ":".join([currency, account_type, acct_uuid])
@@ -100,12 +116,14 @@ def ledger_account_factory(request, thl_lm, lm, currency) -> Callable:
)
return lm.create_account(account=acct_model)
- return _ledger_account_factory
+ return _inner
-@pytest.fixture(scope="function")
-def ledger_account_credit(request, lm, currency) -> "LedgerAccount":
- from generalresearch.models.thl.ledger import Direction, AccountType
+@pytest.fixture
+def ledger_account_credit(
+ request, lm: "LedgerManager", currency: "LedgerCurrency"
+) -> "LedgerAccount":
+ from generalresearch.models.thl.ledger import AccountType, Direction
account_type = AccountType.REVENUE
acct_uuid = uuid4().hex
@@ -124,9 +142,11 @@ def ledger_account_credit(request, lm, currency) -> "LedgerAccount":
return lm.create_account(account=acct_model)
-@pytest.fixture(scope="function")
-def ledger_account_debit(request, lm, currency) -> "LedgerAccount":
- from generalresearch.models.thl.ledger import Direction, AccountType
+@pytest.fixture
+def ledger_account_debit(
+ request, lm: "LedgerManager", currency: "LedgerCurrency"
+) -> "LedgerAccount":
+ from generalresearch.models.thl.ledger import AccountType, Direction
account_type = AccountType.EXPENSE
acct_uuid = uuid4().hex
@@ -145,8 +165,8 @@ def ledger_account_debit(request, lm, currency) -> "LedgerAccount":
return lm.create_account(account=acct_model)
-@pytest.fixture(scope="function")
-def tag(request, lm) -> str:
+@pytest.fixture
+def tag(request, lm: "LedgerManager") -> str:
from generalresearch.currency import LedgerCurrency
return (
@@ -156,16 +176,20 @@ def tag(request, lm) -> str:
)
-@pytest.fixture(scope="function")
+@pytest.fixture
def usd_cent(request) -> USDCent:
amount = randint(99, 9_999)
return request.param if hasattr(request, "usd_cent") else USDCent(amount)
-@pytest.fixture(scope="function")
+@pytest.fixture
def bp_payout_event(
- product, usd_cent, business_payout_event_manager, thl_lm
+ product: "Product",
+ usd_cent,
+ business_payout_event_manager,
+ thl_lm: "ThlLedgerManager",
) -> "UserPayoutEvent":
+
return business_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_lm,
product=product,
@@ -176,13 +200,18 @@ def bp_payout_event(
@pytest.fixture
-def bp_payout_event_factory(brokerage_product_payout_event_manager, thl_lm) -> Callable:
- from generalresearch.models.thl.product import Product
+def bp_payout_event_factory(
+ brokerage_product_payout_event_manager: "BrokerageProductPayoutEventManager",
+ thl_lm: "ThlLedgerManager",
+) -> Callable[..., "BrokerageProductPayoutEvent"]:
+
from generalresearch.currency import USDCent
+ from generalresearch.models.thl.product import Product
- def _create_bp_payout_event(
+ def _inner(
product: Product, usd_cent: USDCent, ext_ref_id: Optional[str] = None
- ):
+ ) -> "BrokerageProductPayoutEvent":
+
return brokerage_product_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_lm,
product=product,
@@ -192,16 +221,16 @@ def bp_payout_event_factory(brokerage_product_payout_event_manager, thl_lm) -> C
skip_one_per_day_check=True,
)
- return _create_bp_payout_event
+ return _inner
-@pytest.fixture(scope="function")
-def currency(lm) -> "LedgerCurrency":
+@pytest.fixture
+def currency(lm: "LedgerManager") -> "LedgerCurrency":
# return request.param if hasattr(request, "currency") else LedgerCurrency.TEST
return lm.currency
-@pytest.fixture(scope="function")
+@pytest.fixture
def tx_metadata(request) -> Optional[Dict[str, str]]:
return (
request.param
@@ -210,15 +239,15 @@ def tx_metadata(request) -> Optional[Dict[str, str]]:
)
-@pytest.fixture(scope="function")
+@pytest.fixture
def ledger_tx(
request,
ledger_account_credit,
ledger_account_debit,
tag,
- currency,
+ currency: "LedgerCurrency",
tx_metadata,
- lm,
+ lm: "LedgerManager",
) -> "LedgerTransaction":
from generalresearch.models.thl.ledger import Direction, LedgerEntry
@@ -240,13 +269,16 @@ def ledger_tx(
return lm.create_tx(entries=entries, tag=tag, metadata=tx_metadata)
-@pytest.fixture(scope="function")
-def create_main_accounts(lm, currency) -> Callable:
- def _create_main_accounts():
+@pytest.fixture
+def create_main_accounts(
+ lm: "LedgerManager", currency: "LedgerCurrency"
+) -> Callable[..., None]:
+
+ def _inner() -> None:
from generalresearch.models.thl.ledger import (
- LedgerAccount,
- Direction,
AccountType,
+ Direction,
+ LedgerAccount,
)
account = LedgerAccount(
@@ -268,12 +300,15 @@ def create_main_accounts(lm, currency) -> Callable:
lm.get_account_or_create(account=account)
- return _create_main_accounts
+ return None
+
+ return _inner
-@pytest.fixture(scope="function")
-def delete_ledger_db(thl_web_rw) -> Callable:
- def _delete_ledger_db():
+@pytest.fixture
+def delete_ledger_db(thl_web_rw: "PostgresManager") -> Callable[..., None]:
+
+ def _inner():
for table in [
"ledger_transactionmetadata",
"ledger_entry",
@@ -284,12 +319,15 @@ def delete_ledger_db(thl_web_rw) -> Callable:
query=f"DELETE FROM {table};",
)
- return _delete_ledger_db
+ return _inner
+
+@pytest.fixture
+def wipe_main_accounts(
+ thl_web_rw: "PostgresManager", lm: "LedgerManager", currency: "LedgerCurrency"
+) -> Callable[..., None]:
-@pytest.fixture(scope="function")
-def wipe_main_accounts(thl_web_rw, lm, currency) -> Callable:
- def _wipe_main_accounts():
+ def _inner() -> None:
db_table = thl_web_rw.db_name
qual_names = [
f"{currency.value}:revenue:task_complete",
@@ -352,15 +390,17 @@ def wipe_main_accounts(thl_web_rw, lm, currency) -> Callable:
commit=True,
)
- return _wipe_main_accounts
+ return None
+ return _inner
-@pytest.fixture(scope="function")
-def account_cash(lm, currency) -> "LedgerAccount":
+
+@pytest.fixture
+def account_cash(lm: "LedgerManager", currency: "LedgerCurrency") -> "LedgerAccount":
from generalresearch.models.thl.ledger import (
- LedgerAccount,
- Direction,
AccountType,
+ Direction,
+ LedgerAccount,
)
account = LedgerAccount(
@@ -373,12 +413,14 @@ def account_cash(lm, currency) -> "LedgerAccount":
return lm.get_account_or_create(account=account)
-@pytest.fixture(scope="function")
-def account_revenue_task_complete(lm, currency) -> "LedgerAccount":
+@pytest.fixture
+def account_revenue_task_complete(
+ lm: "LedgerManager", currency: "LedgerCurrency"
+) -> "LedgerAccount":
from generalresearch.models.thl.ledger import (
- LedgerAccount,
- Direction,
AccountType,
+ Direction,
+ LedgerAccount,
)
account = LedgerAccount(
@@ -391,12 +433,14 @@ def account_revenue_task_complete(lm, currency) -> "LedgerAccount":
return lm.get_account_or_create(account=account)
-@pytest.fixture(scope="function")
-def account_expense_tango(lm, currency) -> "LedgerAccount":
+@pytest.fixture
+def account_expense_tango(
+ lm: "LedgerManager", currency: "LedgerCurrency"
+) -> "LedgerAccount":
from generalresearch.models.thl.ledger import (
- LedgerAccount,
- Direction,
AccountType,
+ Direction,
+ LedgerAccount,
)
account = LedgerAccount(
@@ -409,12 +453,14 @@ def account_expense_tango(lm, currency) -> "LedgerAccount":
return lm.get_account_or_create(account=account)
-@pytest.fixture(scope="function")
-def user_account_user_wallet(lm, user, currency) -> "LedgerAccount":
+@pytest.fixture
+def user_account_user_wallet(
+ lm: "LedgerManager", user, currency: "LedgerCurrency"
+) -> "LedgerAccount":
from generalresearch.models.thl.ledger import (
- LedgerAccount,
- Direction,
AccountType,
+ Direction,
+ LedgerAccount,
)
account = LedgerAccount(
@@ -429,12 +475,14 @@ def user_account_user_wallet(lm, user, currency) -> "LedgerAccount":
return lm.get_account_or_create(account=account)
-@pytest.fixture(scope="function")
-def product_account_bp_wallet(lm, product, currency) -> "LedgerAccount":
+@pytest.fixture
+def product_account_bp_wallet(
+ lm: "LedgerManager", product: "Product", currency: "LedgerCurrency"
+) -> "LedgerAccount":
from generalresearch.models.thl.ledger import (
- LedgerAccount,
- Direction,
AccountType,
+ Direction,
+ LedgerAccount,
)
account = LedgerAccount.model_validate(
@@ -451,12 +499,17 @@ def product_account_bp_wallet(lm, product, currency) -> "LedgerAccount":
return lm.get_account_or_create(account=account)
-@pytest.fixture(scope="function")
-def setup_accounts(product_factory, lm, user, currency) -> None:
+@pytest.fixture
+def setup_accounts(
+ product_factory: Callable[..., "Product"],
+ lm: "LedgerManager",
+ user: "User",
+ currency: "LedgerCurrency",
+) -> None:
from generalresearch.models.thl.ledger import (
- LedgerAccount,
- Direction,
AccountType,
+ Direction,
+ LedgerAccount,
)
# BP's wallet and a revenue from their commissions account.
@@ -522,24 +575,25 @@ def setup_accounts(product_factory, lm, user, currency) -> None:
lm.get_account_or_create(account=account)
-@pytest.fixture(scope="function")
+@pytest.fixture
def session_with_tx_factory(
- user_factory,
- product,
- session_factory,
+ user_factory: Callable[..., "User"],
+ product: "Product",
+ session_factory: Callable[..., "Session"],
session_manager,
wall_manager,
- utc_hour_ago,
- thl_lm,
-) -> Callable:
+ utc_hour_ago: datetime,
+ thl_lm: "ThlLedgerManager",
+) -> Callable[..., "Session"]:
+
from generalresearch.models.thl.session import (
- Status,
Session,
+ Status,
StatusCode1,
)
from generalresearch.models.thl.user import User
- def _session_with_tx_factory(
+ def _inner(
user: User,
final_status: Status = Status.COMPLETE,
wall_req_cpi: Decimal = Decimal(".50"),
@@ -583,18 +637,21 @@ def session_with_tx_factory(
return s
- return _session_with_tx_factory
+ return _inner
-@pytest.fixture(scope="function")
-def adj_to_fail_with_tx_factory(session_manager, wall_manager, thl_lm) -> Callable:
+@pytest.fixture
+def adj_to_fail_with_tx_factory(
+ session_manager, wall_manager, thl_lm: "ThlLedgerManager"
+) -> Callable[..., None]:
+ from datetime import datetime, timedelta
+
+ from generalresearch.models.thl.definitions import WallAdjustedStatus
from generalresearch.models.thl.session import (
Session,
)
- from datetime import timedelta
- from generalresearch.models.thl.definitions import WallAdjustedStatus
- def _adj_to_fail_with_tx_factory(
+ def _inner(
session: Session,
created: datetime,
) -> None:
@@ -636,18 +693,21 @@ def adj_to_fail_with_tx_factory(session_manager, wall_manager, thl_lm) -> Callab
return None
- return _adj_to_fail_with_tx_factory
+ return _inner
-@pytest.fixture(scope="function")
-def adj_to_complete_with_tx_factory(session_manager, wall_manager, thl_lm) -> Callable:
+@pytest.fixture
+def adj_to_complete_with_tx_factory(
+ session_manager, wall_manager, thl_lm: "ThlLedgerManager"
+) -> Callable[..., None]:
+ from datetime import timedelta
+
+ from generalresearch.models.thl.definitions import WallAdjustedStatus
from generalresearch.models.thl.session import (
Session,
)
- from datetime import timedelta
- from generalresearch.models.thl.definitions import WallAdjustedStatus
- def _adj_to_complete_with_tx_factory(
+ def _inner(
session: Session,
created: datetime,
) -> None:
@@ -675,4 +735,4 @@ def adj_to_complete_with_tx_factory(session_manager, wall_manager, thl_lm) -> Ca
return None
- return _adj_to_complete_with_tx_factory
+ return _inner