aboutsummaryrefslogtreecommitdiff
path: root/tests/managers/thl/test_ledger
diff options
context:
space:
mode:
authorGreg Stupp2026-09-18 22:39:18 +0000
committerGreg Stupp2026-09-18 22:39:18 +0000
commitb373b992cae3a9628a9cf64387c7b8e286d6e1e0 (patch)
tree5e21759ea2c6925e8f54328fbbac88b6be007648 /tests/managers/thl/test_ledger
parent32f30b5ddc600e22e071f7659f1872a18ebf42c7 (diff)
parente3c6a824f4176402e40217c5ce70f837dedc5c3d (diff)
downloadgeneralresearch-3.5.0.tar.gz
generalresearch-3.5.0.zip
Merges pull request #4 v3.5.0
User Cashout Stuff pulled out of grpc, user ip history enrichments with grip (no maxmind)
Diffstat (limited to 'tests/managers/thl/test_ledger')
-rw-r--r--tests/managers/thl/test_ledger/test_lm_tx.py4
-rw-r--r--tests/managers/thl/test_ledger/test_lm_tx_locks.py21
-rw-r--r--tests/managers/thl/test_ledger/test_thl_lm_tx.py27
-rw-r--r--tests/managers/thl/test_ledger/test_thl_pem.py51
4 files changed, 48 insertions, 55 deletions
diff --git a/tests/managers/thl/test_ledger/test_lm_tx.py b/tests/managers/thl/test_ledger/test_lm_tx.py
index 025f6ac..d98b838 100644
--- a/tests/managers/thl/test_ledger/test_lm_tx.py
+++ b/tests/managers/thl/test_ledger/test_lm_tx.py
@@ -206,12 +206,12 @@ class TestLedgerManagerGetTx:
self, ledger_tx: LedgerTransaction, tag: str, ledger_manager: LedgerManager
):
# (1) search for a random tag
- res = ledger_manager.get_tx_by_tag(tag="aaa:bbb")
+ res = ledger_manager.get_txs_by_tag(tag="aaa:bbb")
assert isinstance(res, list)
assert len(res) == 0
# (2) search for the tag that was used during ledger_transaction creation
- res = ledger_manager.get_tx_by_tag(tag=tag)
+ res = ledger_manager.get_txs_by_tag(tag=tag)
assert isinstance(res, list)
assert len(res) == 1
diff --git a/tests/managers/thl/test_ledger/test_lm_tx_locks.py b/tests/managers/thl/test_ledger/test_lm_tx_locks.py
index 166598e..91d9cbc 100644
--- a/tests/managers/thl/test_ledger/test_lm_tx_locks.py
+++ b/tests/managers/thl/test_ledger/test_lm_tx_locks.py
@@ -38,7 +38,6 @@ logger = logging.getLogger("LedgerManager")
class TestLedgerLocks:
-
def test_a(
self,
user_factory: Callable[..., User],
@@ -108,16 +107,16 @@ class TestLedgerLocks:
f1 = generate_condition_mp_payment(wall=w1)
f2 = generate_condition_mp_payment(wall=w2)
f3 = generate_condition_mp_payment(wall=w3)
- assert f1(ledger_manager) is False
- assert f2(lm=ledger_manager) is False
- assert f3(lm=ledger_manager) is True
+ assert f1(ledger_manager) == (False, "duplicate tag")
+ assert f2(lm=ledger_manager) == (False, "duplicate tag")
+ assert f3(lm=ledger_manager)[0] == True
condition = f3
create_tx_func = lambda: thl_ledger_manager.create_tx_task_complete_(
wall=w3, user=user
)
assert isinstance(create_tx_func, Callable)
- assert f3(ledger_manager) is True
+ assert f3(ledger_manager)[0] is True
ledger_manager.redis_client.delete(flag_name)
ledger_manager.redis_client.delete(lock_name)
@@ -125,13 +124,14 @@ class TestLedgerLocks:
tx = thl_ledger_manager.create_tx_protected(
lock_key=lock_key, condition=condition, create_tx_func=create_tx_func
)
- assert f3(ledger_manager) is False
+ assert f3(ledger_manager) == (False, "duplicate tag")
# purposely hold the lock open
tx = None
ledger_manager.redis_client.set(lock_name, "1")
- with caplog.at_level(logging.ERROR), pytest.raises(
- expected_exception=LedgerTransactionCreateLockError
+ with (
+ caplog.at_level(logging.ERROR),
+ pytest.raises(expected_exception=LedgerTransactionCreateLockError),
):
tx = thl_ledger_manager.create_tx_protected(
lock_key=lock_key,
@@ -231,8 +231,9 @@ class TestLedgerLocks:
# Purposely hold the lock open
ledger_manager.redis_client.set(name=lock_name, value="1")
- with caplog.at_level(logging.DEBUG), pytest.raises(
- expected_exception=LedgerTransactionCreateLockError
+ with (
+ caplog.at_level(logging.DEBUG),
+ pytest.raises(expected_exception=LedgerTransactionCreateLockError),
):
tx = thl_ledger_manager.create_tx_task_complete(
wall=wall3, user=user, created=wall3.started
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 96ea0d6..22a7b73 100644
--- a/tests/managers/thl/test_ledger/test_thl_lm_tx.py
+++ b/tests/managers/thl/test_ledger/test_thl_lm_tx.py
@@ -806,6 +806,24 @@ class TestThlLedgerTxManager:
assert thl_ledger_manager.get_session_attempt_credit(session.uuid) == 5
assert thl_ledger_manager.get_user_attempt_credit_balance(user) == 5
+ attempt_credit_account = (
+ thl_ledger_manager.get_account_or_create_user_attempt_credit(user)
+ )
+ user_txs = thl_ledger_manager.get_user_txs(
+ user, account_uuid=attempt_credit_account.uuid
+ )
+ assert user_txs.total == 1
+ assert user_txs.transactions[0].tx_type == TransactionType.USER_ATTEMPT_CREDIT
+ assert user_txs.transactions[0].amount == 5
+ assert user_txs.transactions[0].balance_after == 5
+ assert user_txs.summary.user_attempt_credit.entry_count == 1
+ assert user_txs.summary.user_attempt_credit.total_amount == 5
+
+ user_txs_by_name = thl_ledger_manager.get_user_txs(
+ user, qualified_name=attempt_credit_account.qualified_name
+ )
+ assert user_txs_by_name == user_txs
+
with pytest.raises(
LedgerTransactionConditionFailedError, match=r"^duplicate tag$"
):
@@ -887,6 +905,15 @@ class TestThlLedgerTxManager:
assert thl_ledger_manager.get_user_wallet_balance(user) == round(user_pay * 100)
assert thl_ledger_manager.check_ledger_balanced()
+ attempt_credit_account = (
+ thl_ledger_manager.get_account_or_create_user_attempt_credit(user)
+ )
+ user_txs = thl_ledger_manager.get_user_txs(
+ user, account_uuid=attempt_credit_account.uuid
+ )
+ assert [tx.amount for tx in user_txs.transactions] == [5, -5]
+ assert [tx.balance_after for tx in user_txs.transactions] == [5, 0]
+
def test_bp_payment_with_zero_attempt_credit_balance(
self,
session_factory: Callable[..., Session],
diff --git a/tests/managers/thl/test_ledger/test_thl_pem.py b/tests/managers/thl/test_ledger/test_thl_pem.py
index fb35aa4..348a02d 100644
--- a/tests/managers/thl/test_ledger/test_thl_pem.py
+++ b/tests/managers/thl/test_ledger/test_thl_pem.py
@@ -8,13 +8,9 @@ from uuid import UUID, uuid4
import pytest
from generalresearch.currency import USDCent
-from generalresearch.models.thl.definitions import PayoutStatus
from generalresearch.models.thl.payout import (
BrokerageProductPayoutEvent,
)
-from generalresearch.models.thl.wallet.cashout_method import (
- CashoutRequestInfo,
-)
if TYPE_CHECKING:
from generalresearch.managers.thl.ledger_manager.ledger import LedgerManager
@@ -23,6 +19,7 @@ if TYPE_CHECKING:
)
from generalresearch.managers.thl.payout import (
BrokerageProductPayoutEventManager,
+ BusinessPayoutEventManager,
UserPayoutEventManager,
)
from generalresearch.models.thl.payout import UserPayoutEvent
@@ -30,7 +27,6 @@ if TYPE_CHECKING:
class TestThlPayoutEventManager:
-
def test_get_by_uuid(
self, brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager
):
@@ -50,8 +46,9 @@ class TestThlPayoutEventManager:
bp_payout_event_factory: Callable[..., BrokerageProductPayoutEvent],
thl_ledger_manager: ThlLedgerManager,
brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
+ create_main_accounts,
):
-
+ create_main_accounts()
N_PRODUCTS = randint(3, 10)
N_PAYOUT_EVENTS = randint(3, 10)
amounts = []
@@ -122,38 +119,6 @@ class TestThlPayoutEventManager:
assert len(res) == (N_PRODUCTS * N_PAYOUT_EVENTS)
assert sum([i.amount for i in res]) == sum(amounts)
- @pytest.mark.skip
- def test_get_payout_detail(self, user_payout_event_manager: UserPayoutEventManager):
- """This fails because the description coming back is None, but then
- it tries to return a PayoutEvent which validates that the
- description can't be None
- """
- from generalresearch.models.thl.payout import (
- PayoutType,
- )
-
- rand_amount = randint(a=99, b=999)
-
- pe = user_payout_event_manager.create(
- debit_account_uuid=uuid4().hex,
- account_reference_type="str-type-random",
- account_reference_uuid=uuid4().hex,
- cashout_method_uuid=uuid4().hex,
- description="Best payout !",
- amount=rand_amount,
- status=PayoutStatus.PENDING,
- ext_ref_id="123",
- payout_type=PayoutType.CASH_IN_MAIL,
- request_data={"foo": 123},
- order_data={},
- )
-
- res = user_payout_event_manager.get_payout_detail(pe_uuid=pe.uuid)
- assert isinstance(res, CashoutRequestInfo)
-
- # def test_filter_by(self):
- # raise NotImplementedError
-
def test_create(
self,
user_payout_event_factory: Callable[..., UserPayoutEvent],
@@ -185,6 +150,7 @@ class TestThlPayoutEventManager:
create_main_accounts: Callable[..., None],
thl_ledger_manager: ThlLedgerManager,
brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
+ business_payout_event_manager: BusinessPayoutEventManager,
ledger_manager: LedgerManager,
):
@@ -198,13 +164,13 @@ class TestThlPayoutEventManager:
# Save a Brokerage Product Payout, so we have something in the
# Payout Event table and the respective ledger TX and Entry rows for it
- pe = brokerage_product_payout_event_manager.create_bp_payout_event(
+ bus_pe = business_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_ledger_manager,
product=product,
amount=USDCent(rand_amount),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
+ ext_ref_id=uuid4().hex
)
+ pe = bus_pe.bp_payouts[0]
assert isinstance(pe, BrokerageProductPayoutEvent)
# Now try to query for it!
@@ -215,7 +181,7 @@ class TestThlPayoutEventManager:
res = thl_ledger_manager.get_tx_bp_payouts(account_uuids=[uuid4().hex])
assert len(res) == 0
- # Confirm it added to the users balance. The amount is negative because
+ # Confirm it added to the user's balance. The amount is negative because
# money was sent to the Brokerage product: Product, but they didn't have
# any activity that earned them money
bal = ledger_manager.get_account_balance(account=account_bp_wallet)
@@ -223,7 +189,6 @@ class TestThlPayoutEventManager:
class TestBPPayoutEvent:
-
def test_get_bp_bp_payout_events_for_products(
self,
product_factory: Callable[..., Product],