aboutsummaryrefslogtreecommitdiff
path: root/tests/managers/thl
diff options
context:
space:
mode:
Diffstat (limited to 'tests/managers/thl')
-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_pem.py14
-rw-r--r--tests/managers/thl/test_payout.py30
-rw-r--r--tests/managers/thl/test_session_manager.py6
-rw-r--r--tests/managers/thl/test_survey_penalty.py2
-rw-r--r--tests/managers/thl/test_user_manager/test_base.py28
-rw-r--r--tests/managers/thl/test_user_manager/test_redis.py15
-rw-r--r--tests/managers/thl/test_userhealth.py2
9 files changed, 57 insertions, 65 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_pem.py b/tests/managers/thl/test_ledger/test_thl_pem.py
index 2d03b25..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
@@ -153,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,
):
@@ -166,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!
@@ -183,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)
diff --git a/tests/managers/thl/test_payout.py b/tests/managers/thl/test_payout.py
index a9cd52a..be121d8 100644
--- a/tests/managers/thl/test_payout.py
+++ b/tests/managers/thl/test_payout.py
@@ -388,7 +388,7 @@ class TestBusinessPayoutEventManager:
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
gr_business.prebuild_balance(
- thl_pg_config=thl_web_rr,
+ product_manager=product_manager,
lm=thl_ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
@@ -472,6 +472,7 @@ class TestBusinessPayoutEventManager:
self, business_payout_event_manager: BusinessPayoutEventManager, request
):
# TODO: Generate this file at random
+ # @max file is not commited
fp = os.path.join(
request.config.rootpath, "data/pytest_recoup_proportional.csv"
)
@@ -690,7 +691,7 @@ class TestBusinessPayoutEventManager:
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
gr_business.prebuild_balance(
- thl_pg_config=thl_web_rr,
+ product_manager=product_manager,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
@@ -862,18 +863,18 @@ class TestBusinessPayoutEventManager:
assert gr_business.payouts is None
gr_business.prebuild_payouts(
- thl_pg_config=thl_web_rr,
- thl_lm=thl_ledger_manager,
bpem=business_payout_event_manager,
)
assert isinstance(gr_business.payouts, list)
assert len(gr_business.payouts) == 1
assert gr_business.payouts[0].ext_ref_id == ach_id1
+ ach_id2 = uuid4().hex
+
bp1 = business_payout_event_manager.create_from_ach_or_wire(
business=gr_business,
amount=USDCent(bb1.available_balance),
- transaction_id=ach_id1,
+ transaction_id=ach_id2,
pm=product_manager,
thl_lm=thl_ledger_manager,
created=start + timedelta(days=1, hours=5),
@@ -885,16 +886,12 @@ class TestBusinessPayoutEventManager:
bp1_tx = brokerage_product_payout_event_manager.check_for_ledger_tx(
thl_ledger_manager=thl_ledger_manager,
payout_event=bp1.bp_payouts[0],
- product_id=bp1.bp_payouts[0].product_id,
- amount=bp1.bp_payouts[0].amount,
)
assert bp1_tx
bp2_tx = brokerage_product_payout_event_manager.check_for_ledger_tx(
thl_ledger_manager=thl_ledger_manager,
payout_event=bp1.bp_payouts[1],
- product_id=bp1.bp_payouts[1].product_id,
- amount=bp1.bp_payouts[1].amount,
)
assert bp2_tx
@@ -996,13 +993,12 @@ class TestBusinessPayoutEventManager:
wall_req_cpi=Decimal("50.00"),
started=start + timedelta(days=1, hours=2, minutes=1 + idx),
)
- payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
# Now that we paid out the business: Business, let's confirm the updated balances
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
gr_business.prebuild_balance(
- thl_pg_config=thl_web_rr,
+ product_manager=product_manager,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
@@ -1042,6 +1038,7 @@ class TestBusinessPayoutEventManager:
pm=product_manager,
thl_lm=thl_ledger_manager,
created=start + timedelta(days=1, hours=3),
+ transaction_id=uuid4().hex,
)
assert isinstance(bp1, BusinessPayoutEvent)
assert len(bp1.bp_payouts) == 3
@@ -1057,7 +1054,7 @@ class TestBusinessPayoutEventManager:
# balance.available_balance are reflective of having a $250 ACH/Wire
# sent to the Business
gr_business.prebuild_balance(
- thl_pg_config=thl_web_rr,
+ product_manager=product_manager,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
@@ -1123,14 +1120,13 @@ class TestBusinessPayoutEventManager:
wall_req_cpi=Decimal("7.50"),
started=start + timedelta(days=1, hours=1 + iidx, minutes=1 + idx),
)
- payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
rm_ledger_collection()
rm_pop_ledger_merge()
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
gr_business.prebuild_balance(
- thl_pg_config=thl_web_rr,
+ product_manager=product_manager,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
@@ -1151,7 +1147,7 @@ class TestBusinessPayoutEventManager:
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
gr_business.prebuild_balance(
- thl_pg_config=thl_web_rr,
+ product_manager=product_manager,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
@@ -1175,12 +1171,10 @@ class TestBusinessPayoutEventManager:
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
gr_business.prebuild_payouts(
- thl_pg_config=thl_web_rr,
- thl_lm=thl_ledger_manager,
bpem=business_payout_event_manager,
)
gr_business.prebuild_balance(
- thl_pg_config=thl_web_rr,
+ product_manager=product_manager,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
diff --git a/tests/managers/thl/test_session_manager.py b/tests/managers/thl/test_session_manager.py
index 60edcb9..4b122ec 100644
--- a/tests/managers/thl/test_session_manager.py
+++ b/tests/managers/thl/test_session_manager.py
@@ -117,6 +117,7 @@ class TestSessionManagerFilter:
def test_team(
self,
product_factory: Callable[..., Product],
+ product_manager,
user_factory: Callable[..., User],
gr_team: Team,
session_manager: SessionManager,
@@ -129,7 +130,7 @@ class TestSessionManagerFilter:
u = user_factory(product=p1)
session_manager.create(started=utc_hour_ago, user=u, uuid_id=uuid4().hex)
- gr_team.prefetch_products(thl_pg_config=thl_web_rr)
+ gr_team.prefetch_products(product_manager=product_manager)
assert len(gr_team.product_uuids) == 1
res = session_manager.filter(product_uuids=gr_team.product_uuids)
assert len(res) == 5
@@ -142,6 +143,7 @@ class TestSessionManagerFilter:
session_manager: SessionManager,
utc_hour_ago: datetime,
thl_web_rr: PostgresConfig,
+ product_manager,
):
p1 = product_factory(business=gr_business)
@@ -149,7 +151,7 @@ class TestSessionManagerFilter:
u = user_factory(product=p1)
session_manager.create(started=utc_hour_ago, user=u, uuid_id=uuid4().hex)
- gr_business.prefetch_products(thl_pg_config=thl_web_rr)
+ gr_business.prefetch_products(product_manager=product_manager)
assert len(gr_business.product_uuids) == 1
res = session_manager.filter(product_uuids=gr_business.product_uuids)
assert len(res) == 5
diff --git a/tests/managers/thl/test_survey_penalty.py b/tests/managers/thl/test_survey_penalty.py
index 04f69d2..71cea16 100644
--- a/tests/managers/thl/test_survey_penalty.py
+++ b/tests/managers/thl/test_survey_penalty.py
@@ -103,7 +103,7 @@ class TestSurveyPenalty:
assert res == {"t:a": 0.1, "t:b": 0.2, "u:b": 0.1}
assert surveypenalty_manager.cache.currsize == 1
cached_key = tuple(list(next(iter(surveypenalty_manager.cache.keys())))[1:])
- assert cached_key == ("product_id", product_uuid, "team_id", team_id_random)
+ assert cached_key == (("product_id", product_uuid), ("team_id", team_id_random))
# Both don't exist, return nothing
res = surveypenalty_manager.get_penalties_for(
diff --git a/tests/managers/thl/test_user_manager/test_base.py b/tests/managers/thl/test_user_manager/test_base.py
index 5d12052..2a7e879 100644
--- a/tests/managers/thl/test_user_manager/test_base.py
+++ b/tests/managers/thl/test_user_manager/test_base.py
@@ -56,43 +56,43 @@ class TestUserManager:
def test_get_user_no_inmemory(self):
self.user_manager.clear_user_inmemory_cache(self.user)
- self.user_manager.get_user.__wrapped__.cache_clear()
+ self.user_manager.cache_clear()
u = self.user_manager.get_user(user_id=self.user.user_id)
# this should hit mysql
assert u == self.user
- cache_info = self.user_manager.get_user.__wrapped__.cache_info()
- assert cache_info.hits == 0, cache_info
- assert cache_info.misses == 1, cache_info
+ cache_info = self.user_manager.cache_info()
+ assert cache_info['hits'] == 0, cache_info
+ assert cache_info['misses'] == 1, cache_info
# this should hit the lru cache
u = self.user_manager.get_user(user_id=self.user.user_id)
assert u == self.user
- cache_info = self.user_manager.get_user.__wrapped__.cache_info()
- assert cache_info.hits == 1, cache_info
- assert cache_info.misses == 1, cache_info
+ cache_info = self.user_manager.cache_info()
+ assert cache_info['hits'] == 1, cache_info
+ assert cache_info['misses'] == 1, cache_info
def test_get_user_with_inmemory(self):
# user_manager = self.get_user_manager()
self.user_manager.set_user_inmemory_cache(self.user)
- self.user_manager.get_user.__wrapped__.cache_clear()
+ self.user_manager.cache_clear()
u = self.user_manager.get_user(user_id=self.user.user_id)
# this should hit inmemory cache
assert u == self.user
- cache_info = self.user_manager.get_user.__wrapped__.cache_info()
- assert cache_info.hits == 0, cache_info
- assert cache_info.misses == 1, cache_info
+ cache_info = self.user_manager.cache_info()
+ assert cache_info['hits'] == 0, cache_info
+ assert cache_info['misses'] == 1, cache_info
# this should hit the lru cache
u = self.user_manager.get_user(user_id=self.user.user_id)
assert u == self.user
- cache_info = self.user_manager.get_user.__wrapped__.cache_info()
- assert cache_info.hits == 1, cache_info
- assert cache_info.misses == 1, cache_info
+ cache_info = self.user_manager.cache_info()
+ assert cache_info['hits'] == 1, cache_info
+ assert cache_info['misses'] == 1, cache_info
class TestBlockUserManager:
diff --git a/tests/managers/thl/test_user_manager/test_redis.py b/tests/managers/thl/test_user_manager/test_redis.py
index f6b59c9..89d0a7a 100644
--- a/tests/managers/thl/test_user_manager/test_redis.py
+++ b/tests/managers/thl/test_user_manager/test_redis.py
@@ -8,15 +8,14 @@ from generalresearch.managers.base import Permission
from generalresearch.managers.thl.user_manager.redis_user_manager import (
RedisUserManager,
)
+from generalresearch.redis_helper import RedisConfig
if TYPE_CHECKING:
- from generalresearch.config import GRLBaseSettings
from generalresearch.models.thl.user import User
from generalresearch.pg_helper import PostgresConfig
class TestUserManagerRedis:
-
def test_get_notset(self, redis_user_manager: RedisUserManager, user: User):
redis_user_manager.clear_user(user=user)
assert redis_user_manager.get_user(user_id=user.user_id) is None
@@ -48,10 +47,10 @@ class TestUserManagerRedis:
def test_get_with_cache_prefix(
self,
- settings: GRLBaseSettings,
user: User,
thl_web_rw: PostgresConfig,
thl_web_rr: PostgresConfig,
+ thl_redis_config: RedisConfig,
):
"""
Confirm the prefix functionality is working; we do this so it
@@ -67,19 +66,19 @@ class TestUserManagerRedis:
pg_config=thl_web_rw,
pg_config_rr=thl_web_rr,
sql_permissions=[Permission.UPDATE, Permission.CREATE],
- redis=settings.redis,
- redis_timeout=settings.redis_timeout,
+ redis=thl_redis_config.dsn,
+ redis_timeout=1,
)
um2 = UserManager(
pg_config=thl_web_rw,
pg_config_rr=thl_web_rr,
sql_permissions=[Permission.UPDATE, Permission.CREATE],
- redis=settings.redis,
- redis_timeout=settings.redis_timeout,
+ redis=thl_redis_config.dsn,
+ redis_timeout=1,
cache_prefix="user-lookup-v2",
)
-
+ user = user.to_user_ref()
um1.get_or_create_user(
product_id=user.product_id, product_user_id=user.product_user_id
)
diff --git a/tests/managers/thl/test_userhealth.py b/tests/managers/thl/test_userhealth.py
index 8256185..bd2152a 100644
--- a/tests/managers/thl/test_userhealth.py
+++ b/tests/managers/thl/test_userhealth.py
@@ -226,13 +226,11 @@ class TestIPRecordManager:
self,
thl_web_rr: PostgresConfig,
thl_redis_config: RedisConfig,
- geoip_info_manager: GeoIpInfoManager,
ip_record_manager: IPRecordManager,
):
instance = IPRecordManager(
pg_config=thl_web_rr,
redis_config=thl_redis_config,
- geoip_info_manager=geoip_info_manager,
)
assert isinstance(instance, IPRecordManager)
assert isinstance(ip_record_manager, IPRecordManager)