aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Nanis2026-09-03 09:26:17 -0700
committerMax Nanis2026-09-03 09:26:17 -0700
commit1151b332279425e4e088bd3499c76e582f7f045d (patch)
treec4098976eaaed187cb7a2eca388c805b70986efc
parent17ff15c06655717627da820417337c6b0b97de42 (diff)
downloadgeneralresearch-1151b332279425e4e088bd3499c76e582f7f045d.tar.gz
generalresearch-1151b332279425e4e088bd3499c76e582f7f045d.zip
Test cleanup all morning. mangers/thl = 78fail, 417passed
-rw-r--r--generalresearch/thl_django/app/test_settings.py2
-rw-r--r--test_utils/models/conftest.py151
-rw-r--r--test_utils/models/gr/conftest.py7
-rw-r--r--test_utils/models/ledger/conftest.py54
-rw-r--r--test_utils/models/thl/conftest.py382
-rw-r--r--tests/grliq/managers/test_forensic_data.py2
-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
-rw-r--r--tests/models/gr/test_business.py54
-rw-r--r--tests/models/thl/test_product.py26
15 files changed, 404 insertions, 401 deletions
diff --git a/generalresearch/thl_django/app/test_settings.py b/generalresearch/thl_django/app/test_settings.py
index d6ab124..57cb9b9 100644
--- a/generalresearch/thl_django/app/test_settings.py
+++ b/generalresearch/thl_django/app/test_settings.py
@@ -1,7 +1,7 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
- "NAME": 'unittest-2026-09-03-44c0b4',
+ "NAME": 'unittest-2026-09-03-a0a584',
"USER": 'jenkins',
"PASSWORD": '123456789',
"HOST": 'unittest-postgresql.fmt2.grl.internal',
diff --git a/test_utils/models/conftest.py b/test_utils/models/conftest.py
index d5c9a71..9edadd3 100644
--- a/test_utils/models/conftest.py
+++ b/test_utils/models/conftest.py
@@ -51,119 +51,17 @@ if TYPE_CHECKING:
)
from generalresearch.models.thl.session import Session, Wall
from generalresearch.models.thl.user import User
- from generalresearch.pg_helper import PostgresConfig
# === THL ===
@pytest.fixture
-def user(
- request: FixtureRequest,
- user_manager: UserManager,
- thl_web_rr: PostgresConfig,
- product_factory: Callable[..., Product],
-) -> User:
- product = getattr(request, "product", None)
-
- if product is None:
- product = product_factory()
-
- u = user_manager.create_dummy(product_id=product.id)
- u.prefetch_product(pg_config=thl_web_rr)
-
- return u
-
-
-@pytest.fixture
-def user_with_wallet(
- user_factory: Callable[..., User],
- product_user_wallet_yes: Product,
-) -> User:
- # A user on a product with user wallet enabled, but they have no money
- return user_factory(product=product_user_wallet_yes)
-
-
-@pytest.fixture
-def user_with_wallet_amt(
- user_factory: Callable[..., User], product_amt_true: Product
-) -> User:
- # A user on a product with user wallet enabled, on AMT, but they have no money
- return user_factory(product=product_amt_true)
-
-
-@pytest.fixture(scope="function")
-def user_factory(
- user_manager: UserManager, thl_web_rr: PostgresConfig
-) -> Callable[..., User]:
-
- def _inner(product: Product, created: datetime | None = None) -> User:
- u = user_manager.create_dummy(product=product, created=created)
- u.prefetch_product(pg_config=thl_web_rr)
-
- return u
-
- return _inner
-
-
-@pytest.fixture
-def wall_factory(wall_manager: WallManager) -> Callable[..., Wall]:
-
- def _inner(
- session: Session, wall_status: Status, req_cpi: Decimal | None = None
- ) -> Wall:
-
- assert session.started <= datetime.now(
- tz=UTC
- ), "Session can't start in the future"
-
- if session.wall_events:
- # Subsequent Wall events
- wall = session.wall_events[-1]
- assert not wall.finished, "Can't add new Walls until prior finishes"
- # wall_started = last_wall.started + timedelta(milliseconds=1)
- else:
- # First Wall Event in a session
- wall_started = session.started + timedelta(milliseconds=1)
-
- wall = wall_manager.create_dummy(
- session_id=session.id,
- user_id=session.user_id,
- started=wall_started,
- req_cpi=req_cpi,
- )
- session.append_wall_event(w=wall)
-
- options = list(WALL_ALLOWED_STATUS_STATUS_CODE.get(wall_status, {}))
- wall.finish(
- finished=wall.started + timedelta(seconds=randint(a=60 * 2, b=60 * 10)),
- status=wall_status,
- status_code_1=randchoice(options),
- )
-
- return wall
-
- return _inner
-
-
-@pytest.fixture
-def wall(session: Session, user: User, wall_manager: WallManager) -> Wall | None:
- from generalresearch.models.thl.task_status import StatusCode1
-
- wall = wall_manager.create_dummy(session_id=session.id, user_id=user.user_id)
- # thl_session.append_wall_event(wall)
- wall.finish(
- finished=wall.started + timedelta(seconds=randint(a=60 * 2, b=60 * 10)),
- status=Status.COMPLETE,
- status_code_1=StatusCode1.COMPLETE,
- )
- return wall
-
-
-@pytest.fixture
def session_factory(
session_manager: SessionManager,
wall_manager: WallManager,
utc_hour_ago: datetime,
+ session_factory: Callable[..., Session],
+ wall_factory: Callable[..., Wall],
) -> Callable[..., Session]:
from generalresearch.models.thl.session import Source
@@ -184,7 +82,7 @@ def session_factory(
if wall_statuses:
assert len(wall_statuses) == wall_count
- s = session_manager.create_dummy(started=started, user=user, country_iso="us")
+ s = session_factory(started=started, user=user, country_iso="us")
for idx in range(wall_count):
if idx == 0:
# First Wall Event in a session
@@ -195,7 +93,7 @@ def session_factory(
assert last_wall.finished, "Can't add new Walls until prior finishes"
wall_started = last_wall.started + timedelta(milliseconds=1)
- w = wall_manager.create_dummy(
+ w = wall_factory(
session_id=s.id,
source=wall_source,
user_id=s.user_id,
@@ -271,11 +169,15 @@ def finished_session_factory(
@pytest.fixture
def session(
- 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 = session_manager.create_dummy(user=user, country_iso="us")
- wall: Wall = wall_manager.create_dummy(
+ session: Session = session_factory(user=user, country_iso="us")
+ wall: Wall = wall_factory(
session_id=session.id,
user_id=session.user_id,
started=session.started,
@@ -342,37 +244,6 @@ def product_amt_true(
)
-@pytest.fixture
-def bp_payout_factory(
- thl_ledger_manager: ThlLedgerManager,
- product_manager: ProductManager,
- business_payout_event_manager: BusinessPayoutEventManager,
-) -> Callable[..., BrokerageProductPayoutEvent]:
-
- def _inner(
- product: Product | None = None,
- amount: USDCent | None = None,
- ext_ref_id: str | None = None,
- created: AwareDatetime | None = None,
- skip_wallet_balance_check: bool = False,
- skip_one_per_day_check: bool = False,
- ) -> BrokerageProductPayoutEvent:
- from generalresearch.currency import USDCent
-
- product = product or product_manager.create_dummy()
- amount = amount or USDCent(randint(1, 99_99))
-
- return business_payout_event_manager.create_bp_payout_event(
- thl_ledger_manager=thl_ledger_manager,
- product=product,
- amount=amount,
- ext_ref_id=ext_ref_id or uuid4().hex,
- created=created,
- )
-
- return _inner
-
-
@pytest.fixture(scope="session")
def buyer(buyer_manager: BuyerManager) -> Buyer:
buyer_code = uuid4().hex
diff --git a/test_utils/models/gr/conftest.py b/test_utils/models/gr/conftest.py
index 3dd73a1..1dbea0c 100644
--- a/test_utils/models/gr/conftest.py
+++ b/test_utils/models/gr/conftest.py
@@ -132,13 +132,6 @@ def gr_business_address_factory(
return _inner
-# @pytest.fixture
-# def business_address(
-# gr_business: Business, business_address_manager: BusinessAddressManager
-# ) -> :
-# return business_address_manager.create_dummy(business_id=gr_business.id)
-
-
@pytest.fixture
def gr_business_address(
gr_business_address_factory: Callable[..., BusinessAddress],
diff --git a/test_utils/models/ledger/conftest.py b/test_utils/models/ledger/conftest.py
index 31e5eb4..9ee0df2 100644
--- a/test_utils/models/ledger/conftest.py
+++ b/test_utils/models/ledger/conftest.py
@@ -11,36 +11,29 @@ import pytest
from pytest import FixtureRequest as Request
from generalresearch.currency import USDCent
-from test_utils.models.conftest import (
- payout_config,
- product_amt_true,
- product_user_wallet_no,
- product_user_wallet_yes,
- session,
- session_factory,
- user_factory,
- wall,
- wall_factory,
-)
-if TYPE_CHECKING:
- from generalresearch.managers.base import PostgresManager
-
-_ = (
- user_factory,
- product_user_wallet_no,
- wall,
- product_amt_true,
- product_user_wallet_yes,
- session_factory,
- session,
- wall_factory,
- payout_config,
-)
+# from test_utils.models.conftest import (
+# payout_config,
+# product_amt_true,
+# product_user_wallet_no,
+# product_user_wallet_yes,
+# )
+
+# _ = (
+# user_factory,
+# product_user_wallet_no,
+# wall,
+# product_amt_true,
+# product_user_wallet_yes,
+# session_factory,
+# session,
+# wall_factory,
+# payout_config,
+# )
if TYPE_CHECKING:
-
from generalresearch.currency import LedgerCurrency
+ from generalresearch.managers.base import PostgresManager
from generalresearch.managers.thl.ledger_manager.ledger import LedgerManager
from generalresearch.managers.thl.ledger_manager.thl_ledger import (
ThlLedgerManager,
@@ -193,16 +186,17 @@ def usd_cent(request: Request) -> USDCent:
def bp_payout_event(
product: Product,
usd_cent: USDCent,
- business_payout_event_manager: BusinessPayoutEventManager,
+ brokerage_product_payout_event_manager: BrokerageProductPayoutEvent,
thl_ledger_manager: ThlLedgerManager,
) -> BrokerageProductPayoutEvent:
- return business_payout_event_manager.create_bp_payout_event(
+ _ext_ref_id = f"tx-{uuid4().hex[:7]}"
+
+ return brokerage_product_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_ledger_manager,
+ ext_ref_id=_ext_ref_id,
product=product,
amount=usd_cent,
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
diff --git a/test_utils/models/thl/conftest.py b/test_utils/models/thl/conftest.py
index 14f8f36..5dc46cd 100644
--- a/test_utils/models/thl/conftest.py
+++ b/test_utils/models/thl/conftest.py
@@ -1,7 +1,7 @@
from __future__ import annotations
from collections.abc import Callable
-from datetime import UTC, datetime
+from datetime import UTC, datetime, timedelta
from decimal import ROUND_DOWN, Decimal
from random import choice as rand_choice
from random import randint, random
@@ -13,37 +13,49 @@ import pytest
from grip_client.enums import AccessType
from pydantic import PositiveInt
+from generalresearch.managers.thl.payout import UserPayoutEventManager
from generalresearch.models.custom_types import (
AwareDatetimeISO,
IPvAnyAddressStr,
UUIDStr,
)
-from generalresearch.models.thl.definitions import PayoutStatus
+from generalresearch.models.thl.definitions import (
+ WALL_ALLOWED_STATUS_STATUS_CODE,
+ PayoutStatus,
+)
+from generalresearch.models.thl.payout import UserPayoutEvent
from generalresearch.models.thl.session import (
Source,
Status,
)
from generalresearch.models.thl.user import User
+from generalresearch.models.thl.user_iphistory import IPRecord
from generalresearch.models.thl.userhealth import AuditLogLevel
from generalresearch.models.thl.wallet.definitions import PayoutType
if TYPE_CHECKING:
+ from generalresearch.currency import USDCent
from generalresearch.managers.thl.ipinfo import (
IPGeonameManager,
IPInformationManager,
)
- from generalresearch.managers.thl.payout import UserPayoutEventManager
+ from generalresearch.managers.thl.ledger_manager.thl_ledger import ThlLedgerManager
+ from generalresearch.managers.thl.payout import (
+ BrokerageProductPayoutEventManager,
+ BusinessPayoutEventManager,
+ )
from generalresearch.managers.thl.product import ProductManager
from generalresearch.managers.thl.session import SessionManager
from generalresearch.managers.thl.user_manager.user_manager import UserManager
from generalresearch.managers.thl.userhealth import AuditLogManager, IPRecordManager
from generalresearch.managers.thl.wall import WallManager
+ from generalresearch.models.custom_types import AwareDatetime
from generalresearch.models.definitions import DeviceType
from generalresearch.models.gr.business import Business
from generalresearch.models.gr.team import Team
from generalresearch.models.legacy.bucket import Bucket
from generalresearch.models.thl.ipinfo import IPGeoname, IPInformation
- from generalresearch.models.thl.payout import UserPayoutEvent
+ from generalresearch.models.thl.payout import BrokerageProductPayoutEvent
from generalresearch.models.thl.product import (
PayoutConfig,
Product,
@@ -66,19 +78,31 @@ if TYPE_CHECKING:
fake = faker.Faker()
+# --- Wall ---
-@pytest.fixture
-def wall_status() -> Status:
- return Status.COMPLETE
+
+# from generalresearch.models.thl.task_status import StatusCode1
+# # thl_session.append_wall_event(wall)
+# wall.finish(
+# finished=wall.started + timedelta(seconds=randint(a=60 * 2, b=60 * 10)),
+# status=Status.COMPLETE,
+# status_code_1=StatusCode1.COMPLETE,
+# )
+# return wall
@pytest.fixture
def wall_factory(
- wall_manager: WallManager, session_factory: Session
+ wall_manager: WallManager,
+ session_factory: Callable[..., Session],
+ session_manager: SessionManager,
) -> Callable[..., Wall]:
def _inner(
- session_id: int | None = None,
+ wall_status: Status,
+ save: bool = True,
+ session: Session | None = None,
+ session_id: PositiveInt | None = None,
user_id: int | None = None,
started: datetime | None = None,
source: Source | None = None,
@@ -86,43 +110,157 @@ def wall_factory(
req_cpi: Decimal | None = None,
buyer_id: str | None = None,
uuid_id: str | None = None,
- ):
+ ) -> Wall:
"""To be used in tests, where we don't care about certain fields"""
- user_id = user_id or fake.random_int(min=1, max=2_147_483_648)
- started = started or fake.date_time_between(
- start_date=datetime(year=1900, month=1, day=1, tzinfo=UTC),
- end_date=datetime.now(tz=UTC),
- tzinfo=UTC,
- )
+ if save:
- if session_id is None:
- # session = SessionManager(pg_config=self.pg_config).create_dummy(
- # started=started
- # )
- session = session_factory()
- session_id = session.id
+ user_id = user_id or fake.random_int(min=1, max=2_147_483_648)
+ _wall_started = started or fake.date_time_between(
+ start_date=datetime(year=1900, month=1, day=1, tzinfo=UTC),
+ end_date=datetime.now(tz=UTC),
+ tzinfo=UTC,
+ )
- source = source or rand_choice(list(Source))
- req_survey_id = req_survey_id or uuid4().hex
- req_cpi = req_cpi or Decimal(fake.random_int(min=1, max=150) / 100).quantize(
- Decimal(".01"), rounding=ROUND_DOWN
- )
+ if session:
+ # If an existing Session was provided, we want to do some
+ # additional validation.
+
+ if session.wall_events:
+ # Subsequent Wall events
+ _last_wall = session.wall_events[-1]
+ assert (
+ not _last_wall.finished
+ ), "Can't add new Walls until prior finishes"
+ _wall_started = _last_wall.started + timedelta(milliseconds=1)
+ else:
+ # First Wall Event in a session
+ _wall_started = session.started + timedelta(milliseconds=1)
+ else:
+ # If a Session was NOT provided, either (1) try to retrieve it
+ # from an optionally provided session_id int, or (2) proceed
+ # forward and make one
+ session = (
+ session_manager.get_from_id(session_id=session_id)
+ if session_id
+ else None
+ ) or session_factory(save=True, user_id=user_id)
+
+ assert session, "Wall factory requires Session"
+
+ source = source or rand_choice(list(Source))
+ req_survey_id = req_survey_id or uuid4().hex
+ req_cpi = req_cpi or Decimal(
+ fake.random_int(min=1, max=150) / 100
+ ).quantize(Decimal(".01"), rounding=ROUND_DOWN)
+
+ w = wall_manager.create(
+ session_id=session.id,
+ user_id=session.user_id,
+ started=_wall_started,
+ source=source,
+ req_survey_id=req_survey_id,
+ req_cpi=req_cpi,
+ buyer_id=buyer_id,
+ uuid_id=uuid_id,
+ )
- return wall_manager.create(
- session_id=session_id,
- user_id=user_id,
- started=started,
- source=source,
- req_survey_id=req_survey_id,
- req_cpi=req_cpi,
- buyer_id=buyer_id,
- uuid_id=uuid_id,
- )
+ _status_code_options = list(
+ WALL_ALLOWED_STATUS_STATUS_CODE.get(wall_status, {})
+ )
+ w.finish(
+ finished=w.started + timedelta(seconds=randint(a=60 * 2, b=60 * 10)),
+ status=wall_status,
+ status_code_1=rand_choice(_status_code_options),
+ )
+
+ session.append_wall_event(w=w)
+
+ return w
+
+ else:
+ raise ValueError("Unsaved Wall not yet supported")
return _inner
+@pytest.fixture
+def wall(wall_factory: Callable[..., Wall]) -> Wall:
+ return wall_factory(save=True)
+
+
+@pytest.fixture()
+def unsaved_wall(wall_factory: Callable[..., Wall]) -> Wall:
+ return wall_factory(save=False)
+
+
+# --- Wall: Enum(s) ---
+
+
+@pytest.fixture
+def wall_status() -> Status:
+ return Status.COMPLETE
+
+
+# --- Session ---
+
+
+@pytest.fixture
+def session_factory(session_manager: SessionManager, user_factory: Callable[..., User]):
+
+ def _inner(
+ save: bool = True,
+ # -- Create Dummy "optional" -- #
+ started: datetime | None = None,
+ user: User | None = None,
+ # -- Optional -- #
+ country_iso: str | None = None,
+ device_type: DeviceType | None = None,
+ ip: str | None = None,
+ bucket: Bucket | None = None,
+ url_metadata: dict[str, str] | None = None,
+ uuid_id: str | None = None,
+ ) -> Session:
+
+ if save:
+ """To be used in tests, where we don't care about certain fields"""
+ started = started or fake.date_time_between(
+ start_date=datetime(year=1900, month=1, day=1, tzinfo=UTC),
+ end_date=datetime(year=2000, month=1, day=1, tzinfo=UTC),
+ tzinfo=UTC,
+ )
+ user = user or user_factory(save=True)
+ assert user.user_id, "Provided User must be saved to the database"
+
+ return session_manager.create(
+ started=started,
+ user=user,
+ country_iso=country_iso,
+ device_type=device_type,
+ ip=ip,
+ bucket=bucket,
+ url_metadata=url_metadata,
+ uuid_id=uuid_id,
+ )
+ else:
+ # user = User(
+ # user_id=fake.random_int(min=1, max=2_147_483_648), uuid=uuid4().hex
+ # )
+ raise ValueError("Unsaved Session not yet supported")
+
+ return _inner
+
+
+@pytest.fixture()
+def session(session_factory: Callable[..., Session]) -> Session:
+ return session_factory(save=True)
+
+
+@pytest.fixture()
+def unsaved_session(session_factory: Callable[..., Session]) -> Session:
+ return session_factory(save=False)
+
+
# --- Product ---
@@ -193,46 +331,7 @@ def unsaved_product(product_factory: Callable[..., Product]) -> Product:
return product_factory(save=False)
-# --- Session ---
-
-
-@pytest.fixture
-def session_factory(session_manager: SessionManager):
-
- def _inner(
- # -- Create Dummy "optional" -- #
- started: datetime | None = None,
- user: User | None = None,
- # -- Optional -- #
- country_iso: str | None = None,
- device_type: DeviceType | None = None,
- ip: str | None = None,
- bucket: Bucket | None = None,
- url_metadata: dict[str, str] | None = None,
- uuid_id: str | None = None,
- ) -> Session:
- """To be used in tests, where we don't care about certain fields"""
- started = started or fake.date_time_between(
- start_date=datetime(year=1900, month=1, day=1, tzinfo=UTC),
- end_date=datetime(year=2000, month=1, day=1, tzinfo=UTC),
- tzinfo=UTC,
- )
- user = user or User(
- user_id=fake.random_int(min=1, max=2_147_483_648), uuid=uuid4().hex
- )
-
- return session_manager.create(
- started=started,
- user=user,
- country_iso=country_iso,
- device_type=device_type,
- ip=ip,
- bucket=bucket,
- url_metadata=url_metadata,
- uuid_id=uuid_id,
- )
-
- return _inner
+# --- IP Geoname ---
@pytest.fixture
@@ -363,7 +462,7 @@ def ip_information(
return ip_information_factory(save=True)
-@pytest.fixture
+@pytest.fixture()
def unsaved_ip_information(
ip_information_factory: Callable[..., IPInformation],
) -> IPInformation:
@@ -373,41 +472,36 @@ def unsaved_ip_information(
# --- IP Record ---
-@pytest.fixture
-def ip_record_factory(
- ip_record_manager: IPRecordManager, user: User
-) -> Callable[..., IPRecord]:
- # return ip_record_manager.create_dummy(user_id=user.user_id)
-
- # def create_dummy(
- # self,
- # user_id: PositiveInt,
- # ip: IPvAnyAddressStr | None = None,
- # forwarded_ip1: IPvAnyAddressStr | None = None,
- # forwarded_ip2: IPvAnyAddressStr | None = None,
- # forwarded_ip3: IPvAnyAddressStr | None = None,
- # forwarded_ip4: IPvAnyAddressStr | None = None,
- # forwarded_ip5: IPvAnyAddressStr | None = None,
- # forwarded_ip6: IPvAnyAddressStr | None = None,
- # ) -> IPRecord:
- # return self.create(
- # user_id=user_id,
- # ip=ip or fake.ipv4_public(),
- # forwarded_ip1=(forwarded_ip1 or fake.ipv4_public()),
- # forwarded_ip2=(forwarded_ip2 or fake.ipv6() if random() < 0.5 else None),
- # forwarded_ip3=(
- # forwarded_ip3 or fake.ipv4_public() if random() < 0.25 else None
- # ),
- # forwarded_ip4=forwarded_ip4,
- # forwarded_ip5=forwarded_ip5,
- # forwarded_ip6=forwarded_ip6,
- # )
+@pytest.fixture()
+def ip_record_factory(ip_record_manager: IPRecordManager) -> Callable[..., IPRecord]:
def _inner(
- user_id: PositiveInt, save: bool = True, ip: str | None = None
+ user_id: PositiveInt,
+ save: bool = True,
+ ip: IPvAnyAddressStr | None = None,
+ forwarded_ip1: IPvAnyAddressStr | None = None,
+ forwarded_ip2: IPvAnyAddressStr | None = None,
+ forwarded_ip3: IPvAnyAddressStr | None = None,
+ forwarded_ip4: IPvAnyAddressStr | None = None,
+ forwarded_ip5: IPvAnyAddressStr | None = None,
+ forwarded_ip6: IPvAnyAddressStr | None = None,
) -> IPRecord:
+
if save:
- return ip_record_manager.create_dummy(user_id=user_id, ip=ip)
+ return ip_record_manager.create(
+ user_id=user_id,
+ ip=ip or fake.ipv4_public(),
+ forwarded_ip1=(forwarded_ip1 or fake.ipv4_public()),
+ forwarded_ip2=(
+ forwarded_ip2 or fake.ipv6() if random() < 0.5 else None
+ ),
+ forwarded_ip3=(
+ forwarded_ip3 or fake.ipv4_public() if random() < 0.25 else None
+ ),
+ forwarded_ip4=forwarded_ip4,
+ forwarded_ip5=forwarded_ip5,
+ forwarded_ip6=forwarded_ip6,
+ )
else:
raise ValueError("Unsaved IP Record not supported")
@@ -415,9 +509,7 @@ def ip_record_factory(
@pytest.fixture()
-def ip_record(
- ip_record_manager: IPRecordManager, ip_geoname: IPGeoname, user: User
-) -> IPRecord:
+def ip_record(ip_record_factory: Callable[..., IPRecord]) -> IPRecord:
return ip_record_factory(save=True)
@@ -431,7 +523,8 @@ def unsaved_ip_record(ip_record_factory: Callable[..., IPRecord]) -> IPRecord:
@pytest.fixture()
def user_factory(
- user_manager: UserManager, thl_web_rr: PostgresConfig
+ user_manager: UserManager,
+ thl_web_rr: PostgresConfig,
) -> Callable[..., User]:
def _inner(
@@ -456,8 +549,6 @@ def user_factory(
created=created,
)
- u = user_manager.create_dummy(product=product, created=created)
-
u.prefetch_product(pg_config=thl_web_rr)
return u
@@ -498,7 +589,7 @@ def user_with_wallet_amt(
return user_factory(save=True, product=product_amt_true)
-# --- User Payout ---
+# --- User Payout Event ---
@pytest.fixture
@@ -555,30 +646,47 @@ def user_payout_event_factory(
return _inner
+@pytest.fixture()
+def user_payout_event(
+ user_payout_event_factory: Callable[..., UserPayoutEvent],
+) -> UserPayoutEvent:
+ return user_payout_event_factory(save=True)
+
+
+@pytest.fixture()
+def unsaved_user_payout_event(
+ user_payout_event_factory: Callable[..., UserPayoutEvent],
+) -> UserPayoutEvent:
+ return user_payout_event_factory(save=True)
+
+
+# -- Brokerage Product Payout Event
+
+
@pytest.fixture
-def iprecord_factory(iprecord_manager: IPRecordManager) -> Callable[..., IPRecord]:
+def brokerage_product_payout_event_factory(
+ thl_ledger_manager: ThlLedgerManager,
+ brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
+ product_factory: Callable[..., Product],
+) -> Callable[..., BrokerageProductPayoutEvent]:
def _inner(
- user_id: PositiveInt,
- ip: IPvAnyAddressStr | None = None,
- forwarded_ip1: IPvAnyAddressStr | None = None,
- forwarded_ip2: IPvAnyAddressStr | None = None,
- forwarded_ip3: IPvAnyAddressStr | None = None,
- forwarded_ip4: IPvAnyAddressStr | None = None,
- forwarded_ip5: IPvAnyAddressStr | None = None,
- forwarded_ip6: IPvAnyAddressStr | None = None,
- ) -> IPRecord:
- return iprecord_manager.create(
- user_id=user_id,
- ip=ip or fake.ipv4_public(),
- forwarded_ip1=(forwarded_ip1 or fake.ipv4_public()),
- forwarded_ip2=(forwarded_ip2 or fake.ipv6() if random() < 0.5 else None),
- forwarded_ip3=(
- forwarded_ip3 or fake.ipv4_public() if random() < 0.25 else None
- ),
- forwarded_ip4=forwarded_ip4,
- forwarded_ip5=forwarded_ip5,
- forwarded_ip6=forwarded_ip6,
+ product: Product | None = None,
+ amount: USDCent | None = None,
+ ext_ref_id: str | None = None,
+ created: AwareDatetime | None = None,
+ ) -> BrokerageProductPayoutEvent:
+ from generalresearch.currency import USDCent
+
+ product = product or product_factory()
+ amount = amount or USDCent(randint(1, 99_99))
+
+ return brokerage_product_payout_event_manager.create_bp_payout_event(
+ thl_ledger_manager=thl_ledger_manager,
+ product=product,
+ amount=amount,
+ ext_ref_id=ext_ref_id or uuid4().hex,
+ created=created,
)
return _inner
diff --git a/tests/grliq/managers/test_forensic_data.py b/tests/grliq/managers/test_forensic_data.py
index 1b83757..2254829 100644
--- a/tests/grliq/managers/test_forensic_data.py
+++ b/tests/grliq/managers/test_forensic_data.py
@@ -31,7 +31,7 @@ except ImportError:
class TestGrlIqDataManager:
- def test_create_dummy(
+ def test_factory(
self,
grliq_data_factory: Callable[..., GrlIqData],
):
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,
diff --git a/tests/models/gr/test_business.py b/tests/models/gr/test_business.py
index e942be5..030a214 100644
--- a/tests/models/gr/test_business.py
+++ b/tests/models/gr/test_business.py
@@ -134,7 +134,9 @@ class TestBusiness:
thl_ledger_manager: ThlLedgerManager,
product_manager: ProductManager,
business_payout_event_manager: BusinessPayoutEventManager,
- bp_payout_factory: Callable[..., BusinessPayoutEventManager],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BusinessPayoutEventManager
+ ],
start: datetime,
user_factory: Callable[..., User],
session_with_tx_factory: Callable[..., Session],
@@ -179,7 +181,7 @@ class TestBusiness:
wall_req_cpi=Decimal("2.50"),
started=start + timedelta(days=5),
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(50),
created=start + timedelta(days=4),
@@ -329,7 +331,9 @@ class TestBusiness:
self,
gr_business: Business,
product_factory: Callable[..., Product],
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
thl_ledger_manager: ThlLedgerManager,
business_payout_event_manager: BusinessPayoutEventManager,
create_main_accounts: Callable[..., None],
@@ -341,7 +345,7 @@ class TestBusiness:
thl_lm=thl_ledger_manager
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=p, amount=USDCent(123), skip_wallet_balance_check=True
)
@@ -352,7 +356,7 @@ class TestBusiness:
assert sum([p.amount for p in gr_business.payouts]) == 123
# Add another!
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=p,
amount=USDCent(123),
skip_wallet_balance_check=True,
@@ -373,7 +377,9 @@ class TestBusiness:
self,
gr_business: Business,
product_factory: Callable[..., Product],
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
thl_ledger_manager: ThlLedgerManager,
thl_web_rr: PostgresConfig,
business_payout_event_manager: BusinessPayoutEventManager,
@@ -388,21 +394,21 @@ class TestBusiness:
thl_lm=thl_ledger_manager
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(1),
skip_wallet_balance_check=True,
skip_one_per_day_check=True,
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(25),
skip_wallet_balance_check=True,
skip_one_per_day_check=True,
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(50),
skip_wallet_balance_check=True,
@@ -633,7 +639,9 @@ class TestBusinessBalance:
user_factory: Callable[..., User],
product_manager: ProductManager,
mnt_filepath: GRLDatasets,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
thl_ledger_manager: ThlLedgerManager,
ledger_manager: LedgerManager,
start: datetime,
@@ -668,7 +676,7 @@ class TestBusinessBalance:
payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u1.product,
amount=USDCent(5),
created=start + timedelta(days=4),
@@ -676,7 +684,7 @@ class TestBusinessBalance:
skip_one_per_day_check=True,
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u2.product,
amount=USDCent(50),
created=start + timedelta(days=4),
@@ -707,7 +715,9 @@ class TestBusinessBalance:
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
mnt_filepath: GRLDatasets,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
ledger_manager: LedgerManager,
thl_ledger_manager: ThlLedgerManager,
start: datetime,
@@ -762,7 +772,7 @@ class TestBusinessBalance:
)
payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u1.product,
amount=USDCent(250),
created=start + timedelta(days=3),
@@ -770,7 +780,7 @@ class TestBusinessBalance:
skip_one_per_day_check=True,
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u2.product,
amount=USDCent(50),
created=start + timedelta(days=4),
@@ -846,7 +856,9 @@ class TestBusinessBalance:
session_with_tx_factory: Callable[..., Session],
pop_ledger_merge: PopLedgerMerge,
start: datetime,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
payout_event_manager,
product_manager: ProductManager,
adj_to_fail_with_tx_factory: Callable[..., None],
@@ -876,7 +888,7 @@ class TestBusinessBalance:
started=start + timedelta(days=1),
)
payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u1.product,
amount=USDCent(71),
ext_ref_id=uuid4().hex,
@@ -958,7 +970,9 @@ class TestBusinessBalance:
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
mnt_filepath: GRLDatasets,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
thl_ledger_manager: ThlLedgerManager,
ledger_manager: LedgerManager,
product_manager: ProductManager,
@@ -1029,7 +1043,7 @@ class TestBusinessBalance:
)
payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u1.product,
amount=USDCent(250),
created=start + timedelta(days=3),
@@ -1037,7 +1051,7 @@ class TestBusinessBalance:
skip_one_per_day_check=True,
)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=u2.product,
amount=USDCent(50),
created=start + timedelta(days=4),
diff --git a/tests/models/thl/test_product.py b/tests/models/thl/test_product.py
index f1050bb..223430f 100644
--- a/tests/models/thl/test_product.py
+++ b/tests/models/thl/test_product.py
@@ -617,7 +617,9 @@ class TestProductFinancials:
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
mnt_filepath: GRLDatasets,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
thl_ledger_manager: ThlLedgerManager,
start: datetime,
brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
@@ -716,7 +718,7 @@ class TestProductFinancials:
from generalresearch.currency import USDCent
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(50),
created=start + timedelta(days=3),
@@ -766,7 +768,7 @@ class TestProductFinancials:
# -- Now pay ou another!.
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(5),
created=start + timedelta(days=4),
@@ -843,7 +845,9 @@ class TestProductBalance:
session_with_tx_factory: Callable[..., Session],
pop_ledger_merge: PopLedgerMerge,
start: datetime,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
payout_event_manager: PayoutEventManager,
):
# Now let's load it up and actually test some things
@@ -864,7 +868,7 @@ class TestProductBalance:
# 2. Payout and build Parquets 2nd time
payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=product,
amount=USDCent(71),
ext_ref_id=uuid4().hex,
@@ -895,7 +899,9 @@ class TestProductBalance:
session_with_tx_factory: Callable[..., None],
pop_ledger_merge: PopLedgerMerge,
start: datetime,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
payout_event_manager: PayoutEventManager,
):
# This is very similar to the test_complete_payout_pq_inconsistent
@@ -923,7 +929,7 @@ class TestProductBalance:
# 2. Payout and build Parquets 2nd time but this payout is "now"
# so it hasn't already been archived
payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=product,
amount=USDCent(71),
ext_ref_id=uuid4().hex,
@@ -1114,7 +1120,9 @@ class TestProductCache:
session_with_tx_factory: Callable[..., None],
pop_ledger_merge: PopLedgerMerge,
start: datetime,
- bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
+ brokerage_product_payout_event_factory: Callable[
+ ..., BrokerageProductPayoutEvent
+ ],
payout_event_manager: PayoutEventManager,
adj_to_fail_with_tx_factory: Callable[..., None],
):
@@ -1136,7 +1144,7 @@ class TestProductCache:
# 2. Payout
payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
- bp_payout_factory(
+ brokerage_product_payout_event_factory(
product=product,
amount=USDCent(71),
ext_ref_id=uuid4().hex,