aboutsummaryrefslogtreecommitdiff
path: root/tests/managers/thl/test_ledger/test_lm_accounts.py
diff options
context:
space:
mode:
authorstuppie2026-09-07 11:47:43 -0600
committerstuppie2026-09-07 11:47:43 -0600
commit092960233652cce1f4dc7841856034a6635e9cd9 (patch)
tree46e5fcd4d1e1b7ed0b987980c6c67ffa6e6b45c7 /tests/managers/thl/test_ledger/test_lm_accounts.py
parent80fd8aab4c7271ddb619b0de18741d7ac77b490b (diff)
parent242579a44855873d5e054e375440e9d3492cd682 (diff)
downloadgeneralresearch-092960233652cce1f4dc7841856034a6635e9cd9.tar.gz
generalresearch-092960233652cce1f4dc7841856034a6635e9cd9.zip
Merge branch 'master' into dev-greg
Diffstat (limited to 'tests/managers/thl/test_ledger/test_lm_accounts.py')
-rw-r--r--tests/managers/thl/test_ledger/test_lm_accounts.py162
1 files changed, 84 insertions, 78 deletions
diff --git a/tests/managers/thl/test_ledger/test_lm_accounts.py b/tests/managers/thl/test_ledger/test_lm_accounts.py
index 5cfaac1..3af10e7 100644
--- a/tests/managers/thl/test_ledger/test_lm_accounts.py
+++ b/tests/managers/thl/test_ledger/test_lm_accounts.py
@@ -1,9 +1,12 @@
+from __future__ import annotations
+
from itertools import product as iproduct
from random import randint
-from typing import TYPE_CHECKING, Callable
+from typing import TYPE_CHECKING
from uuid import uuid4
import pytest
+from pydantic import PositiveInt
from generalresearch.currency import LedgerCurrency
from generalresearch.managers.base import Permission
@@ -11,6 +14,7 @@ from generalresearch.managers.thl.ledger_manager.exceptions import (
LedgerAccountDoesntExistError,
)
from generalresearch.managers.thl.ledger_manager.ledger import LedgerManager
+from generalresearch.models.custom_types import UUIDStr
from generalresearch.models.thl.ledger import (
AccountType,
Direction,
@@ -19,22 +23,10 @@ from generalresearch.models.thl.ledger import (
)
if TYPE_CHECKING:
- from pydantic import PositiveInt
- from generalresearch.config import GRLSettings
- from generalresearch.currency import LedgerCurrency
- from generalresearch.managers.thl.ledger_manager.ledger import LedgerManager
- from generalresearch.models.custom_types import AccountType, Direction, UUIDStr
- from generalresearch.models.thl import Direction
from generalresearch.models.thl.ledger import (
- AccountType,
- LedgerAccount,
LedgerTransaction,
)
- 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(
@@ -51,53 +43,63 @@ class TestLedgerAccountManagerNoResults:
def test_get_account_no_results(
self,
- currency: "LedgerCurrency",
+ currency: LedgerCurrency,
kind: str,
- acct_id: "UUIDStr",
- lm: "LedgerManager",
+ acct_id: UUIDStr,
+ ledger_manager: LedgerManager,
):
"""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
"""
- qn = ":".join([currency, kind, acct_id])
+ qn = f"{currency}:{kind}:{acct_id}"
# (1) .get_account is just a wrapper for .get_account_many_ but
# call it either way
- assert lm.get_account(qualified_name=qn, raise_on_error=False) is None
+ assert (
+ ledger_manager.get_account(qualified_name=qn, raise_on_error=False) is None
+ )
with pytest.raises(expected_exception=LedgerAccountDoesntExistError):
- lm.get_account(qualified_name=qn, raise_on_error=True)
+ ledger_manager.get_account(qualified_name=qn, raise_on_error=True)
# (2) .get_account_if_exists is another wrapper
- assert lm.get_account(qualified_name=qn, raise_on_error=False) is None
+ assert (
+ ledger_manager.get_account(qualified_name=qn, raise_on_error=False) is None
+ )
def test_get_account_no_results_many(
self,
- currency: "LedgerCurrency",
+ currency: LedgerCurrency,
kind: str,
- acct_id: "UUIDStr",
- lm: "LedgerManager",
+ acct_id: UUIDStr,
+ ledger_manager: 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) == []
+ assert (
+ ledger_manager.get_account_many_(qualified_names=[qn], raise_on_error=False)
+ == []
+ )
with pytest.raises(expected_exception=LedgerAccountDoesntExistError):
- lm.get_account_many_(qualified_names=[qn], raise_on_error=True)
+ ledger_manager.get_account_many_(qualified_names=[qn], raise_on_error=True)
# (2) .get_many
- assert lm.get_account_many(qualified_names=[qn], raise_on_error=False) == []
+ assert (
+ ledger_manager.get_account_many(qualified_names=[qn], raise_on_error=False)
+ == []
+ )
with pytest.raises(expected_exception=LedgerAccountDoesntExistError):
- lm.get_account_many(qualified_names=[qn], raise_on_error=True)
+ ledger_manager.get_account_many(qualified_names=[qn], raise_on_error=True)
# (3) .get_accounts(..)
- assert lm.get_accounts_if_exists(qualified_names=[qn]) == []
+ assert ledger_manager.get_accounts_if_exists(qualified_names=[qn]) == []
with pytest.raises(expected_exception=LedgerAccountDoesntExistError):
- lm.get_accounts(qualified_names=[qn])
+ ledger_manager.get_accounts(qualified_names=[qn])
@pytest.mark.parametrize(
@@ -114,10 +116,10 @@ class TestLedgerAccountManagerCreate:
def test_create_account_error_permission(
self,
- currency: "LedgerCurrency",
- account_type: "AccountType",
- direction: "Direction",
- lm: "LedgerManager",
+ currency: LedgerCurrency,
+ account_type: AccountType,
+ direction: Direction,
+ ledger_manager: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -134,11 +136,11 @@ class TestLedgerAccountManagerCreate:
# (1) With no Permissions defined
test_lm = LedgerManager(
- pg_config=lm.pg_config,
+ pg_config=ledger_manager.pg_config,
permissions=[],
- redis_config=lm.redis_config,
- cache_prefix=lm.cache_prefix,
- testing=lm.testing,
+ redis_config=ledger_manager.redis_config,
+ cache_prefix=ledger_manager.cache_prefix,
+ testing=ledger_manager.testing,
)
with pytest.raises(expected_exception=AssertionError) as excinfo:
@@ -149,11 +151,11 @@ class TestLedgerAccountManagerCreate:
# (2) With Permissions defined, but not CREATE
test_lm = LedgerManager(
- pg_config=lm.pg_config,
+ pg_config=ledger_manager.pg_config,
permissions=[Permission.READ, Permission.UPDATE, Permission.DELETE],
- redis_config=lm.redis_config,
- cache_prefix=lm.cache_prefix,
- testing=lm.testing,
+ redis_config=ledger_manager.redis_config,
+ cache_prefix=ledger_manager.cache_prefix,
+ testing=ledger_manager.testing,
)
with pytest.raises(expected_exception=AssertionError) as excinfo:
@@ -164,10 +166,10 @@ class TestLedgerAccountManagerCreate:
def test_create(
self,
- currency: "LedgerCurrency",
- account_type: "AccountType",
- direction: "Direction",
- lm: "LedgerManager",
+ currency: LedgerCurrency,
+ account_type: AccountType,
+ direction: Direction,
+ ledger_manager: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -184,20 +186,20 @@ class TestLedgerAccountManagerCreate:
account_type=account_type,
normal_balance=direction,
)
- account = lm.create_account(account=acct_model)
+ account = ledger_manager.create_account(account=acct_model)
assert isinstance(account, LedgerAccount)
# Query for, and make sure the Account was saved in the DB
- res = lm.get_account(qualified_name=qn, raise_on_error=True)
+ res = ledger_manager.get_account(qualified_name=qn, raise_on_error=True)
assert res is not None
assert account.uuid == res.uuid
def test_get_or_create(
self,
- currency: "LedgerCurrency",
- account_type: "AccountType",
- direction: "Direction",
- lm: "LedgerManager",
+ currency: LedgerCurrency,
+ account_type: AccountType,
+ direction: Direction,
+ ledger_manager: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -214,27 +216,31 @@ class TestLedgerAccountManagerCreate:
account_type=account_type,
normal_balance=direction,
)
- account = lm.get_account_or_create(account=acct_model)
+ account = ledger_manager.get_account_or_create(account=acct_model)
assert isinstance(account, LedgerAccount)
# Query for, and make sure the Account was saved in the DB
- res = lm.get_account(qualified_name=qn, raise_on_error=True)
+ res = ledger_manager.get_account(qualified_name=qn, raise_on_error=True)
assert res is not None
assert account.uuid == res.uuid
class TestLedgerAccountManagerGet:
- def test_get(self, ledger_account: "LedgerAccount", lm: "LedgerManager"):
- res = lm.get_account(qualified_name=ledger_account.qualified_name)
+ def test_get(self, ledger_account: LedgerAccount, ledger_manager: LedgerManager):
+ res = ledger_manager.get_account(qualified_name=ledger_account.qualified_name)
assert res is not None
assert res.uuid == ledger_account.uuid
- res = lm.get_account_many(qualified_names=[ledger_account.qualified_name])
+ res = ledger_manager.get_account_many(
+ qualified_names=[ledger_account.qualified_name]
+ )
assert len(res) == 1
assert res[0].uuid == ledger_account.uuid
- res = lm.get_accounts(qualified_names=[ledger_account.qualified_name])
+ res = ledger_manager.get_accounts(
+ qualified_names=[ledger_account.qualified_name]
+ )
assert len(res) == 1
assert res[0].uuid == ledger_account.uuid
@@ -243,30 +249,30 @@ class TestLedgerAccountManagerGet:
def test_get_balance_empty(
self,
- ledger_account: "LedgerAccount",
- ledger_account_credit: "LedgerAccount",
- ledger_account_debit: "LedgerAccount",
- ledger_tx: "LedgerTransaction",
- lm: "LedgerManager",
+ ledger_account: LedgerAccount,
+ ledger_account_credit: LedgerAccount,
+ ledger_account_debit: LedgerAccount,
+ ledger_tx: LedgerTransaction,
+ ledger_manager: LedgerManager,
):
- res = lm.get_account_balance(account=ledger_account)
+ res = ledger_manager.get_account_balance(account=ledger_account)
assert res == 0
- res = lm.get_account_balance(account=ledger_account_credit)
+ res = ledger_manager.get_account_balance(account=ledger_account_credit)
assert res == 100
- res = lm.get_account_balance(account=ledger_account_debit)
+ res = ledger_manager.get_account_balance(account=ledger_account_debit)
assert res == 100
@pytest.mark.parametrize("n_times", range(5))
def test_get_account_filtered_balance(
self,
- ledger_account: "LedgerAccount",
- ledger_account_credit: "LedgerAccount",
- ledger_account_debit: "LedgerAccount",
- ledger_tx: "LedgerTransaction",
- n_times: "PositiveInt",
- lm: "LedgerManager",
+ ledger_account: LedgerAccount,
+ ledger_account_credit: LedgerAccount,
+ ledger_account_debit: LedgerAccount,
+ ledger_tx: LedgerTransaction,
+ n_times: PositiveInt,
+ ledger_manager: LedgerManager,
):
"""Try searching for random metadata and confirm it's always 0 because
Tx can be found.
@@ -275,7 +281,7 @@ class TestLedgerAccountManagerGet:
rand_value = uuid4().hex
assert (
- lm.get_account_filtered_balance(
+ ledger_manager.get_account_filtered_balance(
account=ledger_account, metadata_key=rand_key, metadata_value=rand_value
)
== 0
@@ -285,7 +291,7 @@ class TestLedgerAccountManagerGet:
# and that we can filter it back
rand_amount = randint(10, 1_000)
- lm.create_tx(
+ ledger_manager.create_tx(
entries=[
LedgerEntry(
direction=Direction.CREDIT,
@@ -302,7 +308,7 @@ class TestLedgerAccountManagerGet:
)
assert (
- lm.get_account_filtered_balance(
+ ledger_manager.get_account_filtered_balance(
account=ledger_account_credit,
metadata_key=rand_key,
metadata_value=rand_value,
@@ -311,7 +317,7 @@ class TestLedgerAccountManagerGet:
)
assert (
- lm.get_account_filtered_balance(
+ ledger_manager.get_account_filtered_balance(
account=ledger_account_debit,
metadata_key=rand_key,
metadata_value=rand_value,
@@ -320,7 +326,7 @@ class TestLedgerAccountManagerGet:
)
def test_get_balance_timerange_empty(
- self, ledger_account: "LedgerAccount", lm: "LedgerManager"
+ self, ledger_account: LedgerAccount, ledger_manager: LedgerManager
):
- res = lm.get_account_balance_timerange(account=ledger_account)
+ res = ledger_manager.get_account_balance_timerange(account=ledger_account)
assert res == 0