aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuppie2026-09-18 14:56:36 -0600
committerstuppie2026-09-18 14:56:36 -0600
commitf4909f0fafd6161dd423859afadb72b916e90564 (patch)
tree4b364461c185f935d315b591d3b52808d3824f45
parent438ea05fdb98c847d534ae190179b4766fa96f26 (diff)
downloadgeneralresearch-f4909f0fafd6161dd423859afadb72b916e90564.tar.gz
generalresearch-f4909f0fafd6161dd423859afadb72b916e90564.zip
1 single broken managers test
-rw-r--r--generalresearch/cacheing.py72
-rw-r--r--generalresearch/managers/thl/cashout_method.py19
-rw-r--r--generalresearch/managers/thl/ledger_manager/conditions.py17
-rw-r--r--generalresearch/managers/thl/ledger_manager/thl_ledger.py2
-rw-r--r--generalresearch/managers/thl/payout.py2
-rw-r--r--generalresearch/managers/thl/user_manager/user_manager.py9
-rw-r--r--test_utils/models/thl/conftest.py7
-rw-r--r--test_utils/models/upk/conftest.py7
-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
17 files changed, 121 insertions, 136 deletions
diff --git a/generalresearch/cacheing.py b/generalresearch/cacheing.py
index 34df267..55d9c9c 100644
--- a/generalresearch/cacheing.py
+++ b/generalresearch/cacheing.py
@@ -1,47 +1,25 @@
-from generalresearch import retry
-
-
-class RetryCache:
- # Simple pylibmc.Client wrapper that implements a retry on each method
-
- def __init__(self, client, tries: int = 4, delay: int = 1, backoff: float = 1.5):
- import pylibmc
-
- self.client = client
- self.f = retry(pylibmc.Error, tries=tries, delay=delay, backoff=backoff)
-
- def get(self, key):
- @self.f
- def _get(key):
- return self.client.get(key)
-
- return _get(key)
-
- def set(self, key, value, timeout=0):
- @self.f
- def _set(key, value, timeout):
- return self.client.set(key, value, time=timeout)
-
- return _set(key, value, timeout)
-
- def delete_multi(self, keys):
- @self.f
- def _delete_multi(keys):
- return self.client.delete_multi(keys)
-
- return _delete_multi(keys)
-
- def delete(self, key):
- @self.f
- def _delete(key):
- return self.client.delete(key)
-
- return _delete(key)
-
-
-if __name__ == "__main__":
- import pylibmc
-
- CACHE = RetryCache(pylibmc.Client(["127.0.0.1:11211"], binary=True))
- CACHE.set("foo", "bar")
- print(CACHE.get("foo"))
+from cachetools import TTLCache
+
+
+class InstrumentedTTLCache(TTLCache):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.hits = 0
+ self.misses = 0
+
+ def __getitem__(self, key):
+ try:
+ value = super().__getitem__(key)
+ self.hits += 1
+ return value
+ except KeyError:
+ self.misses += 1
+ raise
+
+ def cache_info(self):
+ return {
+ "hits": self.hits,
+ "misses": self.misses,
+ "currsize": self.currsize,
+ "maxsize": self.maxsize,
+ }
diff --git a/generalresearch/managers/thl/cashout_method.py b/generalresearch/managers/thl/cashout_method.py
index 90a6876..e83b16a 100644
--- a/generalresearch/managers/thl/cashout_method.py
+++ b/generalresearch/managers/thl/cashout_method.py
@@ -329,6 +329,16 @@ class CashoutMethodManager(PostgresManager):
cms = self.get_cashout_methods(user=user)
+ # Filter out by country before bothering w exchange rates
+ cms = [
+ cm
+ for cm in cms
+ if (
+ cm.type == PayoutType.TANGO and country_iso.lower() in cm.data.countries
+ )
+ or cm.type != PayoutType.TANGO
+ ]
+
for x in cms:
# assets in non-USD need to be converted to USD here
if x.original_currency is not None:
@@ -342,15 +352,6 @@ class CashoutMethodManager(PostgresManager):
# Adjust min_value for BP
x.min_value = max(x.min_value_usd, min_value)
- cms = [
- cm
- for cm in cms
- if (
- cm.type == PayoutType.TANGO and country_iso.lower() in cm.data.countries
- )
- or cm.type != PayoutType.TANGO
- ]
-
return {x.id: x for x in cms}
@staticmethod
diff --git a/generalresearch/managers/thl/ledger_manager/conditions.py b/generalresearch/managers/thl/ledger_manager/conditions.py
index 21a99b5..98502d0 100644
--- a/generalresearch/managers/thl/ledger_manager/conditions.py
+++ b/generalresearch/managers/thl/ledger_manager/conditions.py
@@ -35,7 +35,10 @@ def generate_condition_mp_payment(wall: Wall) -> Callable[..., tuple[bool, str]]
def _condition(lm: LedgerManager) -> tuple[bool, str]:
tag = f"{lm.currency.value}:mp_payment:{wall_uuid}"
txs = lm.get_tx_ids_by_tag(tag=tag)
- return len(txs) == 0, "duplicate tag"
+ if len(txs) != 0:
+ return False, "duplicate tag"
+ else:
+ return True, ""
return _condition
@@ -49,8 +52,11 @@ def generate_condition_bp_payment(session: Session) -> Callable[..., tuple[bool,
def _condition(lm: LedgerManager) -> tuple[bool, str]:
tag = f"{lm.currency.value}:bp_payment:{session_uuid}"
- txs_ids = lm.get_tx_ids_by_tag(tag=tag)
- return len(txs_ids) == 0, "duplicate tag"
+ txs = lm.get_tx_ids_by_tag(tag=tag)
+ if len(txs) != 0:
+ return False, "duplicate tag"
+ else:
+ return True, ""
return _condition
@@ -62,7 +68,10 @@ def generate_condition_tag_exists(tag: str) -> Callable[..., tuple[bool, str]]:
def _condition(lm: LedgerManager) -> tuple[bool, str]:
txs_ids = lm.get_tx_ids_by_tag(tag=tag)
- return len(txs_ids) == 0, "duplicate tag"
+ if len(txs_ids) != 0:
+ return False, "duplicate tag"
+ else:
+ return True, ""
return _condition
diff --git a/generalresearch/managers/thl/ledger_manager/thl_ledger.py b/generalresearch/managers/thl/ledger_manager/thl_ledger.py
index 5210189..de7cae9 100644
--- a/generalresearch/managers/thl/ledger_manager/thl_ledger.py
+++ b/generalresearch/managers/thl/ledger_manager/thl_ledger.py
@@ -303,7 +303,7 @@ class ThlLedgerManager(LedgerManager):
user: User,
created: datetime | None = None,
force: bool = False,
- ) -> PositiveInt:
+ ) -> LedgerTransaction:
"""
Create a transaction when we complete a task from a marketplace,
showing the marketplace paying us for the task complete.
diff --git a/generalresearch/managers/thl/payout.py b/generalresearch/managers/thl/payout.py
index 3968ea7..af4f712 100644
--- a/generalresearch/managers/thl/payout.py
+++ b/generalresearch/managers/thl/payout.py
@@ -145,7 +145,7 @@ class BrokerageProductPayoutEventManager(PayoutEventManager):
amount = USDCent(payout_event.amount)
product_id = payout_event.product_id
- txs = thl_ledger_manager.get_tx_by_tag(tag)
+ txs = thl_ledger_manager.get_txs_by_tag(tag)
if not txs:
return False
diff --git a/generalresearch/managers/thl/user_manager/user_manager.py b/generalresearch/managers/thl/user_manager/user_manager.py
index df3fb6b..15fd291 100644
--- a/generalresearch/managers/thl/user_manager/user_manager.py
+++ b/generalresearch/managers/thl/user_manager/user_manager.py
@@ -7,9 +7,10 @@ from datetime import datetime
from threading import Lock
from typing import TYPE_CHECKING
-from cachetools import TTLCache, cachedmethod
+from cachetools import cachedmethod
from pydantic import RedisDsn
+from generalresearch.cacheing import InstrumentedTTLCache
from generalresearch.managers.base import Permission
from generalresearch.managers.thl.product import ProductManager
from generalresearch.managers.thl.user_manager.exceptions import (
@@ -87,7 +88,7 @@ class UserManager:
self.product_manager = ProductManager(
pg_config=pg_config, permissions=[Permission.READ]
)
- self.get_user_cache = TTLCache(maxsize=10000, ttl=30)
+ self.get_user_cache = InstrumentedTTLCache(maxsize=10000, ttl=30)
self.get_user_cache_lock = Lock()
def set_last_seen(self, user: User) -> None:
@@ -147,6 +148,10 @@ class UserManager:
with self.get_user_cache_lock:
self.get_user_cache.clear()
+ def cache_info(self):
+ with self.get_user_cache_lock:
+ return self.get_user_cache.cache_info()
+
@deepcopy_return
@cachedmethod(
operator.attrgetter("get_user_cache"),
diff --git a/test_utils/models/thl/conftest.py b/test_utils/models/thl/conftest.py
index 433003c..a8ad037 100644
--- a/test_utils/models/thl/conftest.py
+++ b/test_utils/models/thl/conftest.py
@@ -628,13 +628,9 @@ def user_payout_event_factory(
debit_account_uuid = debit_account_uuid or uuid4().hex
cashout_method_uuid = cashout_method_uuid or uuid4().hex
- # account_reference_type = account_reference_type or f"acct-ref-{uuid4().hex}"
- # account_reference_uuid = account_reference_uuid or uuid4().hex
- # cashout_method_uuid = cashout_method_uuid or uuid4().hex
amount = amount or randint(a=99, b=9_999)
status = status or rand_choice(list(PayoutStatus))
- description = description or f"desc-{uuid4().hex[:12]}"
# ext_ref_id = ext_ref_id or f"ext-ref-{uuid4().hex[:8]}"
payout_type = payout_type or rand_choice(list(PayoutType))
request_data = request_data or {}
@@ -643,10 +639,7 @@ def user_payout_event_factory(
return user_payout_event_manager.create(
uuid=uuid,
debit_account_uuid=debit_account_uuid,
- account_reference_type=account_reference_type,
- account_reference_uuid=account_reference_uuid,
cashout_method_uuid=cashout_method_uuid,
- description=description,
created=created,
amount=amount,
status=status,
diff --git a/test_utils/models/upk/conftest.py b/test_utils/models/upk/conftest.py
index ad96bbb..520d566 100644
--- a/test_utils/models/upk/conftest.py
+++ b/test_utils/models/upk/conftest.py
@@ -33,6 +33,13 @@ def insert_data_from_csv(
df["id"] = df["id"].map(lambda x: UUID(x).hex)
args = df.to_dict("tight")["data"]
+ # Fix issue with nullable cols
+ if table_name == 'marketplace_question':
+ for arg in args:
+ for idx, col in enumerate(arg):
+ if pd.isnull(col):
+ arg[idx] = None
+
with thl_web_rw.make_connection() as conn:
with conn.cursor() as c:
if disable_fk_checks:
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)