aboutsummaryrefslogtreecommitdiff
path: root/tests/managers
diff options
context:
space:
mode:
Diffstat (limited to 'tests/managers')
-rw-r--r--tests/managers/test_events.py20
-rw-r--r--tests/managers/thl/test_ledger/test_thl_pem.py14
-rw-r--r--tests/managers/thl/test_payout.py38
-rw-r--r--tests/managers/thl/test_task_adjustment.py12
-rw-r--r--tests/managers/thl/test_user_streak.py24
-rw-r--r--tests/managers/thl/test_userhealth.py5
-rw-r--r--tests/managers/thl/test_wall_manager.py14
7 files changed, 71 insertions, 56 deletions
diff --git a/tests/managers/test_events.py b/tests/managers/test_events.py
index 8745126..e256876 100644
--- a/tests/managers/test_events.py
+++ b/tests/managers/test_events.py
@@ -1,13 +1,10 @@
from __future__ import annotations
import math
-import random
import time
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
from decimal import Decimal
-from functools import partial
-from math import floor
from typing import TYPE_CHECKING
from uuid import uuid4
@@ -39,27 +36,10 @@ def product_id(product_manager: ProductManager) -> str:
@pytest.fixture(scope="function")
-def user_factory(product_id: str):
- return partial(create_dummy, product_id=product_id)
-
-
-@pytest.fixture(scope="function")
def event_subscriber(thl_redis_config: RedisConfig, product_id: str) -> EventSubscriber:
return EventSubscriber(redis_config=thl_redis_config, product_id=product_id)
-def create_dummy(
- product_id: str | None = None, product_user_id: str | None = None
-) -> User:
- return User(
- product_id=product_id,
- product_user_id=product_user_id or uuid4().hex,
- uuid=uuid4().hex,
- created=datetime.now(tz=UTC),
- user_id=random.randint(0, floor(2**32 / 2)),
- )
-
-
class TestActiveUsers:
def test_run_empty(self, event_manager: EventManager, product_id: str):
diff --git a/tests/managers/thl/test_ledger/test_thl_pem.py b/tests/managers/thl/test_ledger/test_thl_pem.py
index 9dbec48..18102c3 100644
--- a/tests/managers/thl/test_ledger/test_thl_pem.py
+++ b/tests/managers/thl/test_ledger/test_thl_pem.py
@@ -25,6 +25,7 @@ if TYPE_CHECKING:
BrokerageProductPayoutEventManager,
UserPayoutEventManager,
)
+ from generalresearch.models.thl.payout import UserPayoutEvent
from generalresearch.models.thl.product import Product
@@ -111,7 +112,7 @@ class TestThlPayoutEventManager:
# We just added 5 Payouts for a specific product: Product, now go
# ahead and query for them
res = brokerage_product_payout_event_manager.get_bp_bp_payout_events_for_products(
- thl_ledger_manager=thl_ledger_manager, product_uuids=[product.id]
+ product_uuids=[product.id]
)
assert len(res) == N_PAYOUT_EVENTS
@@ -120,7 +121,6 @@ class TestThlPayoutEventManager:
# ahead and query for them
res = (
brokerage_product_payout_event_manager.get_bp_bp_payout_events_for_products(
- thl_ledger_manager=thl_ledger_manager,
product_uuids=[i.uuid for i in products],
)
)
@@ -160,11 +160,15 @@ class TestThlPayoutEventManager:
# def test_filter_by(self):
# raise NotImplementedError
- def test_create(self, user_payout_event_manager: UserPayoutEventManager):
+ def test_create(
+ self,
+ user_payout_event_factory: Callable[..., UserPayoutEvent],
+ user_payout_event_manager: UserPayoutEventManager,
+ ):
from generalresearch.models.thl.payout import UserPayoutEvent
# Confirm the creation method returns back an instance.
- pe = user_payout_event_manager.create_dummy()
+ pe = user_payout_event_factory()
assert isinstance(pe, UserPayoutEvent)
# Now query the DB for that PayoutEvent to confirm it was actually
@@ -260,7 +264,7 @@ class TestBPPayoutEvent:
# array of BPPayoutEvents
bp_bp_res = (
brokerage_product_payout_event_manager.get_bp_bp_payout_events_for_products(
- thl_ledger_manager=thl_ledger_manager, product_uuids=[product.uuid]
+ product_uuids=[product.uuid]
)
)
assert isinstance(bp_bp_res, list)
diff --git a/tests/managers/thl/test_payout.py b/tests/managers/thl/test_payout.py
index ad101a4..52bbbec 100644
--- a/tests/managers/thl/test_payout.py
+++ b/tests/managers/thl/test_payout.py
@@ -282,7 +282,9 @@ class TestBusinessPayoutEventManager:
create_main_accounts: Callable[..., None],
thl_ledger_manager: ThlLedgerManager,
product_factory: Callable[..., Product],
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
gr_business: Business,
):
delete_ledger_db()
@@ -295,16 +297,24 @@ class TestBusinessPayoutEventManager:
ach_id2 = uuid4().hex
# ext_ref_id is required now
- bp_payout_factory(product=p1, amount=USDCent(1), ext_ref_id="none")
+ brokerage_product_payout_event_factory(
+ product=p1, amount=USDCent(1), ext_ref_id="none"
+ )
- bp_payout_factory(product=p1, amount=USDCent(1), ext_ref_id=ach_id1)
+ brokerage_product_payout_event_factory(
+ product=p1, amount=USDCent(1), ext_ref_id=ach_id1
+ )
with pytest.raises(
expected_exception=ValueError,
match="Cannot create a BusinessPayoutEvent with an existing transaction_id",
):
- bp_payout_factory(product=p1, amount=USDCent(25), ext_ref_id=ach_id1)
+ brokerage_product_payout_event_factory(
+ product=p1, amount=USDCent(25), ext_ref_id=ach_id1
+ )
- bp_payout_factory(product=p1, amount=USDCent(50), ext_ref_id=ach_id2)
+ brokerage_product_payout_event_factory(
+ product=p1, amount=USDCent(50), ext_ref_id=ach_id2
+ )
gr_business.prebuild_payouts(
bpem=business_payout_event_manager,
@@ -562,9 +572,9 @@ class TestBusinessPayoutEventManager:
session_with_tx_factory: Callable[..., Session],
pop_ledger_merge: PopLedgerMerge,
start: datetime,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
- adj_to_fail_with_tx_factory: Callable[..., None],
- thl_web_rr: PostgresConfig,
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
ledger_manager: LedgerManager,
product_manager: ProductManager,
):
@@ -593,7 +603,7 @@ class TestBusinessPayoutEventManager:
wall_req_cpi=Decimal("5.00"),
started=start + timedelta(days=6),
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u1.product,
amount=USDCent(475), # 95% of $5.00
created=start + timedelta(days=1, minutes=1),
@@ -602,7 +612,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,
@@ -747,7 +757,9 @@ class TestBusinessPayoutEventManager:
session_with_tx_factory: Callable[..., None],
pop_ledger_merge: PopLedgerMerge,
start: datetime,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
adj_to_fail_with_tx_factory: Callable[..., None],
thl_web_rr: PostgresConfig,
ledger_manager: LedgerManager,
@@ -784,7 +796,7 @@ class TestBusinessPayoutEventManager:
wall_req_cpi=Decimal("5.00"),
started=start + timedelta(days=1),
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u1.product,
amount=USDCent(475), # 95% of $5.00
ext_ref_id=ach_id1,
@@ -815,7 +827,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,
diff --git a/tests/managers/thl/test_task_adjustment.py b/tests/managers/thl/test_task_adjustment.py
index a14401e..323d6db 100644
--- a/tests/managers/thl/test_task_adjustment.py
+++ b/tests/managers/thl/test_task_adjustment.py
@@ -23,7 +23,7 @@ if TYPE_CHECKING:
TaskAdjustmentManager,
)
from generalresearch.managers.thl.wall import WallManager
- from generalresearch.models.thl.session import Session
+ from generalresearch.models.thl.session import Session, Wall
from generalresearch.models.thl.user import User
@@ -47,10 +47,14 @@ def session_complete_with_wallet(
@pytest.fixture()
def session_fail(
- user: User, session_manager: SessionManager, wall_manager: WallManager
+ user: User,
+ session_manager: SessionManager,
+ wall_manager: WallManager,
+ session_factory: Callable[..., Session],
+ wall_factory: Callable[..., Wall],
) -> Session:
- session = session_manager.create_dummy(started=datetime.now(UTC), user=user)
- wall1 = wall_manager.create_dummy(
+ session = session_factory(started=datetime.now(UTC), user=user)
+ wall1 = wall_factory(
session_id=session.id,
user_id=user.user_id,
source=Source.DYNATA,
diff --git a/tests/managers/thl/test_user_streak.py b/tests/managers/thl/test_user_streak.py
index 564a142..59dee2d 100644
--- a/tests/managers/thl/test_user_streak.py
+++ b/tests/managers/thl/test_user_streak.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import copy
+from collections.abc import Callable
from datetime import UTC, date, datetime, timedelta
from decimal import Decimal
from typing import TYPE_CHECKING
@@ -24,6 +25,7 @@ if TYPE_CHECKING:
from generalresearch.managers.thl.user_streak import (
UserStreakManager,
)
+ from generalresearch.models.thl.session import Session, Wall
from generalresearch.models.thl.user import User
@@ -106,8 +108,14 @@ def broken_active_streak(user: User) -> list[UserStreak]:
]
-def create_session_fail(session_manager: SessionManager, start: datetime, user: User):
- session = session_manager.create_dummy(started=start, country_iso="us", user=user)
+def create_session_fail(
+ session_manager: SessionManager,
+ start: datetime,
+ user: User,
+ session_factory: Callable[..., Session],
+ wall_factory: Callable[..., Wall],
+):
+ session = session_factory(started=start, country_iso="us", user=user)
session_manager.finish_with_status(
session,
finished=start + timedelta(minutes=1),
@@ -117,9 +125,13 @@ def create_session_fail(session_manager: SessionManager, start: datetime, user:
def create_session_complete(
- session_manager: SessionManager, start: datetime, user: User
+ session_manager: SessionManager,
+ start: datetime,
+ user: User,
+ session_factory: Callable[..., Session],
+ wall_factory: Callable[..., Wall],
):
- session = session_manager.create_dummy(started=start, country_iso="us", user=user)
+ session = session_factory(started=start, country_iso="us", user=user)
session_manager.finish_with_status(
session,
finished=start + timedelta(minutes=1),
@@ -141,13 +153,15 @@ def test_user_streaks_active_broken(
user: User,
session_manager: SessionManager,
broken_active_streak: list[UserStreak],
+ session_factory: Callable[..., Session],
+ wall_factory: Callable[..., Wall],
):
# Testing active streak, but broken (not today or yesterday)
start1 = datetime(2025, 2, 12, tzinfo=UTC)
end1 = start1 + timedelta(minutes=1)
# abandon counts as inactive
- session = session_manager.create_dummy(started=start1, country_iso="us", user=user)
+ session = session_factory(started=start1, country_iso="us", user=user)
streak = user_streak_manager.get_user_streaks(user_id=user.user_id)
assert streak == []
diff --git a/tests/managers/thl/test_userhealth.py b/tests/managers/thl/test_userhealth.py
index ce6c221..a86361a 100644
--- a/tests/managers/thl/test_userhealth.py
+++ b/tests/managers/thl/test_userhealth.py
@@ -241,10 +241,9 @@ class TestIPRecordManager:
ip_record_manager: IPRecordManager,
user: User,
ip_information: IPInformation,
+ ip_record_factory: Callable[..., IPRecord],
):
- instance = ip_record_manager.create_dummy(
- user_id=user.user_id, ip=ip_information.ip
- )
+ instance = ip_record_factory(user_id=user.user_id, ip=ip_information.ip)
assert isinstance(instance, IPRecord)
assert isinstance(instance.forwarded_ips, list)
diff --git a/tests/managers/thl/test_wall_manager.py b/tests/managers/thl/test_wall_manager.py
index 58de7a2..70db71e 100644
--- a/tests/managers/thl/test_wall_manager.py
+++ b/tests/managers/thl/test_wall_manager.py
@@ -19,7 +19,7 @@ from generalresearch.models.thl.definitions import (
if TYPE_CHECKING:
from generalresearch.managers.thl.session import SessionManager
from generalresearch.managers.thl.wall import WallCacheManager, WallManager
- from generalresearch.models.thl.session import Session
+ from generalresearch.models.thl.session import Session, Wall
from generalresearch.models.thl.user import User
@@ -250,13 +250,15 @@ class TestWallCacheManager:
wall_manager: WallManager,
session_manager: SessionManager,
user: User,
+ session_factory: Callable[..., Session],
+ wall_factory: Callable[..., Wall],
):
start1 = datetime.now(UTC) - timedelta(hours=3)
start2 = datetime.now(UTC) - timedelta(hours=2)
start3 = datetime.now(UTC) - timedelta(hours=1)
- session = session_manager.create_dummy(started=start1, user=user)
- wall_manager.create_dummy(
+ session = session_factory(started=start1, user=user)
+ wall_factory(
session_id=session.id,
user_id=session.user_id,
started=start1,
@@ -272,7 +274,7 @@ class TestWallCacheManager:
attempts = wall_cache_manager.get_attempts(user_id=user.user_id)
assert len(attempts) == 1
- wall_manager.create_dummy(
+ wall_factory(
session_id=session.id,
user_id=session.user_id,
started=start2,
@@ -298,8 +300,8 @@ class TestWallCacheManager:
attempts10000 = [attempts[0]] * 6000
wall_cache_manager.update_attempts_redis_(attempts10000, user_id=user.user_id)
- session = session_manager.create_dummy(started=start3, user=user)
- wall_manager.create_dummy(
+ session = session_factory(started=start3, user=user)
+ wall_factory(
session_id=session.id,
user_id=session.user_id,
started=start3,