aboutsummaryrefslogtreecommitdiff
path: root/tests/managers/thl/test_ledger
diff options
context:
space:
mode:
authorMax Nanis2026-08-27 17:46:11 -0700
committerMax Nanis2026-08-27 17:46:11 -0700
commitaeeb7fef2594ccd34fbe96a77f6c5b392299fed7 (patch)
treede0896615df0c9747208fc26eb1ddde60f248286 /tests/managers/thl/test_ledger
parentfdc170938ac4ac8fa5d9d4df1936e6dc0777f291 (diff)
downloadgeneralresearch-aeeb7fef2594ccd34fbe96a77f6c5b392299fed7.tar.gz
generalresearch-aeeb7fef2594ccd34fbe96a77f6c5b392299fed7.zip
Ruff afternoon
Diffstat (limited to 'tests/managers/thl/test_ledger')
-rw-r--r--tests/managers/thl/test_ledger/test_lm_accounts.py2
-rw-r--r--tests/managers/thl/test_ledger/test_lm_tx.py4
-rw-r--r--tests/managers/thl/test_ledger/test_thl_lm_accounts.py11
-rw-r--r--tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py54
-rw-r--r--tests/managers/thl/test_ledger/test_thl_lm_tx.py26
5 files changed, 50 insertions, 47 deletions
diff --git a/tests/managers/thl/test_ledger/test_lm_accounts.py b/tests/managers/thl/test_ledger/test_lm_accounts.py
index 540bea8..7b65b2d 100644
--- a/tests/managers/thl/test_ledger/test_lm_accounts.py
+++ b/tests/managers/thl/test_ledger/test_lm_accounts.py
@@ -63,7 +63,7 @@ class TestLedgerAccountManagerNoResults:
acct_id: UUIDStr,
lm: LedgerManager,
):
- qn = ":".join([currency, kind, acct_id])
+ qn = f"{currency}:{kind}:{acct_id}"
# (1) .get_many_
assert lm.get_account_many_(qualified_names=[qn], raise_on_error=False) == []
diff --git a/tests/managers/thl/test_ledger/test_lm_tx.py b/tests/managers/thl/test_ledger/test_lm_tx.py
index 13495a7..ce609d6 100644
--- a/tests/managers/thl/test_ledger/test_lm_tx.py
+++ b/tests/managers/thl/test_ledger/test_lm_tx.py
@@ -24,8 +24,6 @@ class TestLedgerManagerCreateTx:
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
"""
- acct_uuid = uuid4().hex
-
# (1) With no Permissions defined
test_lm = LedgerManager(
pg_config=ledger_manager.pg_config,
@@ -44,8 +42,6 @@ class TestLedgerManagerCreateTx:
def test_create_assertions(
self,
- ledger_account_debit: LedgerAccount,
- ledger_account_credit: LedgerAccount,
ledger_manager: LedgerManager,
):
with pytest.raises(expected_exception=ValueError) as excinfo:
diff --git a/tests/managers/thl/test_ledger/test_thl_lm_accounts.py b/tests/managers/thl/test_ledger/test_thl_lm_accounts.py
index dce9116..60eb71c 100644
--- a/tests/managers/thl/test_ledger/test_thl_lm_accounts.py
+++ b/tests/managers/thl/test_ledger/test_thl_lm_accounts.py
@@ -229,6 +229,7 @@ class TestThlLedgerManagerAccounts:
# (1) known account and confirm it comes back
res = ledger_manager.get_account(qualified_name=account1.qualified_name)
+ assert isinstance(res, LedgerAccount)
assert account1.model_dump_json() == res.model_dump_json()
# (2) known accounts and confirm they both come back
@@ -291,6 +292,7 @@ class TestThlLedgerManagerAccounts:
assert len(res) == 2
# Confirm an empty array comes back for all unknown qualified names
+ assert isinstance(ledger_manager.currency, LedgerCurrency)
res = ledger_manager.get_accounts_if_exists(
qualified_names=[
f"{ledger_manager.currency.value}:bp_wall:{uuid4().hex}"
@@ -328,7 +330,7 @@ class TestThlLedgerManagerAccounts:
product_uuids=product_uuids
)
assert len(res) == len(product_uuids)
- assert all([isinstance(i, LedgerAccount) for i in res])
+ assert all(isinstance(i, LedgerAccount) for i in res)
class TestLedgerAccountManager:
@@ -351,10 +353,10 @@ class TestLedgerAccountManager:
# First we want to validate that using the get_account method raises
# an error for a random LedgerAccount which we know does not exist.
with pytest.raises(LedgerAccountDoesntExistError):
- lam.get_account(qualified_name=account.qualified_name)
+ ledger_account_manager.get_account(qualified_name=account.qualified_name)
# Now that we know it doesn't exist, get_or_create for it
- instance = lam.get_account_or_create(account=account)
+ instance = ledger_account_manager.get_account_or_create(account=account)
# It should always return
assert isinstance(instance, LedgerAccount)
@@ -364,10 +366,11 @@ class TestLedgerAccountManager:
self,
user: User,
thl_ledger_manager: ThlLedgerManager,
- ledger_manager: LedgerManager,
ledger_account_manager: LedgerAccountManager,
):
+ assert isinstance(user.product, Product)
+
with pytest.raises(LedgerAccountDoesntExistError):
ledger_account_manager.get_account(
qualified_name=f"test:bp_wallet:{user.product.id}"
diff --git a/tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py b/tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py
index e4a25a3..b518453 100644
--- a/tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py
+++ b/tests/managers/thl/test_ledger/test_thl_lm_bp_payout.py
@@ -133,16 +133,17 @@ class TestThlLedgerManagerBPPayout:
)
payoutevent_uuid = uuid4().hex
- with caplog.at_level(logging.INFO):
- with pytest.raises(LedgerTransactionConditionFailedError):
- thl_ledger_manager.create_tx_bp_payout(
- user.product,
- amount=USDCent(10_000),
- created=now + timedelta(minutes=2),
- skip_one_per_day_check=True,
- skip_wallet_balance_check=False,
- payoutevent_uuid=payoutevent_uuid,
- )
+ with caplog.at_level(logging.INFO), pytest.raises(
+ LedgerTransactionConditionFailedError
+ ):
+ thl_ledger_manager.create_tx_bp_payout(
+ user.product,
+ amount=USDCent(10_000),
+ created=now + timedelta(minutes=2),
+ skip_one_per_day_check=True,
+ skip_wallet_balance_check=False,
+ payoutevent_uuid=payoutevent_uuid,
+ )
assert "failed condition check balance:" in caplog.text
thl_ledger_manager.create_tx_bp_payout(
@@ -197,17 +198,18 @@ class TestThlLedgerManagerBPPayout:
assert balance == int(rand_amount) * -1
# Test some basic assertions
- with caplog.at_level(logging.INFO):
- with pytest.raises(expected_exception=Exception):
- thl_ledger_manager.create_tx_bp_payout(
- product=product,
- amount=rand_amount,
- payoutevent_uuid=uuid4().hex,
- created=datetime.now(tz=UTC),
- skip_wallet_balance_check=False,
- skip_one_per_day_check=False,
- skip_flag_check=False,
- )
+ with caplog.at_level(logging.INFO), pytest.raises(
+ expected_exception=ValueError
+ ):
+ thl_ledger_manager.create_tx_bp_payout(
+ product=product,
+ amount=rand_amount,
+ payoutevent_uuid=uuid4().hex,
+ created=datetime.now(tz=UTC),
+ skip_wallet_balance_check=False,
+ skip_one_per_day_check=False,
+ skip_flag_check=False,
+ )
assert "failed condition check >1 tx per day" in caplog.text
def test_create_tx_redis_failure(
@@ -291,7 +293,7 @@ class TestThlLedgerManagerBPPayout:
# Will fail due to multiple per day
payoutevent_uuid2 = uuid4().hex
with pytest.raises(expected_exception=Exception) as e:
- tx = thl_ledger_manager.create_tx_bp_payout(
+ thl_ledger_manager.create_tx_bp_payout(
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid2,
@@ -348,7 +350,7 @@ class TestThlLedgerManagerBPPayout:
# Create TX will fail on lock exit, after the tx was created!
with pytest.raises(expected_exception=Exception) as e:
- tx = thl_ledger_manager.create_tx_bp_payout(
+ thl_ledger_manager.create_tx_bp_payout(
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
@@ -384,7 +386,9 @@ class TestPayoutEventManagerBPPayout:
product, rand_amount, now, direction=Direction.CREDIT
)
assert thl_ledger_manager.get_account_balance(bp_wallet_account) == rand_amount
- brokerage_product_payout_event_manager.set_account_lookup_table(thl_lm=thl_lm)
+ brokerage_product_payout_event_manager.set_account_lookup_table(
+ thl_lm=thl_ledger_manager
+ )
pe = brokerage_product_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_ledger_manager,
@@ -557,7 +561,7 @@ class TestPayoutEventManagerBPPayout:
# Will fail on lock exit, after the tx was created!
# But it'll see that the tx was created and so everything will be fine
Lock.release = broken_release
- pe = brokerage_product_payout_event_manager.create_bp_payout_event(
+ brokerage_product_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_ledger_manager,
product=product,
created=now,
diff --git a/tests/managers/thl/test_ledger/test_thl_lm_tx.py b/tests/managers/thl/test_ledger/test_thl_lm_tx.py
index 89adb0b..1860d6d 100644
--- a/tests/managers/thl/test_ledger/test_thl_lm_tx.py
+++ b/tests/managers/thl/test_ledger/test_thl_lm_tx.py
@@ -23,7 +23,6 @@ from generalresearch.models.thl.definitions import (
WALL_ALLOWED_STATUS_STATUS_CODE,
)
from generalresearch.models.thl.ledger import (
- AccountType,
Direction,
LedgerAccount,
TransactionType,
@@ -287,17 +286,18 @@ class TestThlLedgerTxManager:
assert balance == int(rand_amount) * -1
# Test some basic assertions
- with caplog.at_level(logging.INFO):
- with pytest.raises(expected_exception=Exception):
- thl_ledger_manager.create_tx_bp_payout(
- product=product,
- amount=rand_amount,
- payoutevent_uuid=uuid4().hex,
- created=datetime.now(tz=UTC),
- skip_wallet_balance_check=False,
- skip_one_per_day_check=False,
- skip_flag_check=False,
- )
+ with caplog.at_level(logging.INFO), pytest.raises(
+ expected_exception=ValueError
+ ):
+ thl_ledger_manager.create_tx_bp_payout(
+ product=product,
+ amount=rand_amount,
+ payoutevent_uuid=uuid4().hex,
+ created=datetime.now(tz=UTC),
+ skip_wallet_balance_check=False,
+ skip_one_per_day_check=False,
+ skip_flag_check=False,
+ )
assert "failed condition check >1 tx per day" in caplog.text
def test_create_tx_bp_payout_(
@@ -1794,7 +1794,7 @@ class TestThlLedgerManagerAdj:
)
thl_ledger_manager.create_tx_bp_payment(session, created=wall1.started)
- revenue = ththl_ledger_managerl_lm.get_account_task_complete_revenue()
+ revenue = thl_ledger_manager.get_account_task_complete_revenue()
bp_wallet_account = thl_ledger_manager.get_account_or_create_bp_wallet(
user.product
)