aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Nanis2026-09-01 12:29:10 -0700
committerMax Nanis2026-09-01 12:29:10 -0700
commit6469e7e55a53cfe18bd015b3c455ecbbb550cbb9 (patch)
tree15ed92293881207dc03641b6c24b24d0576185c5
parent89ed44f466dc9a93d6f85931fb6eea0e9cbd27f6 (diff)
downloadgeneralresearch-6469e7e55a53cfe18bd015b3c455ecbbb550cbb9.tar.gz
generalresearch-6469e7e55a53cfe18bd015b3c455ecbbb550cbb9.zip
WIP Business tests, fixture cleanup(s)
-rw-r--r--generalresearch/incite/base.py4
-rw-r--r--generalresearch/incite/defaults.py10
-rw-r--r--generalresearch/managers/__init__.py16
-rw-r--r--generalresearch/managers/gr/business.py3
-rw-r--r--generalresearch/managers/pollfish/user_pid.py2
-rw-r--r--generalresearch/managers/thl/cashout_method.py9
-rw-r--r--generalresearch/models/__init__.py114
-rw-r--r--generalresearch/models/gr/business.py13
-rw-r--r--generalresearch/models/gr/definitions.py13
-rw-r--r--generalresearch/models/thl/__init__.py18
-rw-r--r--generalresearch/models/thl/session.py8
-rw-r--r--generalresearch/models/thl/task_status.py2
-rw-r--r--generalresearch/models/thl/utils.py11
-rw-r--r--generalresearch/models/thl/wallet/__init__.py87
-rw-r--r--test_utils/conftest.py2
-rw-r--r--test_utils/incite/collections/conftest.py2
-rw-r--r--test_utils/incite/conftest.py10
-rw-r--r--test_utils/incite/mergers/conftest.py16
-rw-r--r--test_utils/managers/gr/conftest.py28
-rw-r--r--test_utils/managers/thl/conftest.py37
-rw-r--r--test_utils/models/conftest.py4
-rw-r--r--test_utils/models/contest/conftest.py12
-rw-r--r--test_utils/models/gr/conftest.py2
-rw-r--r--test_utils/models/ledger/conftest.py108
-rw-r--r--tests/incite/collections/test_df_collection_base.py6
-rw-r--r--tests/incite/collections/test_df_collection_item_base.py6
-rw-r--r--tests/incite/test_interval_idx.py2
-rw-r--r--tests/managers/gr/test_business.py32
-rw-r--r--tests/managers/thl/test_ledger/test_lm_accounts.py96
-rw-r--r--tests/managers/thl/test_ledger/test_thl_lm_tx.py5
-rw-r--r--tests/managers/thl/test_payout.py176
-rw-r--r--tests/managers/thl/test_session_manager.py10
-rw-r--r--tests/models/gr/test_authentication.py55
-rw-r--r--tests/models/gr/test_business.py86
-rw-r--r--tests/models/gr/test_team.py6
-rw-r--r--tests/models/test_finance.py14
-rw-r--r--tests/models/thl/test_payout.py2
-rw-r--r--tests/models/thl/test_product.py99
38 files changed, 484 insertions, 642 deletions
diff --git a/generalresearch/incite/base.py b/generalresearch/incite/base.py
index 473a124..a06aac9 100644
--- a/generalresearch/incite/base.py
+++ b/generalresearch/incite/base.py
@@ -95,7 +95,7 @@ class GRLDatasets(BaseModel):
from generalresearch.incite.collections.thl_marketplaces import (
DFCollectionType,
)
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
assert self.data_src, "data src must be defined"
@@ -128,7 +128,7 @@ class GRLDatasets(BaseModel):
type..
"""
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
folder = "mergers" if isinstance(enum_type, MergeType) else "raw/df-collections"
assert self.incite is not None
diff --git a/generalresearch/incite/defaults.py b/generalresearch/incite/defaults.py
index 368b74a..5ee305b 100644
--- a/generalresearch/incite/defaults.py
+++ b/generalresearch/incite/defaults.py
@@ -3,7 +3,7 @@ from __future__ import annotations
from datetime import UTC, datetime
from generalresearch.incite.base import GRLDatasets
-from generalresearch.incite.collections import DFCollectionType
+from generalresearch.incite.collections.base import DFCollectionType
from generalresearch.incite.collections.thl_marketplaces import (
InnovateSurveyHistoryCollection,
MorningSurveyTimeseriesCollection,
@@ -82,7 +82,7 @@ def ledger_df_collection(
ds: GRLDatasets, pg_config: PostgresConfig
) -> LedgerDFCollection:
return LedgerDFCollection(
- offset="12d",
+ offset="12D",
pg_config=pg_config,
# thl_web:ledger_transaction - 1st record is 2018-03-14 20:22:17.408232
start=datetime(year=2018, month=3, day=14, hour=0, tzinfo=UTC),
@@ -153,7 +153,7 @@ def user_id_product(ds: GRLDatasets) -> UserIdProductMerge:
def enriched_session(ds: GRLDatasets) -> EnrichedSessionMerge:
return EnrichedSessionMerge(
start=datetime(year=2023, month=5, day=1, tzinfo=UTC),
- offset="14d",
+ offset="14D",
archive_path=ds.archive_path(enum_type=MergeType.ENRICHED_SESSION),
)
@@ -162,7 +162,7 @@ def enriched_wall(ds: GRLDatasets) -> EnrichedWallMerge:
return EnrichedWallMerge(
# start=datetime(year=2022, month=5, day=1, tzinfo=timezone.utc),
start=datetime(year=2023, month=7, day=23, tzinfo=UTC),
- offset="14d",
+ offset="14D",
archive_path=ds.archive_path(enum_type=MergeType.ENRICHED_WALL),
)
@@ -180,7 +180,7 @@ def pop_ledger(ds: GRLDatasets) -> PopLedgerMerge:
return PopLedgerMerge(
# thl_web:ledger_transaction - 1st record is 2018-03-14 20:22:17.408232
start=datetime(year=2018, month=3, day=14, hour=0, tzinfo=UTC),
- offset="30d",
+ offset="30D",
archive_path=ds.archive_path(enum_type=MergeType.POP_LEDGER),
)
diff --git a/generalresearch/managers/__init__.py b/generalresearch/managers/__init__.py
index bc745fd..e69de29 100644
--- a/generalresearch/managers/__init__.py
+++ b/generalresearch/managers/__init__.py
@@ -1,16 +0,0 @@
-def parse_order_by(order_by_str: str) -> str:
- """
- Converts django-rest-framework ordering str to mysql clause
- :param order_by_str: e.g. 'created,-name'
- :return: mysql clause e.g. ORDER BY created ASC, name DESC
- """
- fields = order_by_str.split(",")
-
- order_clause = []
- for field in fields:
- if field.startswith("-"):
- order_clause.append(f"{field[1:]} DESC")
- else:
- order_clause.append(f"{field} ASC")
-
- return "ORDER BY " + ", ".join(order_clause)
diff --git a/generalresearch/managers/gr/business.py b/generalresearch/managers/gr/business.py
index ef26f30..9bf6ef2 100644
--- a/generalresearch/managers/gr/business.py
+++ b/generalresearch/managers/gr/business.py
@@ -14,14 +14,13 @@ from generalresearch.managers.base import (
from generalresearch.models.gr.business import (
Business,
BusinessBankAccount,
- BusinessType,
)
+from generalresearch.models.gr.definitions import BusinessType, TransferMethod
if TYPE_CHECKING:
from generalresearch.models.custom_types import UUIDStr
from generalresearch.models.gr.business import (
BusinessAddress,
- TransferMethod,
)
from generalresearch.models.gr.team import Team
diff --git a/generalresearch/managers/pollfish/user_pid.py b/generalresearch/managers/pollfish/user_pid.py
index 1068405..f3983cf 100644
--- a/generalresearch/managers/pollfish/user_pid.py
+++ b/generalresearch/managers/pollfish/user_pid.py
@@ -1,5 +1,5 @@
from generalresearch.managers.marketplace.user_pid import UserPidManager
-from generalresearch.models import Source
+from generalresearch.models.definitions import Source
class PollfishUserPidManager(UserPidManager):
diff --git a/generalresearch/managers/thl/cashout_method.py b/generalresearch/managers/thl/cashout_method.py
index c12c920..ee86bec 100644
--- a/generalresearch/managers/thl/cashout_method.py
+++ b/generalresearch/managers/thl/cashout_method.py
@@ -9,15 +9,13 @@ from uuid import UUID, uuid4
from pydantic import NonNegativeInt
from generalresearch.managers.base import PostgresManager
-from generalresearch.models.thl.wallet.cashout_method import (
- CashoutMethod,
-)
from generalresearch.models.thl.wallet.definitions import PayoutType
if TYPE_CHECKING:
from generalresearch.models.thl.user import User
from generalresearch.models.thl.wallet.cashout_method import (
CashMailCashoutMethodData,
+ CashoutMethod,
PaypalCashoutMethodData,
)
@@ -82,6 +80,7 @@ class CashoutMethodManager(PostgresManager):
:return: the uuid of the created cashout method
"""
# todo: validate shipping address?
+ from generalresearch.models.thl.wallet.cashout_method import CashoutMethod
cm = CashoutMethod(
name="Cash in Mail",
@@ -126,6 +125,8 @@ class CashoutMethodManager(PostgresManager):
:param user:
:return: the uuid of the created cashout method
"""
+ from generalresearch.models.thl.wallet.cashout_method import CashoutMethod
+
cm = CashoutMethod(
name="PayPal",
description="Cashout via PayPal",
@@ -290,6 +291,8 @@ class CashoutMethodManager(PostgresManager):
# The data column here is inconsistent. Pulling keys from the mysql 'data' col
# and putting them into the base level. Renamed so that we don't overwrite
# a col called "data" within the "_data_" field.
+ from generalresearch.models.thl.wallet.cashout_method import CashoutMethod
+
for k in list(x["_data_"].keys()):
if k in CashoutMethod.model_fields:
x[k] = x["_data_"].pop(k)
diff --git a/generalresearch/models/__init__.py b/generalresearch/models/__init__.py
index c0348d7..e69de29 100644
--- a/generalresearch/models/__init__.py
+++ b/generalresearch/models/__init__.py
@@ -1,114 +0,0 @@
-from __future__ import annotations
-
-from enum import IntEnum, StrEnum
-
-from generalresearch.utils.enum import ReprEnumMeta
-
-
-class Source(StrEnum, metaclass=ReprEnumMeta):
- # The external marketplace, or the source of the survey / work.
- # Max length of the value is 2.
- GRS = "g"
- CINT = "c"
- DALIA = "a" # deprecated
- DYNATA = "d"
- ETX = "et"
- FULL_CIRCLE = "f"
- INNOVATE = "i"
- LUCID = "l"
- MORNING_CONSULT = "m"
- OPEN_LABS = "n"
- POLLFISH = "o"
- PRECISION = "e"
- PRODEGE_USER = "r" # deprecated
- PRODEGE = "pr" # using 'r' for vendor_wall
- PULLEY = "p" # deprecated
- REPDATA = "rd" # using 'q' for vendor_wall
- SAGO = "h"
- SPECTRUM = "s"
- TESTING = "t" # Used internally for testing
- TESTING2 = "u" # Used internally for testing
- WXET = "w"
-
-
-class DebitKey(IntEnum, metaclass=ReprEnumMeta):
- # The debit key for marketplaces
- CINT = 8
- DALIA = 9
- DYNATA = 6
- # ETX = None
- FULL_CIRCLE = 15
- INNOVATE = 7
- LUCID = 0
- MORNING_CONSULT = 12
- # OPEN_LABS = None
- POLLFISH = 13
- PRECISION = 14
- PRODEGE = 11
- SAGO = 10
- SPECTRUM = 5
- # WXET = None
-
-
-class DeviceType(IntEnum, metaclass=ReprEnumMeta):
- UNKNOWN = 0
- MOBILE = 1
- DESKTOP = 2
- TABLET = 3
-
-
-class LogicalOperator(StrEnum, metaclass=ReprEnumMeta):
- OR = "OR"
- AND = "AND"
- # There is currently no use case for NOT. See MarketplaceCondition.explain_not
- NOT = "NOT"
-
-
-class TaskStatus(StrEnum, metaclass=ReprEnumMeta):
- # A survey is live if it is open and, given all conditions are met, is
- # possible to send in traffic. All other statuses are just variants of
- # NOT Live (not accepting traffic)
- LIVE = "LIVE"
-
- # This is a generic NOT Live status. A marketplace may use other more
- # specific statuses but in practice they don't matter because all we care
- # about is if the task is LIVE.
- NOT_LIVE = "NOT_LIVE"
-
- # We need a status to mark if a survey we thought was live does not come
- # back from the API, we'll mark it as NOT_FOUND.
- NOT_FOUND = "NOT_FOUND"
-
-
-class TaskCalculationType(StrEnum):
- COMPLETES = "COMPLETES"
- STARTS = "STARTS"
-
- @classmethod
- def from_api(cls, v: str) -> TaskCalculationType:
- return {
- "complete": cls.COMPLETES,
- "completes": cls.COMPLETES,
- "survey start": cls.STARTS,
- "survey starts": cls.STARTS,
- "start": cls.STARTS,
- "prescreens": cls.STARTS,
- "prescreen": cls.STARTS,
- }[v.lower()]
-
- @classmethod
- def prodege_from_api(cls, v: int) -> TaskCalculationType:
- return {1: cls.COMPLETES, 2: cls.STARTS}[v]
-
- @classmethod
- def innovate_from_api(cls, v: int) -> TaskCalculationType:
- return {0: cls.COMPLETES, 1: cls.STARTS}[v]
-
-
-class URLQueryKey(StrEnum, metaclass=ReprEnumMeta):
- PRODUCT_ID = "39057c8b"
- PRODUCT_USER_ID = "c184efc0"
- SESSION_ID = "0bb50182"
-
-
-MAX_INT32 = 2**31
diff --git a/generalresearch/models/gr/business.py b/generalresearch/models/gr/business.py
index e11c54d..c6d3468 100644
--- a/generalresearch/models/gr/business.py
+++ b/generalresearch/models/gr/business.py
@@ -4,7 +4,6 @@ import json
import logging
import os
from datetime import UTC, datetime
-from enum import Enum, StrEnum
from pathlib import Path
from typing import TYPE_CHECKING
from uuid import uuid4
@@ -29,11 +28,11 @@ from generalresearch.models.custom_types import (
UUIDStr,
UUIDStrCoerce,
)
+from generalresearch.models.gr.definitions import BusinessType, TransferMethod
from generalresearch.models.gr.team import Team
from generalresearch.models.thl.finance import BusinessBalances, POPFinancial
from generalresearch.models.thl.ledger import OrderBy
from generalresearch.utils.aggregation import group_by_year
-from generalresearch.utils.enum import ReprEnumMeta
if TYPE_CHECKING:
from generalresearch.incite.mergers.pop_ledger import PopLedgerMerge
@@ -69,16 +68,6 @@ if TYPE_CHECKING:
from generalresearch.models.thl.product import Product
-class TransferMethod(Enum, metaclass=ReprEnumMeta):
- ACH = 0
- WIRE = 1
-
-
-class BusinessType(StrEnum, metaclass=ReprEnumMeta):
- INDIVIDUAL = "i"
- COMPANY = "c"
-
-
class BusinessBankAccount(BaseModel):
model_config = ConfigDict(
use_enum_values=True,
diff --git a/generalresearch/models/gr/definitions.py b/generalresearch/models/gr/definitions.py
new file mode 100644
index 0000000..2e06c03
--- /dev/null
+++ b/generalresearch/models/gr/definitions.py
@@ -0,0 +1,13 @@
+from enum import Enum, StrEnum
+
+from generalresearch.utils.enum import ReprEnumMeta
+
+
+class TransferMethod(Enum, metaclass=ReprEnumMeta):
+ ACH = 0
+ WIRE = 1
+
+
+class BusinessType(StrEnum, metaclass=ReprEnumMeta):
+ INDIVIDUAL = "i"
+ COMPANY = "c"
diff --git a/generalresearch/models/thl/__init__.py b/generalresearch/models/thl/__init__.py
index 7f2b8a9..45278f8 100644
--- a/generalresearch/models/thl/__init__.py
+++ b/generalresearch/models/thl/__init__.py
@@ -1,14 +1,12 @@
-from decimal import Decimal
-
# from generalresearch.models.thl.finance import (
# POPFinancial,
# ProductBalances,
# )
# from generalresearch.models.thl.payout import (
-# BrokerageProductPayoutEvent,
+# # BrokerageProductPayoutEvent,
# PayoutEvent,
# )
-from generalresearch.models.thl.product import Product
+# from generalresearch.models.thl.product import Product
# _ = (
# Product,
@@ -18,16 +16,6 @@ from generalresearch.models.thl.product import Product
# POPFinancial,
# )
-Product.model_rebuild()
+# Product.model_rebuild()
# PayoutEvent.model_rebuild()
# BrokerageProductPayoutEvent.model_rebuild()
-
-
-def decimal_to_int_cents(usd: Decimal | None) -> int | None:
- return round(usd * 100) if usd is not None else None
-
-
-def int_cents_to_decimal(value: int | None, decimals: int = 2) -> Decimal | None:
- if value is None:
- return None
- return (Decimal(value) / Decimal(100)).quantize(Decimal(10) ** -decimals)
diff --git a/generalresearch/models/thl/session.py b/generalresearch/models/thl/session.py
index 404cff7..65b885e 100644
--- a/generalresearch/models/thl/session.py
+++ b/generalresearch/models/thl/session.py
@@ -19,10 +19,6 @@ from pydantic import (
)
from generalresearch.models.definitions import Source
-from generalresearch.models.thl import (
- decimal_to_int_cents,
- int_cents_to_decimal,
-)
from generalresearch.models.thl.definitions import (
WALL_ALLOWED_STATUS_CODE_1_2,
WALL_ALLOWED_STATUS_STATUS_CODE,
@@ -32,6 +28,10 @@ from generalresearch.models.thl.definitions import (
WallAdjustedStatus,
WallStatusCode2,
)
+from generalresearch.models.thl.utils import (
+ decimal_to_int_cents,
+ int_cents_to_decimal,
+)
if TYPE_CHECKING:
from generalresearch.managers.thl.ledger_manager.thl_ledger import (
diff --git a/generalresearch/models/thl/task_status.py b/generalresearch/models/thl/task_status.py
index 817f4c5..6cff884 100644
--- a/generalresearch/models/thl/task_status.py
+++ b/generalresearch/models/thl/task_status.py
@@ -13,7 +13,6 @@ from pydantic import (
model_validator,
)
-from generalresearch.models.thl import decimal_to_int_cents
from generalresearch.models.thl.definitions import (
SessionAdjustedStatus,
SessionStatusCode2,
@@ -25,6 +24,7 @@ from generalresearch.models.thl.payout_format import (
PayoutFormatOptionalField,
)
from generalresearch.models.thl.session import WallOut
+from generalresearch.models.thl.utils import decimal_to_int_cents
if TYPE_CHECKING:
from generalresearch.models.custom_types import (
diff --git a/generalresearch/models/thl/utils.py b/generalresearch/models/thl/utils.py
new file mode 100644
index 0000000..3e14065
--- /dev/null
+++ b/generalresearch/models/thl/utils.py
@@ -0,0 +1,11 @@
+from decimal import Decimal
+
+
+def decimal_to_int_cents(usd: Decimal | None) -> int | None:
+ return round(usd * 100) if usd is not None else None
+
+
+def int_cents_to_decimal(value: int | None, decimals: int = 2) -> Decimal | None:
+ if value is None:
+ return None
+ return (Decimal(value) / Decimal(100)).quantize(Decimal(10) ** -decimals)
diff --git a/generalresearch/models/thl/wallet/__init__.py b/generalresearch/models/thl/wallet/__init__.py
index 2d1eb8d..e69de29 100644
--- a/generalresearch/models/thl/wallet/__init__.py
+++ b/generalresearch/models/thl/wallet/__init__.py
@@ -1,87 +0,0 @@
-from enum import StrEnum
-
-from generalresearch.utils.enum import ReprEnumMeta
-
-
-class PayoutType(StrEnum, metaclass=ReprEnumMeta):
- """
- The method in which the requested payout is delivered.
- """
-
- # The max size of the db field that holds this value is 14, so please
- # don't add new values longer than that!
-
- # User is paid out to their personal PayPal email address
- PAYPAL = "PAYPAL"
- # User is paid out via a Tango Gift Card
- TANGO = "TANGO"
- # DWOLLA
- DWOLLA = "DWOLLA"
- # A payment is made to a bank account using ACH
- ACH = "ACH"
- # A payment is made to a bank account using ACH
- WIRE = "WIRE"
- # A payment is made in cash and mailed to the user.
- CASH_IN_MAIL = "CASH_IN_MAIL"
- # A payment is made as a prize with some monetary value
- PRIZE = "PRIZE"
-
- # This is used to designate either AMT_BONUS or AMT_HIT
- AMT = "AMT"
- # Amazon Mechanical Turk as a Bonus
- AMT_BONUS = "AMT_BONUS"
- # Amazon Mechanical Turk for a HIT
- AMT_HIT = "AMT_ASSIGNMENT"
- AMT_ASSIGNMENT = "AMT_ASSIGNMENT"
-
-
-class Currency(StrEnum):
- # United States Dollar
- USD = "USD"
- # Canadian Dollar
- CAD = "CAD"
- # British Pound Sterling
- GBP = "GBP"
- # Euro
- EUR = "EUR"
- # Indian Rupee
- INR = "INR"
- # Australian Dollar
- AUD = "AUD"
- # Polish Zloty
- PLN = "PLN"
- # Swedish Krona
- SEK = "SEK"
- # Singapore Dollar
- SGD = "SGD"
- # Mexican Peso
- MXN = "MXN"
-
-
-CURRENCY_FORMATTER = {
- "USD": lambda x: f"${x / 100:,.2f}",
- "CAD": lambda x: f"${x / 100:,.2f} CAD",
- "GBP": lambda x: f"{x / 100:,.2f} £",
- "EUR": lambda x: f"€{x / 100:,.2f}",
- "INR": lambda x: f"₹{x / 100:,.2f}",
- "AUD": lambda x: f"${x / 100:,.2f} AUD",
- "PLN": lambda x: f"{x / 100:,.2f} zł",
- "SEK": lambda x: f"{x / 100:,.2f} kr",
- "SGD": lambda x: f"${x / 100:,.2f} SGD",
- "MXN": lambda x: f"${x / 100:,.2f} MXN",
-}
-
-# The max value user can redeem in one go in foreign currencies. should be < $250
-# in order to avoid exchange rate issues
-CURRENCY_MAX_VALUE = {
- "USD": 250,
- "CAD": 200,
- "GBP": 100,
- "EUR": 100,
- "INR": 10000,
- "AUD": 200,
- "PLN": 500,
- "SEK": 1000,
- "SGD": 200,
- "MXN": 4000,
-}
diff --git a/test_utils/conftest.py b/test_utils/conftest.py
index 397d98f..daf6b43 100644
--- a/test_utils/conftest.py
+++ b/test_utils/conftest.py
@@ -342,7 +342,7 @@ def delete_df_collection(
thl_web_rw: PostgresConfig, create_main_accounts: Callable[..., None]
) -> Callable[..., None]:
- from generalresearch.incite.collections import (
+ from generalresearch.incite.collections.base import (
DFCollection,
DFCollectionType,
)
diff --git a/test_utils/incite/collections/conftest.py b/test_utils/incite/collections/conftest.py
index f490e14..499f90b 100644
--- a/test_utils/incite/collections/conftest.py
+++ b/test_utils/incite/collections/conftest.py
@@ -197,7 +197,7 @@ def df_collection(
utc_90days_ago: datetime,
thl_web_rr: PostgresConfig,
) -> DFCollection:
- from generalresearch.incite.collections import DFCollection
+ from generalresearch.incite.collections.base import DFCollection
start = utc_90days_ago.replace(microsecond=0)
diff --git a/test_utils/incite/conftest.py b/test_utils/incite/conftest.py
index 2968d18..bcf0511 100644
--- a/test_utils/incite/conftest.py
+++ b/test_utils/incite/conftest.py
@@ -16,11 +16,11 @@ from faker import Faker
if TYPE_CHECKING:
from generalresearch.config import GRLBaseSettings
from generalresearch.incite.base import GRLDatasets
- from generalresearch.incite.collections import (
+ from generalresearch.incite.collections.base import (
DFCollectionItem,
DFCollectionType,
)
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
from generalresearch.models.admin.request import (
ReportRequest,
)
@@ -131,14 +131,14 @@ def duration() -> timedelta | None:
@pytest.fixture
def df_collection_data_type() -> DFCollectionType:
- from generalresearch.incite.collections import DFCollectionType
+ from generalresearch.incite.collections.base import DFCollectionType
return DFCollectionType.TEST
@pytest.fixture
def merge_type() -> MergeType:
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
return MergeType.TEST
@@ -156,7 +156,7 @@ def incite_item_factory(
observations: int = 3,
user: User | None = None,
):
- from generalresearch.incite.collections import (
+ from generalresearch.incite.collections.base import (
DFCollection,
DFCollectionType,
)
diff --git a/test_utils/incite/mergers/conftest.py b/test_utils/incite/mergers/conftest.py
index 4eb3f2d..fb95c81 100644
--- a/test_utils/incite/mergers/conftest.py
+++ b/test_utils/incite/mergers/conftest.py
@@ -58,7 +58,7 @@ def pop_ledger_merge(
duration: timedelta,
) -> PopLedgerMerge:
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
from generalresearch.incite.mergers.pop_ledger import PopLedgerMerge
return PopLedgerMerge(
@@ -88,7 +88,7 @@ def ym_survey_wall_merge(
mnt_filepath: GRLDatasets,
start: datetime,
) -> YMSurveyWallMerge:
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
from generalresearch.incite.mergers.ym_survey_wall import YMSurveyWallMerge
return YMSurveyWallMerge(
@@ -119,7 +119,7 @@ def ym_wall_summary_merge(
duration: timedelta,
start: datetime,
) -> YMWallSummaryMerge:
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
from generalresearch.incite.mergers.ym_wall_summary import YMWallSummaryMerge
return YMWallSummaryMerge(
@@ -155,7 +155,7 @@ def enriched_session_merge(
duration: timedelta,
start: datetime,
) -> EnrichedSessionMerge:
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
from generalresearch.incite.mergers.foundations.enriched_session import (
EnrichedSessionMerge,
)
@@ -175,7 +175,7 @@ def enriched_task_adjust_merge(
duration: timedelta,
start: datetime,
) -> EnrichedTaskAdjustMerge:
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
from generalresearch.incite.mergers.foundations.enriched_task_adjust import (
EnrichedTaskAdjustMerge,
)
@@ -197,7 +197,7 @@ def enriched_wall_merge(
duration: timedelta,
start: datetime,
) -> EnrichedWallMerge:
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
from generalresearch.incite.mergers.foundations.enriched_wall import (
EnrichedWallMerge,
)
@@ -217,7 +217,7 @@ def user_id_product_merge(
offset: str,
start: datetime,
) -> UserIdProductMerge:
- from generalresearch.incite.mergers import MergeType
+ from generalresearch.incite.mergers.base import MergeType
from generalresearch.incite.mergers.foundations.user_id_product import (
UserIdProductMerge,
)
@@ -243,7 +243,7 @@ def merge_collection(
duration: timedelta,
start: datetime,
):
- from generalresearch.incite.mergers import MergeCollection
+ from generalresearch.incite.mergers.base import MergeCollection
return MergeCollection(
merge_type=merge_type,
diff --git a/test_utils/managers/gr/conftest.py b/test_utils/managers/gr/conftest.py
index 5392c69..a7fa9e9 100644
--- a/test_utils/managers/gr/conftest.py
+++ b/test_utils/managers/gr/conftest.py
@@ -9,7 +9,6 @@ import pytest
import redis
import redis.asyncio as redis_async
from pydantic import PostgresDsn
-from redis import Redis
from generalresearch.managers.gr.business import (
BusinessAddressManager,
@@ -31,33 +30,6 @@ def gr_redis_config_db() -> str:
@pytest.fixture(scope="session")
-def gr_redis(settings: GRLBaseSettings) -> Redis:
- assert "unittest" in str(settings.testing_redis) or "127.0.0.1" in str(
- settings.testing_redis
- )
- return Redis.from_url(
- url=str(settings.gr_redis),
- decode_responses=True,
- socket_timeout=settings.redis_timeout,
- socket_connect_timeout=settings.redis_timeout,
- )
-
-
-@pytest.fixture
-def gr_redis_async(settings: GRLBaseSettings) -> redis_async.Redis:
- assert "unittest" in str(settings.testing_redis) or "127.0.0.1" in str(
- settings.testing_redis
- )
-
- return redis_async.Redis.from_url(
- str(settings.testing_redis),
- decode_responses=True,
- socket_timeout=0.20,
- socket_connect_timeout=0.20,
- )
-
-
-@pytest.fixture(scope="session")
def gr_redis_config(
settings: GRLBaseSettings, gr_redis_config_db: str
) -> Generator[RedisConfig]:
diff --git a/test_utils/managers/thl/conftest.py b/test_utils/managers/thl/conftest.py
index af3fd23..391b74c 100644
--- a/test_utils/managers/thl/conftest.py
+++ b/test_utils/managers/thl/conftest.py
@@ -1,9 +1,12 @@
from __future__ import annotations
-from collections.abc import Callable
+import subprocess
+from collections.abc import Callable, Generator
+from random import randint
from typing import TYPE_CHECKING
import pytest
+import redis
from pydantic import PostgresDsn
from generalresearch.managers.base import Permission
@@ -59,14 +62,40 @@ def thl_web_rw(thl_web_rr: PostgresConfig) -> PostgresConfig:
@pytest.fixture(scope="session")
-def thl_redis_config(settings: GRLBaseSettings) -> RedisConfig:
- return RedisConfig(
- dsn=settings.thl_redis,
+def thl_redis_config_db() -> str:
+ return str(randint(99, 1_023))
+
+
+@pytest.fixture(scope="session")
+def thl_redis_config(
+ settings: GRLBaseSettings, thl_redis_config_db: str
+) -> Generator[RedisConfig]:
+ assert "unittest" in str(settings.testing_redis) or "127.0.0.1" in str(
+ settings.testing_redis
+ )
+
+ uri = f"redis://{settings.testing_redis}/{thl_redis_config_db}"
+
+ res = subprocess.run(
+ ["redis-cli", "-u", uri, "SET", "jenkins_lock", "1", "NX", "EX", "3600"],
+ check=True,
+ text=True,
+ capture_output=True,
+ )
+
+ if res.stdout.strip() != "OK":
+ raise ValueError("Redis already locked... aborting.")
+
+ yield RedisConfig(
+ dsn=uri,
decode_responses=True,
socket_timeout=settings.redis_timeout,
socket_connect_timeout=settings.redis_timeout,
)
+ r = redis.from_url(uri)
+ r.flushdb()
+
@pytest.fixture(scope="session")
def payout_event_manager(
diff --git a/test_utils/models/conftest.py b/test_utils/models/conftest.py
index 089f2e6..ed4da08 100644
--- a/test_utils/models/conftest.py
+++ b/test_utils/models/conftest.py
@@ -370,7 +370,7 @@ def product_amt_true(
@pytest.fixture
def bp_payout_factory(
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
product_manager: ProductManager,
business_payout_event_manager: BusinessPayoutEventManager,
) -> Callable[..., BrokerageProductPayoutEvent]:
@@ -389,7 +389,7 @@ def bp_payout_factory(
amount = amount or USDCent(randint(1, 99_99))
return business_payout_event_manager.create_bp_payout_event(
- thl_ledger_manager=thl_lm,
+ thl_ledger_manager=thl_ledger_manager,
product=product,
amount=amount,
ext_ref_id=ext_ref_id or uuid4().hex,
diff --git a/test_utils/models/contest/conftest.py b/test_utils/models/contest/conftest.py
index 91425dc..18a8e5f 100644
--- a/test_utils/models/contest/conftest.py
+++ b/test_utils/models/contest/conftest.py
@@ -275,24 +275,26 @@ def user_with_money(
request: Request,
user_factory: Callable[..., User],
product_user_wallet_yes: Product,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
) -> User:
params = getattr(request, "param", {}) or {}
min_balance = int(params.get("min_balance", USDCent(1_00)))
user: User = user_factory(product=product_user_wallet_yes)
- wallet = thl_lm.get_account_or_create_user_wallet(user)
- balance = thl_lm.get_account_balance(wallet)
+ wallet = thl_ledger_manager.get_account_or_create_user_wallet(user)
+ balance = thl_ledger_manager.get_account_balance(wallet)
todo = min_balance - balance
if todo > 0:
# # Put money in user's wallet
- thl_lm.create_tx_user_bonus(
+ thl_ledger_manager.create_tx_user_bonus(
user=user,
ref_uuid=uuid4().hex,
description="bonus",
amount=Decimal(todo) / 100,
)
- print(f"wallet balance: {thl_lm.get_user_wallet_balance(user=user)}")
+ print(
+ f"wallet balance: {thl_ledger_manager.get_user_wallet_balance(user=user)}"
+ )
return user
diff --git a/test_utils/models/gr/conftest.py b/test_utils/models/gr/conftest.py
index 6c1877a..e493f20 100644
--- a/test_utils/models/gr/conftest.py
+++ b/test_utils/models/gr/conftest.py
@@ -23,8 +23,8 @@ if TYPE_CHECKING:
Business,
BusinessAddress,
BusinessBankAccount,
- TransferMethod,
)
+ from generalresearch.models.gr.definitions import TransferMethod
from generalresearch.models.gr.team import Membership, Team
from generalresearch.pg_helper import PostgresConfig
from generalresearch.redis_helper import RedisConfig
diff --git a/test_utils/models/ledger/conftest.py b/test_utils/models/ledger/conftest.py
index 8437c7f..31e5eb4 100644
--- a/test_utils/models/ledger/conftest.py
+++ b/test_utils/models/ledger/conftest.py
@@ -65,7 +65,7 @@ if TYPE_CHECKING:
@pytest.fixture
def ledger_account(
- request: Request, lm: LedgerManager, currency: LedgerCurrency
+ request: Request, ledger_manager: LedgerManager, currency: LedgerCurrency
) -> LedgerAccount:
from generalresearch.models.thl.ledger import (
AccountType,
@@ -87,14 +87,14 @@ def ledger_account(
account_type=account_type,
normal_balance=direction,
)
- return lm.create_account(account=acct_model)
+ return ledger_manager.create_account(account=acct_model)
@pytest.fixture
def ledger_account_factory(
request: Request,
- thl_lm: ThlLedgerManager,
- lm: LedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
+ ledger_manager: LedgerManager,
currency: LedgerCurrency,
) -> Callable[..., LedgerAccount]:
@@ -109,7 +109,7 @@ def ledger_account_factory(
account_type: AccountType = AccountType.CASH,
direction: Direction = Direction.CREDIT,
) -> LedgerAccount:
- thl_lm.get_account_or_create_bp_wallet(product=product)
+ thl_ledger_manager.get_account_or_create_bp_wallet(product=product)
acct_uuid = uuid4().hex
qn = f"{currency}:{account_type}:{acct_uuid}"
@@ -121,14 +121,14 @@ def ledger_account_factory(
account_type=account_type,
normal_balance=direction,
)
- return lm.create_account(account=acct_model)
+ return ledger_manager.create_account(account=acct_model)
return _inner
@pytest.fixture
def ledger_account_credit(
- request: Request, lm: LedgerManager, currency: LedgerCurrency
+ request: Request, ledger_manager: LedgerManager, currency: LedgerCurrency
) -> LedgerAccount:
from generalresearch.models.thl.ledger import AccountType, Direction
@@ -146,12 +146,12 @@ def ledger_account_credit(
account_type=account_type,
normal_balance=Direction.CREDIT,
)
- return lm.create_account(account=acct_model)
+ return ledger_manager.create_account(account=acct_model)
@pytest.fixture
def ledger_account_debit(
- request: Request, lm: LedgerManager, currency: LedgerCurrency
+ request: Request, ledger_manager: LedgerManager, currency: LedgerCurrency
) -> LedgerAccount:
from generalresearch.models.thl.ledger import AccountType, Direction
@@ -169,11 +169,11 @@ def ledger_account_debit(
account_type=account_type,
normal_balance=Direction.DEBIT,
)
- return lm.create_account(account=acct_model)
+ return ledger_manager.create_account(account=acct_model)
@pytest.fixture
-def tag(request: Request, lm: LedgerManager) -> str:
+def tag(request: Request) -> str:
from generalresearch.currency import LedgerCurrency
return (
@@ -194,11 +194,11 @@ def bp_payout_event(
product: Product,
usd_cent: USDCent,
business_payout_event_manager: BusinessPayoutEventManager,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
) -> BrokerageProductPayoutEvent:
return business_payout_event_manager.create_bp_payout_event(
- thl_ledger_manager=thl_lm,
+ thl_ledger_manager=thl_ledger_manager,
product=product,
amount=usd_cent,
skip_wallet_balance_check=True,
@@ -209,7 +209,7 @@ def bp_payout_event(
@pytest.fixture
def bp_payout_event_factory(
brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
) -> Callable[..., BrokerageProductPayoutEvent]:
def _inner(
@@ -217,7 +217,7 @@ def bp_payout_event_factory(
) -> BrokerageProductPayoutEvent:
return brokerage_product_payout_event_manager.create_bp_payout_event(
- thl_ledger_manager=thl_lm,
+ thl_ledger_manager=thl_ledger_manager,
product=product,
amount=usd_cent,
ext_ref_id=ext_ref_id,
@@ -229,10 +229,12 @@ def bp_payout_event_factory(
@pytest.fixture
-def currency(lm: LedgerManager) -> LedgerCurrency:
+def currency(ledger_manager: LedgerManager) -> LedgerCurrency:
# return request.param if hasattr(request, "currency") else LedgerCurrency.TEST
- assert lm.currency, "LedgerManager must have a currency specified for these tests"
- return lm.currency
+ assert (
+ ledger_manager.currency
+ ), "LedgerManager must have a currency specified for these tests"
+ return ledger_manager.currency
@pytest.fixture
@@ -252,7 +254,7 @@ def ledger_tx(
tag: str,
currency: LedgerCurrency,
tx_metadata: dict[str, str] | None,
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
) -> LedgerTransaction:
from generalresearch.models.thl.ledger import Direction, LedgerEntry
@@ -271,12 +273,12 @@ def ledger_tx(
),
]
- return lm.create_tx(entries=entries, tag=tag, metadata=tx_metadata)
+ return ledger_manager.create_tx(entries=entries, tag=tag, metadata=tx_metadata)
@pytest.fixture
def create_main_accounts(
- lm: LedgerManager, currency: LedgerCurrency
+ ledger_manager: LedgerManager, currency: LedgerCurrency
) -> Callable[..., None]:
def _inner() -> None:
@@ -291,9 +293,9 @@ def create_main_accounts(
qualified_name=f"{currency.value}:revenue:task_complete",
normal_balance=Direction.CREDIT,
account_type=AccountType.REVENUE,
- currency=lm.currency,
+ currency=ledger_manager.currency,
)
- lm.get_account_or_create(account=account)
+ ledger_manager.get_account_or_create(account=account)
account = LedgerAccount(
display_name="Operating Cash Account",
@@ -303,7 +305,7 @@ def create_main_accounts(
currency=currency,
)
- lm.get_account_or_create(account=account)
+ ledger_manager.get_account_or_create(account=account)
return _inner
@@ -327,7 +329,7 @@ def delete_ledger_db(thl_web_rw: PostgresManager) -> Callable[..., None]:
@pytest.fixture
def wipe_main_accounts(
- thl_web_rw: PostgresManager, lm: LedgerManager, currency: LedgerCurrency
+ thl_web_rw: PostgresManager, ledger_manager: LedgerManager, currency: LedgerCurrency
) -> Callable[..., None]:
def _inner() -> None:
@@ -397,7 +399,9 @@ def wipe_main_accounts(
@pytest.fixture
-def account_cash(lm: LedgerManager, currency: LedgerCurrency) -> LedgerAccount:
+def account_cash(
+ ledger_manager: LedgerManager, currency: LedgerCurrency
+) -> LedgerAccount:
from generalresearch.models.thl.ledger import (
AccountType,
Direction,
@@ -411,12 +415,12 @@ def account_cash(lm: LedgerManager, currency: LedgerCurrency) -> LedgerAccount:
account_type=AccountType.CASH,
currency=currency,
)
- return lm.get_account_or_create(account=account)
+ return ledger_manager.get_account_or_create(account=account)
@pytest.fixture
def account_revenue_task_complete(
- lm: LedgerManager, currency: LedgerCurrency
+ ledger_manager: LedgerManager, currency: LedgerCurrency
) -> LedgerAccount:
from generalresearch.models.thl.ledger import (
AccountType,
@@ -431,11 +435,13 @@ def account_revenue_task_complete(
account_type=AccountType.REVENUE,
currency=currency,
)
- return lm.get_account_or_create(account=account)
+ return ledger_manager.get_account_or_create(account=account)
@pytest.fixture
-def account_expense_tango(lm: LedgerManager, currency: LedgerCurrency) -> LedgerAccount:
+def account_expense_tango(
+ ledger_manager: LedgerManager, currency: LedgerCurrency
+) -> LedgerAccount:
from generalresearch.models.thl.ledger import (
AccountType,
Direction,
@@ -449,12 +455,12 @@ def account_expense_tango(lm: LedgerManager, currency: LedgerCurrency) -> Ledger
account_type=AccountType.EXPENSE,
currency=currency,
)
- return lm.get_account_or_create(account=account)
+ return ledger_manager.get_account_or_create(account=account)
@pytest.fixture
def user_account_user_wallet(
- lm: LedgerManager, user: User, currency: LedgerCurrency
+ ledger_manager: LedgerManager, user: User, currency: LedgerCurrency
) -> LedgerAccount:
from generalresearch.models.thl.ledger import (
AccountType,
@@ -471,12 +477,12 @@ def user_account_user_wallet(
reference_uuid=user.uuid,
currency=currency,
)
- return lm.get_account_or_create(account=account)
+ return ledger_manager.get_account_or_create(account=account)
@pytest.fixture
def product_account_bp_wallet(
- lm: LedgerManager, product: Product, currency: LedgerCurrency
+ ledger_manager: LedgerManager, product: Product, currency: LedgerCurrency
) -> LedgerAccount:
from generalresearch.models.thl.ledger import (
AccountType,
@@ -495,13 +501,13 @@ def product_account_bp_wallet(
"currency": currency,
}
)
- return lm.get_account_or_create(account=account)
+ return ledger_manager.get_account_or_create(account=account)
@pytest.fixture
def setup_accounts(
product_factory: Callable[..., Product],
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
user: User,
currency: LedgerCurrency,
) -> Callable[..., None]:
@@ -524,7 +530,7 @@ def setup_accounts(
reference_uuid=p1.uuid,
currency=currency,
)
- lm.get_account_or_create(account=account)
+ ledger_manager.get_account_or_create(account=account)
account = LedgerAccount.model_validate(
{
@@ -537,7 +543,7 @@ def setup_accounts(
"currency": currency,
}
)
- lm.get_account_or_create(account=account)
+ ledger_manager.get_account_or_create(account=account)
# BP's wallet, user's wallet, and a revenue from their commissions account.
p2 = product_factory()
@@ -550,7 +556,7 @@ def setup_accounts(
reference_uuid=p2.uuid,
currency=currency,
)
- lm.get_account_or_create(account)
+ ledger_manager.get_account_or_create(account)
account = LedgerAccount(
display_name=f"{p2.name} Wallet",
@@ -561,7 +567,7 @@ def setup_accounts(
reference_uuid=p2.uuid,
currency=currency,
)
- lm.get_account_or_create(account)
+ ledger_manager.get_account_or_create(account)
account = LedgerAccount(
display_name=f"{user.uuid} Wallet",
@@ -572,7 +578,7 @@ def setup_accounts(
reference_uuid=user.uuid,
currency="test",
)
- lm.get_account_or_create(account=account)
+ ledger_manager.get_account_or_create(account=account)
return _inner
@@ -583,7 +589,7 @@ def session_with_tx_factory(
session_manager: SessionManager,
wall_manager: WallManager,
utc_hour_ago: datetime,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
) -> Callable[..., Session]:
from generalresearch.models.thl.session import (
@@ -624,14 +630,16 @@ def session_with_tx_factory(
status_code_1=status_code_1,
)
- thl_lm.create_tx_task_complete(
+ thl_ledger_manager.create_tx_task_complete(
wall=last_wall,
user=user,
created=last_wall.finished,
force=True,
)
- thl_lm.create_tx_bp_payment(session=s, created=last_wall.finished, force=True)
+ thl_ledger_manager.create_tx_bp_payment(
+ session=s, created=last_wall.finished, force=True
+ )
return s
@@ -642,7 +650,7 @@ def session_with_tx_factory(
def adj_to_fail_with_tx_factory(
session_manager: SessionManager,
wall_manager: WallManager,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
) -> Callable[..., None]:
from datetime import timedelta
@@ -675,7 +683,7 @@ def adj_to_fail_with_tx_factory(
adjusted_timestamp=created,
)
- thl_lm.create_tx_task_adjustment(
+ thl_ledger_manager.create_tx_task_adjustment(
wall=w1,
user=session.user,
created=created + timedelta(milliseconds=1),
@@ -684,7 +692,7 @@ def adj_to_fail_with_tx_factory(
session.wall_events = wall_manager.get_wall_events(session_id=session.id)
session_manager.adjust_status(session=session)
- thl_lm.create_tx_bp_adjustment(
+ thl_ledger_manager.create_tx_bp_adjustment(
session=session, created=created + timedelta(milliseconds=2)
)
@@ -695,7 +703,7 @@ def adj_to_fail_with_tx_factory(
def adj_to_complete_with_tx_factory(
session_manager: SessionManager,
wall_manager: WallManager,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
) -> Callable[..., None]:
from datetime import timedelta
@@ -714,7 +722,7 @@ def adj_to_complete_with_tx_factory(
adjusted_timestamp=created,
)
- thl_lm.create_tx_task_adjustment(
+ thl_ledger_manager.create_tx_task_adjustment(
wall=w1,
user=session.user,
created=created + timedelta(milliseconds=1),
@@ -723,7 +731,7 @@ def adj_to_complete_with_tx_factory(
session.wall_events = wall_manager.get_wall_events(session_id=session.id)
session_manager.adjust_status(session=session)
- thl_lm.create_tx_bp_adjustment(
+ thl_ledger_manager.create_tx_bp_adjustment(
session=session, created=created + timedelta(milliseconds=2)
)
diff --git a/tests/incite/collections/test_df_collection_base.py b/tests/incite/collections/test_df_collection_base.py
index e20b44b..6d715fa 100644
--- a/tests/incite/collections/test_df_collection_base.py
+++ b/tests/incite/collections/test_df_collection_base.py
@@ -5,7 +5,7 @@ import pandas as pd
import pytest
from pandera.pandas import DataFrameSchema
-from generalresearch.incite.collections import (
+from generalresearch.incite.collections.base import (
DFCollection,
DFCollectionType,
)
@@ -53,7 +53,7 @@ class TestDFCollectionBaseProperties:
data_type=df_coll_type,
start=datetime(year=1800, month=1, day=1, tzinfo=UTC),
finished=datetime(year=1900, month=1, day=1, tzinfo=UTC),
- offset="100d",
+ offset="100D",
archive_path=mnt_filepath.archive_path(enum_type=df_coll_type),
)
@@ -67,7 +67,7 @@ class TestDFCollectionBaseProperties:
data_type=df_coll_type,
start=datetime(year=1800, month=1, day=1, tzinfo=UTC),
finished=datetime(year=1900, month=1, day=1, tzinfo=UTC),
- offset="100d",
+ offset="100D",
archive_path=mnt_filepath.archive_path(enum_type=df_coll_type),
)
diff --git a/tests/incite/collections/test_df_collection_item_base.py b/tests/incite/collections/test_df_collection_item_base.py
index fd70bf0..83d4973 100644
--- a/tests/incite/collections/test_df_collection_item_base.py
+++ b/tests/incite/collections/test_df_collection_item_base.py
@@ -25,7 +25,7 @@ class TestDFCollectionItemBase:
def test_init(self, mnt_filepath: GRLDatasets, df_coll_type: DFCollectionType):
collection = DFCollection(
data_type=df_coll_type,
- offset="100d",
+ offset="100D",
start=datetime(year=1800, month=1, day=1, tzinfo=UTC),
finished=datetime(year=1900, month=1, day=1, tzinfo=UTC),
archive_path=mnt_filepath.archive_path(enum_type=df_coll_type),
@@ -53,7 +53,7 @@ class TestDFCollectionItemMethods:
):
collection = DFCollection(
data_type=df_coll_type,
- offset="100d",
+ offset="100D",
start=datetime(year=1800, month=1, day=1, tzinfo=UTC),
finished=datetime(year=1900, month=1, day=1, tzinfo=UTC),
archive_path=mnt_filepath.archive_path(enum_type=df_coll_type),
@@ -70,7 +70,7 @@ class TestDFCollectionItemMethods:
):
collection = DFCollection(
data_type=df_coll_type,
- offset="100d",
+ offset="100D",
start=datetime(year=1800, month=1, day=1, tzinfo=UTC),
finished=datetime(year=1900, month=1, day=1, tzinfo=UTC),
archive_path=mnt_filepath.archive_path(enum_type=df_coll_type),
diff --git a/tests/incite/test_interval_idx.py b/tests/incite/test_interval_idx.py
index 03d29ea..04d0bb2 100644
--- a/tests/incite/test_interval_idx.py
+++ b/tests/incite/test_interval_idx.py
@@ -18,7 +18,7 @@ class TestIntervalIndex:
# If the offset is longer than the end - start it will not
# error. It will simply have 0 rows.
iv_r: pd.IntervalIndex = pd.interval_range(
- start=start, end=end, freq="30d", closed="left"
+ start=start, end=end, freq="30D", closed="left"
)
assert isinstance(iv_r, pd.IntervalIndex)
assert len(iv_r.to_list()) == 0
diff --git a/tests/managers/gr/test_business.py b/tests/managers/gr/test_business.py
index 1a5d4fa..35c471e 100644
--- a/tests/managers/gr/test_business.py
+++ b/tests/managers/gr/test_business.py
@@ -7,8 +7,8 @@ from generalresearch.models.gr.business import (
Business,
BusinessAddress,
BusinessBankAccount,
- TransferMethod,
)
+from generalresearch.models.gr.definitions import TransferMethod
if TYPE_CHECKING:
from generalresearch.managers.gr.business import (
@@ -32,12 +32,12 @@ class TestBusinessBankAccountManager:
def test_create(
self,
- business: Business,
+ gr_business: Business,
business_bank_account_manager: BusinessBankAccountManager,
):
instance = business_bank_account_manager.create(
- business_id=business.id,
+ business_id=gr_business.id,
uuid=uuid4().hex,
transfer_method=TransferMethod.ACH,
)
@@ -56,10 +56,12 @@ class TestBusinessBankAccountManager:
class TestBusinessAddressManager:
def test_create(
- self, business: Business, business_address_manager: BusinessAddressManager
+ self, gr_business: Business, business_address_manager: BusinessAddressManager
):
- res = business_address_manager.create(uuid=uuid4().hex, business_id=business.id)
+ res = business_address_manager.create(
+ uuid=uuid4().hex, business_id=gr_business.id
+ )
assert isinstance(res, BusinessAddress)
assert isinstance(res.id, int)
@@ -140,18 +142,20 @@ class TestBusinessManager:
def test_get_uuids_by_user_id(self):
pass
- def test_get_by_uuid(self, business: Business, business_manager: BusinessManager):
- instance = business_manager.get_by_uuid(business_uuid=business.uuid)
+ def test_get_by_uuid(
+ self, gr_business: Business, business_manager: BusinessManager
+ ):
+ instance = business_manager.get_by_uuid(business_uuid=gr_business.uuid)
assert isinstance(instance, Business)
- assert business.id == instance.id
+ assert gr_business.id == instance.id
- def test_get_by_id(self, business: Business, business_manager: BusinessManager):
- instance = business_manager.get_by_id(business_id=business.id)
+ def test_get_by_id(self, gr_business: Business, business_manager: BusinessManager):
+ instance = business_manager.get_by_id(business_id=gr_business.id)
assert isinstance(instance, Business)
- assert business.uuid == instance.uuid
+ assert gr_business.uuid == instance.uuid
- def test_cache_key(self, business: Business):
- assert "business:" in business.cache_key
+ def test_cache_key(self, gr_business: Business):
+ assert "business:" in gr_business.cache_key
# def test_create_raise_on_duplicate(self):
# b_uuid = uuid4().hex
@@ -160,7 +164,7 @@ class TestBusinessManager:
# business = BusinessManager.create(
# uuid=b_uuid,
# name=f"test-{b_uuid[:6]}")
- # assert isinstance(business: Business, Business)
+ # assert isinstance(gr_business: Business, Business)
#
# # Try to make it again
# with pytest.raises(expected_exception=psycopg.errors.UniqueViolation):
diff --git a/tests/managers/thl/test_ledger/test_lm_accounts.py b/tests/managers/thl/test_ledger/test_lm_accounts.py
index f5ed883..cdef99a 100644
--- a/tests/managers/thl/test_ledger/test_lm_accounts.py
+++ b/tests/managers/thl/test_ledger/test_lm_accounts.py
@@ -44,7 +44,7 @@ class TestLedgerAccountManagerNoResults:
currency: LedgerCurrency,
kind: str,
acct_id: UUIDStr,
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
):
"""Try to query for accounts that we know don't exist and confirm that
we either get the expected None result or it raises the correct
@@ -54,40 +54,50 @@ class TestLedgerAccountManagerNoResults:
# (1) .get_account is just a wrapper for .get_account_many_ but
# call it either way
- assert lm.get_account(qualified_name=qn, raise_on_error=False) is None
+ assert (
+ ledger_manager.get_account(qualified_name=qn, raise_on_error=False) is None
+ )
with pytest.raises(expected_exception=LedgerAccountDoesntExistError):
- lm.get_account(qualified_name=qn, raise_on_error=True)
+ ledger_manager.get_account(qualified_name=qn, raise_on_error=True)
# (2) .get_account_if_exists is another wrapper
- assert lm.get_account(qualified_name=qn, raise_on_error=False) is None
+ assert (
+ ledger_manager.get_account(qualified_name=qn, raise_on_error=False) is None
+ )
def test_get_account_no_results_many(
self,
currency: LedgerCurrency,
kind: str,
acct_id: UUIDStr,
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
):
qn = f"{currency}:{kind}:{acct_id}"
# (1) .get_many_
- assert lm.get_account_many_(qualified_names=[qn], raise_on_error=False) == []
+ assert (
+ ledger_manager.get_account_many_(qualified_names=[qn], raise_on_error=False)
+ == []
+ )
with pytest.raises(expected_exception=LedgerAccountDoesntExistError):
- lm.get_account_many_(qualified_names=[qn], raise_on_error=True)
+ ledger_manager.get_account_many_(qualified_names=[qn], raise_on_error=True)
# (2) .get_many
- assert lm.get_account_many(qualified_names=[qn], raise_on_error=False) == []
+ assert (
+ ledger_manager.get_account_many(qualified_names=[qn], raise_on_error=False)
+ == []
+ )
with pytest.raises(expected_exception=LedgerAccountDoesntExistError):
- lm.get_account_many(qualified_names=[qn], raise_on_error=True)
+ ledger_manager.get_account_many(qualified_names=[qn], raise_on_error=True)
# (3) .get_accounts(..)
- assert lm.get_accounts_if_exists(qualified_names=[qn]) == []
+ assert ledger_manager.get_accounts_if_exists(qualified_names=[qn]) == []
with pytest.raises(expected_exception=LedgerAccountDoesntExistError):
- lm.get_accounts(qualified_names=[qn])
+ ledger_manager.get_accounts(qualified_names=[qn])
@pytest.mark.parametrize(
@@ -107,7 +117,7 @@ class TestLedgerAccountManagerCreate:
currency: LedgerCurrency,
account_type: AccountType,
direction: Direction,
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -124,11 +134,11 @@ class TestLedgerAccountManagerCreate:
# (1) With no Permissions defined
test_lm = LedgerManager(
- pg_config=lm.pg_config,
+ pg_config=ledger_manager.pg_config,
permissions=[],
- redis_config=lm.redis_config,
- cache_prefix=lm.cache_prefix,
- testing=lm.testing,
+ redis_config=ledger_manager.redis_config,
+ cache_prefix=ledger_manager.cache_prefix,
+ testing=ledger_manager.testing,
)
with pytest.raises(expected_exception=AssertionError) as excinfo:
@@ -139,11 +149,11 @@ class TestLedgerAccountManagerCreate:
# (2) With Permissions defined, but not CREATE
test_lm = LedgerManager(
- pg_config=lm.pg_config,
+ pg_config=ledger_manager.pg_config,
permissions=[Permission.READ, Permission.UPDATE, Permission.DELETE],
- redis_config=lm.redis_config,
- cache_prefix=lm.cache_prefix,
- testing=lm.testing,
+ redis_config=ledger_manager.redis_config,
+ cache_prefix=ledger_manager.cache_prefix,
+ testing=ledger_manager.testing,
)
with pytest.raises(expected_exception=AssertionError) as excinfo:
@@ -157,7 +167,7 @@ class TestLedgerAccountManagerCreate:
currency: LedgerCurrency,
account_type: AccountType,
direction: Direction,
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -174,11 +184,11 @@ class TestLedgerAccountManagerCreate:
account_type=account_type,
normal_balance=direction,
)
- account = lm.create_account(account=acct_model)
+ account = ledger_manager.create_account(account=acct_model)
assert isinstance(account, LedgerAccount)
# Query for, and make sure the Account was saved in the DB
- res = lm.get_account(qualified_name=qn, raise_on_error=True)
+ res = ledger_manager.get_account(qualified_name=qn, raise_on_error=True)
assert res is not None
assert account.uuid == res.uuid
@@ -187,7 +197,7 @@ class TestLedgerAccountManagerCreate:
currency: LedgerCurrency,
account_type: AccountType,
direction: Direction,
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
):
"""Confirm that the Permission values that are set on the Ledger Manger
allow the Creation action to occur.
@@ -204,27 +214,31 @@ class TestLedgerAccountManagerCreate:
account_type=account_type,
normal_balance=direction,
)
- account = lm.get_account_or_create(account=acct_model)
+ account = ledger_manager.get_account_or_create(account=acct_model)
assert isinstance(account, LedgerAccount)
# Query for, and make sure the Account was saved in the DB
- res = lm.get_account(qualified_name=qn, raise_on_error=True)
+ res = ledger_manager.get_account(qualified_name=qn, raise_on_error=True)
assert res is not None
assert account.uuid == res.uuid
class TestLedgerAccountManagerGet:
- def test_get(self, ledger_account: LedgerAccount, lm: LedgerManager):
- res = lm.get_account(qualified_name=ledger_account.qualified_name)
+ def test_get(self, ledger_account: LedgerAccount, ledger_manager: LedgerManager):
+ res = ledger_manager.get_account(qualified_name=ledger_account.qualified_name)
assert res is not None
assert res.uuid == ledger_account.uuid
- res = lm.get_account_many(qualified_names=[ledger_account.qualified_name])
+ res = ledger_manager.get_account_many(
+ qualified_names=[ledger_account.qualified_name]
+ )
assert len(res) == 1
assert res[0].uuid == ledger_account.uuid
- res = lm.get_accounts(qualified_names=[ledger_account.qualified_name])
+ res = ledger_manager.get_accounts(
+ qualified_names=[ledger_account.qualified_name]
+ )
assert len(res) == 1
assert res[0].uuid == ledger_account.uuid
@@ -237,15 +251,15 @@ class TestLedgerAccountManagerGet:
ledger_account_credit: LedgerAccount,
ledger_account_debit: LedgerAccount,
ledger_tx: LedgerTransaction,
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
):
- res = lm.get_account_balance(account=ledger_account)
+ res = ledger_manager.get_account_balance(account=ledger_account)
assert res == 0
- res = lm.get_account_balance(account=ledger_account_credit)
+ res = ledger_manager.get_account_balance(account=ledger_account_credit)
assert res == 100
- res = lm.get_account_balance(account=ledger_account_debit)
+ res = ledger_manager.get_account_balance(account=ledger_account_debit)
assert res == 100
@pytest.mark.parametrize("n_times", range(5))
@@ -256,7 +270,7 @@ class TestLedgerAccountManagerGet:
ledger_account_debit: LedgerAccount,
ledger_tx: LedgerTransaction,
n_times: PositiveInt,
- lm: LedgerManager,
+ ledger_manager: LedgerManager,
):
"""Try searching for random metadata and confirm it's always 0 because
Tx can be found.
@@ -265,7 +279,7 @@ class TestLedgerAccountManagerGet:
rand_value = uuid4().hex
assert (
- lm.get_account_filtered_balance(
+ ledger_manager.get_account_filtered_balance(
account=ledger_account, metadata_key=rand_key, metadata_value=rand_value
)
== 0
@@ -275,7 +289,7 @@ class TestLedgerAccountManagerGet:
# and that we can filter it back
rand_amount = randint(10, 1_000)
- lm.create_tx(
+ ledger_manager.create_tx(
entries=[
LedgerEntry(
direction=Direction.CREDIT,
@@ -292,7 +306,7 @@ class TestLedgerAccountManagerGet:
)
assert (
- lm.get_account_filtered_balance(
+ ledger_manager.get_account_filtered_balance(
account=ledger_account_credit,
metadata_key=rand_key,
metadata_value=rand_value,
@@ -301,7 +315,7 @@ class TestLedgerAccountManagerGet:
)
assert (
- lm.get_account_filtered_balance(
+ ledger_manager.get_account_filtered_balance(
account=ledger_account_debit,
metadata_key=rand_key,
metadata_value=rand_value,
@@ -310,7 +324,7 @@ class TestLedgerAccountManagerGet:
)
def test_get_balance_timerange_empty(
- self, ledger_account: LedgerAccount, lm: LedgerManager
+ self, ledger_account: LedgerAccount, ledger_manager: LedgerManager
):
- res = lm.get_account_balance_timerange(account=ledger_account)
+ res = ledger_manager.get_account_balance_timerange(account=ledger_account)
assert res == 0
diff --git a/tests/managers/thl/test_ledger/test_thl_lm_tx.py b/tests/managers/thl/test_ledger/test_thl_lm_tx.py
index 2e4ab5e..b0484ae 100644
--- a/tests/managers/thl/test_ledger/test_thl_lm_tx.py
+++ b/tests/managers/thl/test_ledger/test_thl_lm_tx.py
@@ -311,15 +311,14 @@ class TestThlLedgerTxManager:
def test_create_tx_bp_payout_(
self,
product: Product,
- thl_lm: ThlLedgerManager,
- ledger_manager: LedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
currency: LedgerCurrency,
):
rand_amount: USDCent = USDCent(randint(100, 1_000))
payoutevent_uuid = uuid4().hex
# Create a BP Payout for a Product without any activity.
- tx = thl_lm.create_tx_bp_payout_(
+ tx = thl_ledger_manager.create_tx_bp_payout_(
product=product,
amount=rand_amount,
payoutevent_uuid=payoutevent_uuid,
diff --git a/tests/managers/thl/test_payout.py b/tests/managers/thl/test_payout.py
index 2494de8..ad101a4 100644
--- a/tests/managers/thl/test_payout.py
+++ b/tests/managers/thl/test_payout.py
@@ -86,7 +86,6 @@ class TestPayout:
self,
user: User,
user_payout_event_manager: UserPayoutEventManager,
- ledger_manager: LedgerManager,
thl_ledger_manager: ThlLedgerManager,
utc_now: datetime,
):
@@ -128,11 +127,11 @@ class TestPayout:
self,
thl_web_rw: PostgresConfig,
product: Product,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
utc_now: datetime,
) -> BrokerageProductPayoutEvent:
- account = thl_lm.get_account_or_create_bp_wallet(product=product)
+ account = thl_ledger_manager.get_account_or_create_bp_wallet(product=product)
bp_pe = BrokerageProductPayoutEvent(
product_id=product.uuid,
amount=USDCent(100),
@@ -161,15 +160,14 @@ class TestPayout:
self,
product: Product,
brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
- thl_lm: ThlLedgerManager,
- ledger_manager: LedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
utc_now: datetime,
pending_bp_pe: BrokerageProductPayoutEvent,
):
- thl_lm.get_account_or_create_bp_wallet(product=product)
+ thl_ledger_manager.get_account_or_create_bp_wallet(product=product)
brokerage_product_payout_event_manager.create_tx_bp_payout_from_payout_event(
- thl_ledger_manager=thl_lm,
+ thl_ledger_manager=thl_ledger_manager,
bp_pe=pending_bp_pe,
product=product,
created=utc_now,
@@ -177,7 +175,7 @@ class TestPayout:
with pytest.raises(ValueError) as cm:
brokerage_product_payout_event_manager.create_tx_bp_payout_from_payout_event(
- thl_ledger_manager=thl_lm,
+ thl_ledger_manager=thl_ledger_manager,
product=product,
bp_pe=pending_bp_pe,
created=utc_now,
@@ -187,7 +185,6 @@ class TestPayout:
def test_filter(
self,
thl_ledger_manager: ThlLedgerManager,
- ledger_manager: LedgerManager,
product: Product,
user: User,
user_payout_event_manager: UserPayoutEventManager,
@@ -280,19 +277,18 @@ class TestBusinessPayoutEventManager:
def test_base(
self,
- brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
business_payout_event_manager: BusinessPayoutEventManager,
delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
thl_ledger_manager: ThlLedgerManager,
product_factory: Callable[..., Product],
bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
- business: Business,
+ gr_business: Business,
):
delete_ledger_db()
create_main_accounts()
- p1: Product = product_factory(business=business)
+ p1: Product = product_factory(business=gr_business)
thl_ledger_manager.get_account_or_create_bp_wallet(product=p1)
ach_id1 = uuid4().hex
@@ -310,23 +306,25 @@ class TestBusinessPayoutEventManager:
bp_payout_factory(product=p1, amount=USDCent(50), ext_ref_id=ach_id2)
- business.prebuild_payouts(
+ gr_business.prebuild_payouts(
bpem=business_payout_event_manager,
)
- assert isinstance(business.payouts, list)
- assert len(business.payouts) == 3
- assert business.payouts_total == sum([pe.amount for pe in business.payouts])
- assert business.payouts[0].created > business.payouts[1].created
- assert len(business.payouts[0].bp_payouts) == 1
+ assert isinstance(gr_business.payouts, list)
+ assert len(gr_business.payouts) == 3
+ assert gr_business.payouts_total == sum(
+ [pe.amount for pe in gr_business.payouts]
+ )
+ assert gr_business.payouts[0].created > gr_business.payouts[1].created
+ assert len(gr_business.payouts[0].bp_payouts) == 1
# Cannot pay out the same product twice in the same business payout
# assert len(business.payouts[1].bp_payouts) == 2
- assert len(business.payouts[1].bp_payouts) == 1
+ assert len(gr_business.payouts[1].bp_payouts) == 1
- assert business.payouts[0].ext_ref_id == ach_id2
- assert business.payouts[1].ext_ref_id == ach_id1
- assert business.payouts[2].ext_ref_id == "none"
+ assert gr_business.payouts[0].ext_ref_id == ach_id2
+ assert gr_business.payouts[1].ext_ref_id == ach_id1
+ assert gr_business.payouts[2].ext_ref_id == "none"
def test_update_ext_reference_ids(
self,
@@ -345,13 +343,13 @@ class TestBusinessPayoutEventManager:
mnt_filepath: GRLDatasets,
product_manager: ProductManager,
start: datetime,
- business: Business,
+ gr_business: Business,
):
delete_ledger_db()
create_main_accounts()
delete_df_collection(coll=ledger_collection)
- p1: Product = product_factory(business=business)
+ p1: Product = product_factory(business=gr_business)
u1: User = user_factory(product=p1)
thl_ledger_manager.get_account_or_create_bp_wallet(product=p1)
@@ -377,7 +375,7 @@ class TestBusinessPayoutEventManager:
# We must build the balance to issue ACH/Wire
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=thl_ledger_manager,
ds=mnt_filepath,
@@ -386,7 +384,7 @@ class TestBusinessPayoutEventManager:
)
res = business_payout_event_manager.create_from_ach_or_wire(
- business=business,
+ business=gr_business,
amount=USDCent(100_01),
pm=product_manager,
thl_lm=thl_ledger_manager,
@@ -558,7 +556,7 @@ class TestBusinessPayoutEventManager:
create_main_accounts: Callable[..., None],
delete_df_collection: Callable[..., None],
ledger_collection: LedgerDFCollection,
- business: Business,
+ gr_business: Business,
user_factory: Callable[..., User],
product_factory: Callable[..., Product],
session_with_tx_factory: Callable[..., Session],
@@ -581,7 +579,7 @@ class TestBusinessPayoutEventManager:
create_main_accounts()
delete_df_collection(coll=ledger_collection)
- p1: Product = product_factory(business=business)
+ p1: Product = product_factory(business=gr_business)
u1: User = user_factory(product=p1)
thl_ledger_manager.get_account_or_create_bp_wallet(product=p1)
@@ -603,7 +601,7 @@ class TestBusinessPayoutEventManager:
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=ledger_manager,
ds=mnt_filepath,
@@ -613,7 +611,7 @@ class TestBusinessPayoutEventManager:
with pytest.raises(expected_exception=AssertionError) as cm:
business_payout_event_manager.create_from_ach_or_wire(
- business=business,
+ business=gr_business,
amount=USDCent(500),
pm=product_manager,
thl_lm=thl_ledger_manager,
@@ -631,7 +629,7 @@ class TestBusinessPayoutEventManager:
create_main_accounts: Callable[..., None],
delete_df_collection: Callable[..., None],
ledger_collection: LedgerDFCollection,
- business: Business,
+ gr_business: Business,
user_factory: Callable[..., User],
product_factory: Callable[..., Product],
session_with_tx_factory: Callable[..., None],
@@ -648,9 +646,9 @@ class TestBusinessPayoutEventManager:
create_main_accounts()
delete_df_collection(coll=ledger_collection)
- p1: Product = product_factory(business=business)
- p2: Product = product_factory(business=business)
- p3: Product = product_factory(business=business)
+ p1: Product = product_factory(business=gr_business)
+ p2: Product = product_factory(business=gr_business)
+ p3: Product = product_factory(business=gr_business)
_: User = user_factory(product=p1)
u2: User = user_factory(product=p2)
u3: User = user_factory(product=p3)
@@ -679,7 +677,7 @@ class TestBusinessPayoutEventManager:
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=ledger_manager,
ds=mnt_filepath,
@@ -687,13 +685,13 @@ class TestBusinessPayoutEventManager:
pop_ledger=pop_ledger_merge,
)
- bb = business.balance
+ bb = gr_business.balance
assert isinstance(bb, BusinessBalances)
assert bb.payout == 475_00 # $500 * .95% = $475
assert bb.net == 475_00
bp1 = business_payout_event_manager.create_from_ach_or_wire(
- business=business,
+ business=gr_business,
amount=USDCent(100_00),
pm=product_manager,
thl_lm=thl_ledger_manager,
@@ -705,7 +703,7 @@ class TestBusinessPayoutEventManager:
assert len(bp1.bp_payouts) == 2
bp2 = business_payout_event_manager.create_from_ach_or_wire(
- business=business,
+ business=gr_business,
amount=USDCent(bb.available_balance),
pm=product_manager,
thl_lm=thl_ledger_manager,
@@ -743,7 +741,7 @@ class TestBusinessPayoutEventManager:
create_main_accounts: Callable[..., None],
delete_df_collection: Callable[..., None],
ledger_collection: LedgerDFCollection,
- business: Business,
+ gr_business: Business,
user_factory: Callable[..., User],
product_factory: Callable[..., Product],
session_with_tx_factory: Callable[..., None],
@@ -768,9 +766,9 @@ class TestBusinessPayoutEventManager:
create_main_accounts()
delete_df_collection(coll=ledger_collection)
- p1: Product = product_factory(business=business)
- p2: Product = product_factory(business=business)
- p3: Product = product_factory(business=business)
+ p1: Product = product_factory(business=gr_business)
+ p2: Product = product_factory(business=gr_business)
+ p3: Product = product_factory(business=gr_business)
u1: User = user_factory(product=p1)
u2: User = user_factory(product=p2)
u3: User = user_factory(product=p3)
@@ -813,10 +811,10 @@ class TestBusinessPayoutEventManager:
started=start + timedelta(days=1, hours=3, minutes=1 + idx),
)
- # Now that we paid out the business: Business, let's confirm the updated balances
+ # Now that we paid out the gr_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)
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=ledger_manager,
ds=mnt_filepath,
@@ -824,7 +822,7 @@ class TestBusinessPayoutEventManager:
pop_ledger=pop_ledger_merge,
)
- bb1 = business.balance
+ bb1 = gr_business.balance
assert isinstance(bb1, BusinessBalances)
pb1 = bb1.product_balances[0]
pb2 = bb1.product_balances[1]
@@ -848,18 +846,18 @@ class TestBusinessPayoutEventManager:
assert pb2.recoup_usd_str == "$0.00"
assert pb3.recoup_usd_str == "$0.00"
- assert business.payouts is None
- business.prebuild_payouts(
+ 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(business.payouts, list)
- assert len(business.payouts) == 1
- assert business.payouts[0].ext_ref_id == ach_id1
+ assert isinstance(gr_business.payouts, list)
+ assert len(gr_business.payouts) == 1
+ assert gr_business.payouts[0].ext_ref_id == ach_id1
bp1 = business_payout_event_manager.create_from_ach_or_wire(
- business=business,
+ business=gr_business,
amount=USDCent(bb1.available_balance),
pm=product_manager,
thl_lm=thl_ledger_manager,
@@ -937,7 +935,7 @@ class TestBusinessPayoutEventManager:
create_main_accounts: Callable[..., None],
delete_df_collection: Callable[..., None],
ledger_collection: LedgerDFCollection,
- business: Business,
+ gr_business: Business,
user_factory: Callable[..., User],
product_factory: Callable[..., Product],
session_with_tx_factory: Callable[..., None],
@@ -950,7 +948,7 @@ class TestBusinessPayoutEventManager:
rm_pop_ledger_merge: Callable[..., None],
):
"""There are valid instances when we want issue a ACH or Wire to a
- business: Business, but not for the full Available Balance amount in their
+ gr_business: Business, but not for the full Available Balance amount in their
account.
To test this, we'll create a Business with multiple Products, and
@@ -965,9 +963,9 @@ class TestBusinessPayoutEventManager:
create_main_accounts()
delete_df_collection(coll=ledger_collection)
- p1: Product = product_factory(business=business)
- p2: Product = product_factory(business=business)
- p3: Product = product_factory(business=business)
+ p1: Product = product_factory(business=gr_business)
+ p2: Product = product_factory(business=gr_business)
+ p3: Product = product_factory(business=gr_business)
u1: User = user_factory(product=p1)
u2: User = user_factory(product=p2)
u3: User = user_factory(product=p3)
@@ -988,20 +986,20 @@ class TestBusinessPayoutEventManager:
# 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)
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
pop_ledger=pop_ledger_merge,
)
- business.prebuild_payouts(
+ gr_business.prebuild_payouts(
bpem=business_payout_event_manager,
)
# Confirm the initial amounts.
- assert len(business.payouts) == 0
- bb1 = business.balance
+ assert len(gr_business.payouts) == 0
+ bb1 = gr_business.balance
assert isinstance(bb1, BusinessBalances)
assert bb1.payout == 3 * 5 * 4750
@@ -1015,16 +1013,16 @@ class TestBusinessPayoutEventManager:
assert bb1.product_balances[x].balance == 5 * 4750
assert bb1.product_balances[x].available_balance_usd_str == "$178.13"
- assert business.payouts_total_str == "$0.00"
- assert isinstance(business.balance, BusinessBalances)
- assert business.balance.payment_usd_str == "$0.00"
- assert business.balance.available_balance_usd_str == "$534.39"
+ assert gr_business.payouts_total_str == "$0.00"
+ assert isinstance(gr_business.balance, BusinessBalances)
+ assert gr_business.balance.payment_usd_str == "$0.00"
+ assert gr_business.balance.available_balance_usd_str == "$534.39"
# This is the important part, even those the Business has $534.39
# available to it, we are only trying to issue out a $250.00 ACH or
# Wire to the Business
bp1 = business_payout_event_manager.create_from_ach_or_wire(
- business=business,
+ business=gr_business,
amount=USDCent(250_00),
pm=product_manager,
thl_lm=thl_ledger_manager,
@@ -1033,7 +1031,7 @@ class TestBusinessPayoutEventManager:
assert isinstance(bp1, BusinessPayoutEvent)
assert len(bp1.bp_payouts) == 3
- # Now that we paid out the business: Business, let's confirm the updated
+ # Now that we paid out the gr_business: Business, let's confirm the updated
# balances. Clear and rebuild the parquet files.
rm_ledger_collection()
rm_pop_ledger_merge()
@@ -1043,25 +1041,23 @@ class TestBusinessPayoutEventManager:
# Now rebuild and confirm the payouts, balance.payment, and the
# balance.available_balance are reflective of having a $250 ACH/Wire
# sent to the Business
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
pop_ledger=pop_ledger_merge,
)
- business.prebuild_payouts(
- thl_pg_config=thl_web_rr,
- thl_lm=thl_ledger_manager,
+ gr_business.prebuild_payouts(
bpem=business_payout_event_manager,
)
- assert isinstance(business.payouts, list)
- assert len(business.payouts) == 1
- assert len(business.payouts[0].bp_payouts) == 3
- assert business.payouts_total_str == "$250.00"
- assert isinstance(business.balance, BusinessBalances)
- assert business.balance.payment_usd_str == "$250.00"
- assert business.balance.available_balance_usd_str == "$346.88"
+ assert isinstance(gr_business.payouts, list)
+ assert len(gr_business.payouts) == 1
+ assert len(gr_business.payouts[0].bp_payouts) == 3
+ assert gr_business.payouts_total_str == "$250.00"
+ assert isinstance(gr_business.balance, BusinessBalances)
+ assert gr_business.balance.payment_usd_str == "$250.00"
+ assert gr_business.balance.available_balance_usd_str == "$346.88"
def test_ach_tx_id_reference(
self,
@@ -1074,7 +1070,7 @@ class TestBusinessPayoutEventManager:
create_main_accounts: Callable[..., None],
delete_df_collection: Callable[..., None],
ledger_collection: LedgerDFCollection,
- business: Business,
+ gr_business: Business,
user_factory: Callable[..., User],
product_factory: Callable[..., Product],
session_with_tx_factory: Callable[..., Session],
@@ -1092,9 +1088,9 @@ class TestBusinessPayoutEventManager:
create_main_accounts()
delete_df_collection(coll=ledger_collection)
- p1: Product = product_factory(business=business)
- p2: Product = product_factory(business=business)
- p3: Product = product_factory(business=business)
+ p1: Product = product_factory(business=gr_business)
+ p2: Product = product_factory(business=gr_business)
+ p3: Product = product_factory(business=gr_business)
u1: User = user_factory(product=p1)
u2: User = user_factory(product=p2)
u3: User = user_factory(product=p3)
@@ -1118,7 +1114,7 @@ class TestBusinessPayoutEventManager:
rm_pop_ledger_merge()
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=ledger_manager,
ds=mnt_filepath,
@@ -1127,7 +1123,7 @@ class TestBusinessPayoutEventManager:
)
bp1 = business_payout_event_manager.create_from_ach_or_wire(
- business=business,
+ business=gr_business,
amount=USDCent(100_01),
transaction_id=ach_id1,
pm=product_manager,
@@ -1139,7 +1135,7 @@ class TestBusinessPayoutEventManager:
rm_pop_ledger_merge()
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=ledger_manager,
ds=mnt_filepath,
@@ -1148,7 +1144,7 @@ class TestBusinessPayoutEventManager:
)
bp2 = business_payout_event_manager.create_from_ach_or_wire(
- business=business,
+ business=gr_business,
amount=USDCent(100_02),
transaction_id=ach_id2,
pm=product_manager,
@@ -1163,18 +1159,18 @@ class TestBusinessPayoutEventManager:
rm_pop_ledger_merge()
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
- business.prebuild_payouts(
+ gr_business.prebuild_payouts(
thl_pg_config=thl_web_rr,
thl_lm=thl_ledger_manager,
bpem=business_payout_event_manager,
)
- business.prebuild_balance(
+ gr_business.prebuild_balance(
thl_pg_config=thl_web_rr,
lm=ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
pop_ledger=pop_ledger_merge,
)
- assert isinstance(business.payouts, list)
- assert business.payouts[0].ext_ref_id == ach_id2
- assert business.payouts[1].ext_ref_id == ach_id1
+ assert isinstance(gr_business.payouts, list)
+ assert gr_business.payouts[0].ext_ref_id == ach_id2
+ assert gr_business.payouts[1].ext_ref_id == ach_id1
diff --git a/tests/managers/thl/test_session_manager.py b/tests/managers/thl/test_session_manager.py
index 30fd9ec..67a802e 100644
--- a/tests/managers/thl/test_session_manager.py
+++ b/tests/managers/thl/test_session_manager.py
@@ -137,19 +137,19 @@ class TestSessionManagerFilter:
def test_business(
self,
product_factory: Callable[..., Product],
- business: Business,
+ gr_business: Business,
user_factory: Callable[..., User],
session_manager: SessionManager,
utc_hour_ago: datetime,
thl_web_rr: PostgresConfig,
):
- p1 = product_factory(business=business)
+ p1 = product_factory(business=gr_business)
for _ in range(5):
u = user_factory(product=p1)
session_manager.create(started=utc_hour_ago, user=u, uuid_id=uuid4().hex)
- business.prefetch_products(thl_pg_config=thl_web_rr)
- assert len(business.product_uuids) == 1
- res = session_manager.filter(product_uuids=business.product_uuids)
+ gr_business.prefetch_products(thl_pg_config=thl_web_rr)
+ 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/models/gr/test_authentication.py b/tests/models/gr/test_authentication.py
index ac1298f..059a0a4 100644
--- a/tests/models/gr/test_authentication.py
+++ b/tests/models/gr/test_authentication.py
@@ -116,7 +116,7 @@ class TestGRUser:
class TestGRUserMethods:
- def test_cache_key(self, gr_user: GRUser, gr_redis: RedisConfig):
+ def test_cache_key(self, gr_user: GRUser):
assert isinstance(gr_user.cache_key, str)
assert ":" in gr_user.cache_key
assert str(gr_user.id) in gr_user.cache_key
@@ -124,13 +124,12 @@ class TestGRUserMethods:
def test_to_redis(
self,
gr_user: GRUser,
- gr_redis: Redis,
team: Team,
- business: Business,
+ gr_business: Business,
product_factory: Callable[..., Product],
membership_factory: Callable[..., Membership],
):
- product_factory(team=team, business=business)
+ product_factory(team=team, business=gr_business)
membership_factory(team=team, gr_user=gr_user)
res = gr_user.to_redis()
@@ -144,31 +143,30 @@ class TestGRUserMethods:
def test_set_cache(
self,
gr_user: GRUser,
- gr_user_token: GRToken,
- gr_redis: Redis,
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
gr_redis_config: RedisConfig,
):
- assert gr_redis.get(name=gr_user.cache_key) is None
- assert gr_redis.get(name=f"{gr_user.cache_key}:team_uuids") is None
- assert gr_redis.get(name=f"{gr_user.cache_key}:business_uuids") is None
- assert gr_redis.get(name=f"{gr_user.cache_key}:product_uuids") is None
+
+ client = gr_redis_config.create_redis_client()
+
+ assert client.get(name=gr_user.cache_key) is None
+ assert client.get(name=f"{gr_user.cache_key}:team_uuids") is None
+ assert client.get(name=f"{gr_user.cache_key}:business_uuids") is None
+ assert client.get(name=f"{gr_user.cache_key}:product_uuids") is None
gr_user.set_cache(
pg_config=gr_db, thl_web_rr=thl_web_rr, redis_config=gr_redis_config
)
- assert gr_redis.get(name=gr_user.cache_key) is not None
- assert gr_redis.get(name=f"{gr_user.cache_key}:team_uuids") is not None
- assert gr_redis.get(name=f"{gr_user.cache_key}:business_uuids") is not None
- assert gr_redis.get(name=f"{gr_user.cache_key}:product_uuids") is not None
+ assert client.get(name=gr_user.cache_key) is not None
+ assert client.get(name=f"{gr_user.cache_key}:team_uuids") is not None
+ assert client.get(name=f"{gr_user.cache_key}:business_uuids") is not None
+ assert client.get(name=f"{gr_user.cache_key}:product_uuids") is not None
def test_set_cache_gr_user(
self,
gr_user: GRUser,
- gr_user_token: GRToken,
- gr_redis: RedisConfig,
gr_redis_config: RedisConfig,
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
@@ -179,6 +177,8 @@ class TestGRUserMethods:
):
from generalresearch.models.gr.authentication import GRUser
+ client = gr_redis_config.create_redis_client()
+
p1 = product_factory(team=team)
membership_factory(team=team, gr_user=gr_user)
@@ -186,7 +186,7 @@ class TestGRUserMethods:
pg_config=gr_db, thl_web_rr=thl_web_rr, redis_config=gr_redis_config
)
- res: str = gr_redis.get(name=gr_user.cache_key)
+ res: str = client.get(name=gr_user.cache_key)
gru2 = GRUser.from_redis(res)
assert gr_user.model_dump_json(
@@ -203,9 +203,6 @@ class TestGRUserMethods:
def test_set_cache_team_uuids(
self,
gr_user: GRUser,
- membership: Membership,
- gr_user_token: GRToken,
- gr_redis: Redis,
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
product_factory: Callable[..., Product],
@@ -213,11 +210,12 @@ class TestGRUserMethods:
gr_redis_config: RedisConfig,
):
product_factory(team=team)
+ client = gr_redis_config.create_redis_client()
gr_user.set_cache(
pg_config=gr_db, thl_web_rr=thl_web_rr, redis_config=gr_redis_config
)
- res = json.loads(gr_redis.get(name=f"{gr_user.cache_key}:team_uuids"))
+ res = json.loads(client.get(name=f"{gr_user.cache_key}:team_uuids"))
assert len(res) == 1
assert gr_user.team_uuids == res
@@ -225,29 +223,27 @@ class TestGRUserMethods:
def test_set_cache_business_uuids(
self,
gr_user: GRUser,
- gr_redis: Redis,
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
product_factory: Callable[..., Product],
- business: Business,
+ gr_business: Business,
team: Team,
gr_redis_config: RedisConfig,
):
- product_factory(team=team, business=business)
+ product_factory(team=team, business=gr_business)
gr_user.set_cache(
pg_config=gr_db, thl_web_rr=thl_web_rr, redis_config=gr_redis_config
)
- res = json.loads(gr_redis.get(name=f"{gr_user.cache_key}:business_uuids"))
+
+ client = gr_redis_config.create_redis_client()
+ res = json.loads(client.get(name=f"{gr_user.cache_key}:business_uuids"))
assert len(res) == 1
assert gr_user.business_uuids == res
def test_set_cache_product_uuids(
self,
gr_user: GRUser,
- membership: Membership,
- gr_user_token: GRToken,
- gr_redis: Redis,
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
product_factory: Callable[..., Product],
@@ -259,7 +255,8 @@ class TestGRUserMethods:
gr_user.set_cache(
pg_config=gr_db, thl_web_rr=thl_web_rr, redis_config=gr_redis_config
)
- res = json.loads(gr_redis.get(name=f"{gr_user.cache_key}:product_uuids"))
+ client = gr_redis_config.create_redis_client()
+ res = json.loads(client.get(name=f"{gr_user.cache_key}:product_uuids"))
assert len(res) == 1
assert gr_user.product_uuids == res
diff --git a/tests/models/gr/test_business.py b/tests/models/gr/test_business.py
index 2c12da1..90e69db 100644
--- a/tests/models/gr/test_business.py
+++ b/tests/models/gr/test_business.py
@@ -64,10 +64,8 @@ class TestBusinessBankAccount:
gr_business: Business,
business_bank_account_manager: BusinessBankAccountManager,
):
- from generalresearch.models.gr.business import (
- BusinessBankAccount,
- TransferMethod,
- )
+ from generalresearch.models.gr.business import BusinessBankAccount
+ from generalresearch.models.gr.definitions import TransferMethod
instance = business_bank_account_manager.create(
business_id=gr_business.id,
@@ -115,7 +113,7 @@ class TestBusiness:
@pytest.fixture
def offset(self) -> str:
- return "30d"
+ return "30D"
@pytest.fixture
def duration(self) -> timedelta | None:
@@ -222,46 +220,46 @@ class TestBusiness:
def test_teams(
self,
- business: Business,
+ gr_business: Business,
team: Team,
team_manager: TeamManager,
gr_db: PostgresConfig,
):
- assert business.teams is None
+ assert gr_business.teams is None
- business.prefetch_teams(pg_config=gr_db)
- assert isinstance(business.teams, list)
- assert len(business.teams) == 0
+ gr_business.prefetch_teams(pg_config=gr_db)
+ assert isinstance(gr_business.teams, list)
+ assert len(gr_business.teams) == 0
- team_manager.add_business(team=team, business=business)
- assert len(business.teams) == 0
- business.prefetch_teams(pg_config=gr_db)
- assert len(business.teams) == 1
+ team_manager.add_business(team=team, business=gr_business)
+ assert len(gr_business.teams) == 0
+ gr_business.prefetch_teams(pg_config=gr_db)
+ assert len(gr_business.teams) == 1
def test_products(
self,
- business: Business,
+ gr_business: Business,
product_factory: Callable[..., Product],
product_manager: ProductManager,
):
- p1 = product_factory(business=business)
- assert business.products is None
+ p1 = product_factory(business=gr_business)
+ assert gr_business.products is None
- business.prefetch_products(product_manager=product_manager)
- assert isinstance(business.products, list)
- assert len(business.products) == 1
- assert isinstance(business.products[0], Product)
+ gr_business.prefetch_products(product_manager=product_manager)
+ assert isinstance(gr_business.products, list)
+ assert len(gr_business.products) == 1
+ assert isinstance(gr_business.products[0], Product)
- assert business.products[0].uuid == p1.uuid
+ assert gr_business.products[0].uuid == p1.uuid
# Add two more, but list is still one until we prefetch
- product_factory(business=business)
- product_factory(business=business)
- assert len(business.products) == 1
+ product_factory(business=gr_business)
+ product_factory(business=gr_business)
+ assert len(gr_business.products) == 1
- business.prefetch_products(product_manager=product_manager)
- assert len(business.products) == 3
+ gr_business.prefetch_products(product_manager=product_manager)
+ assert len(gr_business.products) == 3
def test_bank_accounts(
self,
@@ -306,7 +304,6 @@ class TestBusiness:
self,
gr_business: Business,
product_factory: Callable[..., Product],
- thl_web_rr: PostgresConfig,
thl_ledger_manager: ThlLedgerManager,
business_payout_event_manager: BusinessPayoutEventManager,
):
@@ -322,8 +319,6 @@ class TestBusiness:
thl_ledger_manager.get_account_or_create_bp_wallet(product=p)
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)
@@ -335,7 +330,6 @@ class TestBusiness:
product_factory: Callable[..., Product],
bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
thl_ledger_manager: ThlLedgerManager,
- thl_web_rr: PostgresConfig,
business_payout_event_manager: BusinessPayoutEventManager,
create_main_accounts: Callable[..., None],
):
@@ -351,8 +345,6 @@ class TestBusiness:
)
gr_business.prebuild_payouts(
- thl_pg_config=thl_web_rr,
- thl_lm=thl_ledger_manager,
bpem=business_payout_event_manager,
)
assert len(gr_business.payouts) == 1
@@ -478,7 +470,7 @@ class TestBusinessBalance:
@pytest.fixture
def offset(self) -> str:
- return "30d"
+ return "30D"
@pytest.fixture
def duration(self) -> timedelta | None:
@@ -1190,15 +1182,14 @@ class TestBusinessMethods:
) -> timedelta | None:
return None
- def test_cache_key(self, business: Business):
- assert isinstance(business.cache_key, str)
- assert ":" in business.cache_key
- assert str(business.uuid) in business.cache_key
+ def test_cache_key(self, gr_business: Business):
+ assert isinstance(gr_business.cache_key, str)
+ assert ":" in gr_business.cache_key
+ assert str(gr_business.uuid) in gr_business.cache_key
def test_set_cache(
self,
gr_business: Business,
- gr_redis: RedisConfig,
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
client_no_amm: DaskClient,
@@ -1218,7 +1209,8 @@ class TestBusinessMethods:
gr_redis_config: RedisConfig,
mnt_gr_api_dir: Path,
):
- assert gr_redis.get(name=gr_business.cache_key) is None
+ client = gr_redis_config.create_redis_client()
+ assert client.get(name=gr_business.cache_key) is None
p1 = product_factory(team=team, business=gr_business)
u1 = user_factory(product=p1)
@@ -1244,7 +1236,7 @@ class TestBusinessMethods:
mnt_gr_api=mnt_gr_api_dir,
)
- assert gr_redis.hgetall(name=gr_business.cache_key) is not None
+ assert client.hgetall(name=gr_business.cache_key) is not None
from generalresearch.models.gr.business import Business
# We're going to pull only a specific year, but make sure that
@@ -1367,7 +1359,7 @@ class TestBusinessMethods:
session_factory: Callable[..., Session],
product_factory: Callable[..., Product],
delete_df_collection: Callable[..., None],
- business: Business,
+ gr_business: Business,
mnt_filepath: GRLDatasets,
mnt_gr_api_dir: Path,
):
@@ -1375,8 +1367,8 @@ class TestBusinessMethods:
delete_df_collection(coll=wall_collection)
delete_df_collection(coll=session_collection)
- p1 = product_factory(business=business)
- p2 = product_factory(business=business)
+ p1 = product_factory(business=gr_business)
+ p2 = product_factory(business=gr_business)
for p in [p1, p2]:
u = user_factory(product=p)
@@ -1397,7 +1389,7 @@ class TestBusinessMethods:
pg_config=thl_web_rr,
)
- business.prebuild_enriched_session_parquet(
+ gr_business.prebuild_enriched_session_parquet(
thl_pg_config=thl_web_rr,
ds=mnt_filepath,
client=client_no_amm,
@@ -1407,7 +1399,9 @@ class TestBusinessMethods:
# Now try to read from path
df = pd.read_parquet(
- os.path.join(mnt_gr_api_dir, "pop_session", f"{business.file_key}.parquet")
+ os.path.join(
+ mnt_gr_api_dir, "pop_session", f"{gr_business.file_key}.parquet"
+ )
)
assert isinstance(df, pd.DataFrame)
diff --git a/tests/models/gr/test_team.py b/tests/models/gr/test_team.py
index c1ae6d6..aa2de45 100644
--- a/tests/models/gr/test_team.py
+++ b/tests/models/gr/test_team.py
@@ -152,7 +152,6 @@ class TestTeamMethods:
def test_set_cache(
self,
team: Team,
- gr_redis: RedisConfig,
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
gr_redis_config: RedisConfig,
@@ -162,7 +161,8 @@ class TestTeamMethods:
enriched_wall_merge: EnrichedWallMerge,
enriched_session_merge: EnrichedSessionMerge,
):
- assert gr_redis.get(name=team.cache_key) is None
+ client = gr_redis_config.create_redis_client()
+ assert client.get(name=team.cache_key) is None
team.set_cache(
pg_config=gr_db,
@@ -175,7 +175,7 @@ class TestTeamMethods:
enriched_session=enriched_session_merge,
)
- assert gr_redis.hgetall(name=team.cache_key) is not None
+ assert client.hgetall(name=team.cache_key) is not None
def test_set_cache_team(
self,
diff --git a/tests/models/test_finance.py b/tests/models/test_finance.py
index eabc877..c579d78 100644
--- a/tests/models/test_finance.py
+++ b/tests/models/test_finance.py
@@ -760,7 +760,7 @@ class TestPOPFinancialData:
duration: timedelta,
create_main_accounts: Callable[..., None],
session_with_tx_factory: Callable[..., Session],
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
delete_df_collection: Callable[..., None],
delete_ledger_db: Callable[..., None],
):
@@ -798,8 +798,10 @@ class TestPOPFinancialData:
last_item_finish = item_finishes[0]
accounts = []
- for _ in users:
- account = thl_lm.get_account_or_create_bp_wallet(product=u.product)
+ for _u in users:
+ account = thl_ledger_manager.get_account_or_create_bp_wallet(
+ product=_u.product
+ )
accounts.append(account)
account_ids = [a.uuid for a in accounts]
@@ -856,7 +858,7 @@ class TestBusinessBalanceData:
user_factory: Callable[..., User],
product: Product,
create_main_accounts: Callable[..., None],
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
thl_web_rr: PostgresConfig,
delete_df_collection: Callable[..., None],
delete_ledger_db: Callable[..., None],
@@ -886,7 +888,9 @@ class TestBusinessBalanceData:
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
# assert pop_ledger_merge.progress.has_archive.eq(True).all()
- account: LedgerAccount = thl_lm.get_account_or_create_bp_wallet(product=product)
+ account: LedgerAccount = thl_ledger_manager.get_account_or_create_bp_wallet(
+ product=product
+ )
ddf = pop_ledger_merge.ddf(
force_rr_latest=False,
diff --git a/tests/models/thl/test_payout.py b/tests/models/thl/test_payout.py
index 927687e..cc00f33 100644
--- a/tests/models/thl/test_payout.py
+++ b/tests/models/thl/test_payout.py
@@ -10,8 +10,8 @@ from generalresearch.models.gr import Team
from generalresearch.models.gr.business import (
Business,
BusinessAddress,
- BusinessType,
)
+from generalresearch.models.gr.definitions import BusinessType
from generalresearch.models.thl.payout import (
BrokerageProductPayoutEvent,
BusinessPayoutEvent,
diff --git a/tests/models/thl/test_product.py b/tests/models/thl/test_product.py
index cc0fa8e..a1b3688 100644
--- a/tests/models/thl/test_product.py
+++ b/tests/models/thl/test_product.py
@@ -603,7 +603,7 @@ class TestProductFinancials:
@pytest.fixture
def offset(self) -> str:
- return "30d"
+ return "30D"
@pytest.fixture
def duration(self) -> timedelta | None:
@@ -611,12 +611,12 @@ class TestProductFinancials:
def test_balance(
self,
- business: Business,
+ gr_business: Business,
product_factory: Callable[..., Product],
user_factory: Callable[..., User],
mnt_filepath: GRLDatasets,
bp_payout_factory: Callable[..., BrokerageProductPayoutEvent],
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
start: datetime,
brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
session_with_tx_factory: Callable[..., Session],
@@ -633,33 +633,54 @@ class TestProductFinancials:
from generalresearch.currency import USDCent
- p1: Product = product_factory(business=business)
+ p1: Product = product_factory(business=gr_business)
u1: User = user_factory(product=p1)
- bp_wallet = thl_lm.get_account_or_create_bp_wallet(product=p1)
- thl_lm.get_account_or_create_user_wallet(user=u1)
+ bp_wallet = thl_ledger_manager.get_account_or_create_bp_wallet(product=p1)
+ thl_ledger_manager.get_account_or_create_user_wallet(user=u1)
brokerage_product_payout_event_manager.set_account_lookup_table(thl_lm=thl_lm)
- assert len(thl_lm.get_tx_filtered_by_account(account_uuid=bp_wallet.uuid)) == 0
+ assert (
+ len(
+ thl_ledger_manager.get_tx_filtered_by_account(
+ account_uuid=bp_wallet.uuid
+ )
+ )
+ == 0
+ )
session_with_tx_factory(
user=u1,
wall_req_cpi=Decimal(".50"),
started=start + timedelta(days=1),
)
- assert thl_lm.get_account_balance(account=bp_wallet) == 48
- assert len(thl_lm.get_tx_filtered_by_account(account_uuid=bp_wallet.uuid)) == 1
+ assert thl_ledger_manager.get_account_balance(account=bp_wallet) == 48
+ assert (
+ len(
+ thl_ledger_manager.get_tx_filtered_by_account(
+ account_uuid=bp_wallet.uuid
+ )
+ )
+ == 1
+ )
session_with_tx_factory(
user=u1,
wall_req_cpi=Decimal("1.00"),
started=start + timedelta(days=2),
)
- assert thl_lm.get_account_balance(account=bp_wallet) == 143
- assert len(thl_lm.get_tx_filtered_by_account(account_uuid=bp_wallet.uuid)) == 2
+ assert thl_ledger_manager.get_account_balance(account=bp_wallet) == 143
+ assert (
+ len(
+ thl_ledger_manager.get_tx_filtered_by_account(
+ account_uuid=bp_wallet.uuid
+ )
+ )
+ == 2
+ )
with pytest.raises(expected_exception=AssertionError) as cm:
p1.prebuild_balance(
- thl_lm=thl_lm,
+ thl_lm=thl_ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
)
@@ -669,7 +690,7 @@ class TestProductFinancials:
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
p1.prebuild_balance(
- thl_lm=thl_lm,
+ thl_lm=thl_ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
)
@@ -683,7 +704,7 @@ class TestProductFinancials:
assert p1.balance.available_balance == 108
p1.prebuild_payouts(
- thl_lm=thl_lm,
+ thl_lm=thl_ledger_manager,
bp_pem=brokerage_product_payout_event_manager,
)
assert p1.payouts is not None
@@ -700,7 +721,14 @@ class TestProductFinancials:
skip_wallet_balance_check=True,
skip_one_per_day_check=True,
)
- assert len(thl_lm.get_tx_filtered_by_account(account_uuid=bp_wallet.uuid)) == 3
+ assert (
+ len(
+ thl_ledger_manager.get_tx_filtered_by_account(
+ account_uuid=bp_wallet.uuid
+ )
+ )
+ == 3
+ )
# RM the entire directories
shutil.rmtree(ledger_collection.archive_path)
@@ -712,7 +740,7 @@ class TestProductFinancials:
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
p1.prebuild_balance(
- thl_lm=thl_lm,
+ thl_lm=thl_ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
)
@@ -726,7 +754,7 @@ class TestProductFinancials:
assert p1.balance.available_balance == 70
p1.prebuild_payouts(
- thl_lm=thl_lm,
+ thl_lm=thl_ledger_manager,
bp_pem=brokerage_product_payout_event_manager,
)
assert p1.payouts is not None
@@ -743,7 +771,14 @@ class TestProductFinancials:
skip_wallet_balance_check=True,
skip_one_per_day_check=True,
)
- assert len(thl_lm.get_tx_filtered_by_account(account_uuid=bp_wallet.uuid)) == 4
+ assert (
+ len(
+ thl_ledger_manager.get_tx_filtered_by_account(
+ account_uuid=bp_wallet.uuid
+ )
+ )
+ == 4
+ )
# RM the entire directories
shutil.rmtree(ledger_collection.archive_path)
@@ -755,7 +790,7 @@ class TestProductFinancials:
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
p1.prebuild_balance(
- thl_lm=thl_lm,
+ thl_lm=thl_ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
)
@@ -769,7 +804,7 @@ class TestProductFinancials:
assert p1.balance.available_balance == 66
p1.prebuild_payouts(
- thl_lm=thl_lm,
+ thl_lm=thl_ledger_manager,
bp_pem=brokerage_product_payout_event_manager,
)
assert p1.payouts is not None
@@ -786,7 +821,7 @@ class TestProductBalance:
@pytest.fixture
def offset(self) -> str:
- return "30d"
+ return "30D"
@pytest.fixture
def duration(self) -> timedelta | None:
@@ -796,7 +831,7 @@ class TestProductBalance:
self,
product: Product,
mnt_filepath: GRLDatasets,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
client_no_amm: DaskClient,
delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
@@ -826,7 +861,7 @@ class TestProductBalance:
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
# 2. Payout and build Parquets 2nd time
- payout_event_manager.set_account_lookup_table(thl_lm=thl_lm)
+ payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
bp_payout_factory(
product=product,
amount=USDCent(71),
@@ -840,7 +875,7 @@ class TestProductBalance:
with pytest.raises(expected_exception=AssertionError) as cm:
product.prebuild_balance(
- thl_lm=thl_lm, ds=mnt_filepath, client=client_no_amm
+ thl_lm=thl_ledger_manager, ds=mnt_filepath, client=client_no_amm
)
assert "Sql and Parquet Balance inconsistent" in str(cm)
@@ -848,7 +883,7 @@ class TestProductBalance:
self,
product: Product,
mnt_filepath: GRLDatasets,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
client_no_amm: DaskClient,
delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
@@ -885,7 +920,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_lm)
+ payout_event_manager.set_account_lookup_table(thl_lm=thl_ledger_manager)
bp_payout_factory(
product=product,
amount=USDCent(71),
@@ -898,7 +933,9 @@ class TestProductBalance:
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
# We just want to call this to confirm it doesn't raise.
- product.prebuild_balance(thl_lm=thl_lm, ds=mnt_filepath, client=client_no_amm)
+ product.prebuild_balance(
+ thl_lm=thl_ledger_manager, ds=mnt_filepath, client=client_no_amm
+ )
class TestProductPOPFinancial:
@@ -909,7 +946,7 @@ class TestProductPOPFinancial:
@pytest.fixture
def offset(self) -> str:
- return "30d"
+ return "30D"
@pytest.fixture
def duration(self) -> timedelta | None:
@@ -919,7 +956,7 @@ class TestProductPOPFinancial:
self,
product: Product,
mnt_filepath: GRLDatasets,
- thl_lm: ThlLedgerManager,
+ thl_ledger_manager: ThlLedgerManager,
client_no_amm: DaskClient,
delete_ledger_db: Callable[..., None],
create_main_accounts: Callable[..., None],
@@ -955,7 +992,7 @@ class TestProductPOPFinancial:
# --- test ---
assert product.pop_financial is None
product.prebuild_pop_financial(
- thl_lm=thl_lm,
+ thl_lm=thl_ledger_manager,
ds=mnt_filepath,
client=client_no_amm,
pop_ledger=pop_ledger_merge,
@@ -982,7 +1019,7 @@ class TestProductCache:
@pytest.fixture
def offset(self) -> str:
- return "30d"
+ return "30D"
@pytest.fixture
def duration(self) -> timedelta | None: