aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuppie2026-09-07 11:12:04 -0600
committerstuppie2026-09-07 11:12:04 -0600
commit3338f74a94d0624bf894ebb35bd1bcfca268216e (patch)
tree17c01719cde989d9b6f65ed86580332046f23dad
parent9002e4ea94ce790210ce42f4950a9e63ee8ca27b (diff)
downloadgeneralresearch-3338f74a94d0624bf894ebb35bd1bcfca268216e.tar.gz
generalresearch-3338f74a94d0624bf894ebb35bd1bcfca268216e.zip
fix more tests. Fix survey score optional field
-rw-r--r--generalresearch/models/gr/team.py2
-rw-r--r--generalresearch/models/thl/survey/buyer.py3
-rw-r--r--test_utils/models/gr/conftest.py37
-rw-r--r--test_utils/models/thl/conftest.py12
-rw-r--r--tests/models/gr/test_authentication.py2
-rw-r--r--tests/models/gr/test_business.py80
-rw-r--r--tests/models/gr/test_team.py13
-rw-r--r--tests/models/thl/test_contest/test_leaderboard_contest.py4
-rw-r--r--tests/models/thl/test_product.py12
9 files changed, 52 insertions, 113 deletions
diff --git a/generalresearch/models/gr/team.py b/generalresearch/models/gr/team.py
index aaa5869..8d23bc5 100644
--- a/generalresearch/models/gr/team.py
+++ b/generalresearch/models/gr/team.py
@@ -273,7 +273,7 @@ class Team(BaseModel):
self.prefetch_products(product_manager=product_manager)
self.prefetch_gr_users(gr_user_manager=gr_user_manager)
self.prefetch_businesses(gr_business_manager=gr_business_manager)
- self.prefetch_memberships(membership_manager=gr_membership_manager)
+ self.prefetch_memberships(gr_membership_manager=gr_membership_manager)
rc = redis_config.create_redis_client()
mapping = self.model_dump(mode="json")
diff --git a/generalresearch/models/thl/survey/buyer.py b/generalresearch/models/thl/survey/buyer.py
index 6a67ed7..91102b4 100644
--- a/generalresearch/models/thl/survey/buyer.py
+++ b/generalresearch/models/thl/survey/buyer.py
@@ -177,9 +177,10 @@ class BuyerCountryStat(BaseModel):
)
# ---- Scoring ----
- score: float = Field(
+ score: float | None = Field(
description="Composite score calculated from all of the individual features",
examples=[-5.329389837486194],
+ default=None,
)
@model_validator(mode="after")
diff --git a/test_utils/models/gr/conftest.py b/test_utils/models/gr/conftest.py
index 859aaa4..f5dcaa1 100644
--- a/test_utils/models/gr/conftest.py
+++ b/test_utils/models/gr/conftest.py
@@ -91,7 +91,6 @@ def gr_business_address_factory(
def _inner(
business_id: PositiveInt,
- save: bool = True,
uuid: UUIDStr | None = None,
line_1: str | None = None,
line_2: str | None = None,
@@ -110,36 +109,26 @@ def gr_business_address_factory(
phone_number = None
country = country or "US"
- if save:
- return gr_business_address_manager.create(
- business_id=business_id,
- uuid=uuid,
- line_1=line_1,
- line_2=line_2,
- city=city,
- state=state,
- postal_code=postal_code,
- phone_number=phone_number,
- country=country,
- )
- else:
- raise ValueError("Unsaved BusinessAddress not supported yet")
+ return gr_business_address_manager.create(
+ business_id=business_id,
+ uuid=uuid,
+ line_1=line_1,
+ line_2=line_2,
+ city=city,
+ state=state,
+ postal_code=postal_code,
+ phone_number=phone_number,
+ country=country,
+ )
return _inner
@pytest.fixture
def gr_business_address(
- gr_business_address_factory: Callable[..., BusinessAddress],
-) -> BusinessAddress:
- return gr_business_address_factory(save=True)
-
-
-@pytest.fixture
-def unsaved_gr_business_address(
- gr_business_address_factory: Callable[..., BusinessAddress],
+ gr_business_address_factory: Callable[..., BusinessAddress], gr_business: Business
) -> BusinessAddress:
- return gr_business_address_factory(save=False)
+ return gr_business_address_factory(business_id=gr_business.id)
# --- Business ---
diff --git a/test_utils/models/thl/conftest.py b/test_utils/models/thl/conftest.py
index 376891c..e09eadd 100644
--- a/test_utils/models/thl/conftest.py
+++ b/test_utils/models/thl/conftest.py
@@ -14,7 +14,10 @@ from grip_client.enums import AccessType
from pydantic import PositiveInt
from generalresearch.currency import USDCent
-from generalresearch.managers.thl.payout import UserPayoutEventManager
+from generalresearch.managers.thl.payout import (
+ BusinessPayoutEventManager,
+ UserPayoutEventManager,
+)
from generalresearch.models.custom_types import (
AwareDatetimeISO,
IPvAnyAddressStr,
@@ -38,9 +41,6 @@ if TYPE_CHECKING:
IPInformationManager,
)
from generalresearch.managers.thl.ledger_manager.thl_ledger import ThlLedgerManager
- from generalresearch.managers.thl.payout import (
- BrokerageProductPayoutEventManager,
- )
from generalresearch.managers.thl.product import ProductManager
from generalresearch.managers.thl.session import SessionManager
from generalresearch.managers.thl.user_manager.user_manager import UserManager
@@ -777,7 +777,7 @@ def unsaved_user_payout_event(
@pytest.fixture
def brokerage_product_payout_event_factory(
thl_ledger_manager: ThlLedgerManager,
- brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager,
+ business_payout_event_manager: BusinessPayoutEventManager,
product_factory: Callable[..., Product],
) -> Callable[..., BrokerageProductPayoutEvent]:
@@ -791,7 +791,7 @@ def brokerage_product_payout_event_factory(
product = product or product_factory()
amount = amount or USDCent(randint(1, 99_99))
- return brokerage_product_payout_event_manager.create_bp_payout_event(
+ return business_payout_event_manager.create_bp_payout_event(
thl_ledger_manager=thl_ledger_manager,
product=product,
amount=amount,
diff --git a/tests/models/gr/test_authentication.py b/tests/models/gr/test_authentication.py
index 7ff44d0..21e07a4 100644
--- a/tests/models/gr/test_authentication.py
+++ b/tests/models/gr/test_authentication.py
@@ -205,6 +205,7 @@ class TestGRUserMethods:
product_factory: Callable[..., Product],
gr_team: Team,
gr_redis_config: RedisConfig,
+ gr_membership,
):
product_factory(team=gr_team)
client = gr_redis_config.create_redis_client()
@@ -246,6 +247,7 @@ class TestGRUserMethods:
product_factory: Callable[..., Product],
gr_team: Team,
gr_redis_config: RedisConfig,
+ gr_membership,
):
product_factory(team=gr_team)
diff --git a/tests/models/gr/test_business.py b/tests/models/gr/test_business.py
index 5d0de4f..e38850d 100644
--- a/tests/models/gr/test_business.py
+++ b/tests/models/gr/test_business.py
@@ -58,7 +58,6 @@ if TYPE_CHECKING:
class TestBusinessBankAccount:
-
def test_init(
self,
gr_business: Business,
@@ -93,13 +92,11 @@ class TestBusinessBankAccount:
class TestBusinessAddress:
-
- def test_init(self, business_address: BusinessAddress):
- assert isinstance(business_address, BusinessAddress)
+ def test_init(self, gr_business_address: BusinessAddress):
+ assert isinstance(gr_business_address, BusinessAddress)
class TestBusinessContact:
-
def test_init(self):
bc = BusinessContact(name="abc", email="test@abc.com")
@@ -173,9 +170,6 @@ class TestBusiness:
assert "Ledger Accounts: 2" in res3
# -- need some tx to make these interesting
- business_payout_event_manager.set_account_lookup_table(
- thl_lm=thl_ledger_manager
- )
session_with_tx_factory(
user=u1,
wall_req_cpi=Decimal("2.50"),
@@ -185,8 +179,6 @@ class TestBusiness:
product=p1,
amount=USDCent(50),
created=start + timedelta(days=4),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
ledger_collection.initial_load(client=None, sync=True)
@@ -207,9 +199,7 @@ class TestBusiness:
assert "Available Balance: 141" in res4
def test_addresses(
- self,
- gr_business: Business,
- gr_db: PostgresConfig,
+ self, gr_business: Business, gr_db: PostgresConfig, gr_business_address
):
from generalresearch.models.gr.business import BusinessAddress
@@ -223,8 +213,8 @@ class TestBusiness:
def test_teams(
self,
gr_business: Business,
- team: Team,
- team_manager: TeamManager,
+ gr_team: Team,
+ gr_team_manager: TeamManager,
gr_db: PostgresConfig,
):
assert gr_business.teams is None
@@ -233,7 +223,7 @@ class TestBusiness:
assert isinstance(gr_business.teams, list)
assert len(gr_business.teams) == 0
- team_manager.add_business(team=team, business=gr_business)
+ gr_team_manager.add_business(team=gr_team, business=gr_business)
assert len(gr_business.teams) == 0
gr_business.prefetch_teams(pg_config=gr_db)
assert len(gr_business.teams) == 1
@@ -266,6 +256,7 @@ class TestBusiness:
def test_bank_accounts(
self,
gr_business: Business,
+ gr_business_bank_account,
gr_business_bank_account_manager: BusinessBankAccountManager,
):
assert gr_business.products is None
@@ -341,13 +332,8 @@ class TestBusiness:
create_main_accounts()
p = product_factory(business=gr_business)
thl_ledger_manager.get_account_or_create_bp_wallet(product=p)
- business_payout_event_manager.set_account_lookup_table(
- thl_lm=thl_ledger_manager
- )
- brokerage_product_payout_event_factory(
- product=p, amount=USDCent(123), skip_wallet_balance_check=True
- )
+ brokerage_product_payout_event_factory(product=p, amount=USDCent(123))
gr_business.prebuild_payouts(
bpem=business_payout_event_manager,
@@ -359,18 +345,13 @@ class TestBusiness:
brokerage_product_payout_event_factory(
product=p,
amount=USDCent(123),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
- )
- business_payout_event_manager.set_account_lookup_table(
- thl_lm=thl_ledger_manager
)
gr_business.prebuild_payouts(
bpem=business_payout_event_manager,
)
assert isinstance(gr_business.payouts, list)
- assert len(gr_business.payouts) == 1
- assert len(gr_business.payouts[0].bp_payouts) == 2
+ assert len(gr_business.payouts) == 2
+ assert len(gr_business.payouts[0].bp_payouts) == 1
assert sum([p.amount for p in gr_business.payouts]) == 246
def test_payouts_totals(
@@ -390,29 +371,20 @@ class TestBusiness:
p1: Product = product_factory(business=gr_business)
thl_ledger_manager.get_account_or_create_bp_wallet(product=p1)
- business_payout_event_manager.set_account_lookup_table(
- thl_lm=thl_ledger_manager
- )
brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(1),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(25),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
brokerage_product_payout_event_factory(
product=p1,
amount=USDCent(50),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
gr_business.prebuild_payouts(
@@ -420,8 +392,10 @@ class TestBusiness:
)
assert isinstance(gr_business.payouts, list)
- assert len(gr_business.payouts) == 1
- assert len(gr_business.payouts[0].bp_payouts) == 3
+ assert len(gr_business.payouts) == 3
+ assert len(gr_business.payouts[0].bp_payouts) == 1
+ assert len(gr_business.payouts[1].bp_payouts) == 1
+ assert len(gr_business.payouts[2].bp_payouts) == 1
assert gr_business.payouts_total == USDCent(76)
assert gr_business.payouts_total_str == "$0.76"
@@ -467,7 +441,6 @@ class TestBusiness:
class TestBusinessBalance:
-
@pytest.fixture
def start(self) -> datetime:
return datetime(year=2018, month=3, day=14, hour=0, tzinfo=UTC)
@@ -678,16 +651,12 @@ class TestBusinessBalance:
product=u1.product,
amount=USDCent(5),
created=start + timedelta(days=4),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
brokerage_product_payout_event_factory(
product=u2.product,
amount=USDCent(50),
created=start + timedelta(days=4),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
ledger_collection.initial_load(client=None, sync=True)
@@ -773,16 +742,12 @@ class TestBusinessBalance:
product=u1.product,
amount=USDCent(250),
created=start + timedelta(days=3),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
brokerage_product_payout_event_factory(
product=u2.product,
amount=USDCent(50),
created=start + timedelta(days=4),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
adj_to_fail_with_tx_factory(session=s1, created=start + timedelta(days=5))
@@ -889,8 +854,6 @@ class TestBusinessBalance:
amount=USDCent(71),
ext_ref_id=uuid4().hex,
created=start + timedelta(days=1, minutes=1),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
adj_to_fail_with_tx_factory(
session=s1,
@@ -1042,16 +1005,12 @@ class TestBusinessBalance:
product=u1.product,
amount=USDCent(250),
created=start + timedelta(days=3),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
brokerage_product_payout_event_factory(
product=u2.product,
amount=USDCent(50),
created=start + timedelta(days=4),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
session_with_tx_factory(
@@ -1177,7 +1136,6 @@ class TestBusinessBalance:
class TestBusinessMethods:
-
@pytest.fixture(scope="function")
def start(self, utc_90days_ago: datetime) -> datetime:
s = utc_90days_ago.replace(microsecond=0)
@@ -1269,7 +1227,7 @@ class TestBusinessMethods:
gr_db: PostgresConfig,
thl_web_rr: PostgresConfig,
product_factory: Callable[..., Product],
- team: Team,
+ gr_team: Team,
client_no_amm: DaskClient,
mnt_filepath: GRLDatasets,
ledger_manager: LedgerManager,
@@ -1282,7 +1240,7 @@ class TestBusinessMethods:
create_main_accounts: Callable[..., None],
session_with_tx_factory: Callable[..., Session],
ledger_collection,
- team_manager: TeamManager,
+ gr_team_manager: TeamManager,
pop_ledger_merge: PopLedgerMerge,
gr_redis_config: RedisConfig,
utc_60days_ago: datetime,
@@ -1290,9 +1248,9 @@ class TestBusinessMethods:
):
from generalresearch.models.gr.business import Business
- p1 = product_factory(team=team, business=gr_business)
+ p1 = product_factory(team=gr_team, business=gr_business)
u1 = user_factory(product=p1)
- team_manager.add_business(team=team, business=gr_business)
+ gr_team_manager.add_business(team=gr_team, business=gr_business)
# Business needs tx & incite to build balance
delete_ledger_db()
@@ -1345,7 +1303,7 @@ class TestBusinessMethods:
assert isinstance(business2.teams, list)
assert p1.uuid in [p.uuid for p in business2.products]
assert len(business2.teams) == 1
- assert team.uuid in [t.uuid for t in business2.teams]
+ assert gr_team.uuid in [t.uuid for t in business2.teams]
assert isinstance(business2.balance, BusinessBalances)
assert business2.balance.payout == 48
diff --git a/tests/models/gr/test_team.py b/tests/models/gr/test_team.py
index b5f1781..e853817 100644
--- a/tests/models/gr/test_team.py
+++ b/tests/models/gr/test_team.py
@@ -61,6 +61,7 @@ class TestTeam:
self,
gr_team: Team,
gr_user: GRUser,
+ gr_membership,
gr_user_factory: Callable[..., GRUser],
gr_membership_manager: MembershipManager,
):
@@ -105,7 +106,7 @@ class TestTeam:
def test_businesses(
self,
gr_team: Team,
- business: Business,
+ gr_business: Business,
team_manager: TeamManager,
gr_business_manager: BusinessManager,
):
@@ -116,12 +117,12 @@ class TestTeam:
assert isinstance(gr_team.businesses, list)
assert len(gr_team.businesses) == 0
- team_manager.add_business(team=gr_team, business=business)
+ team_manager.add_business(team=gr_team, business=gr_business)
assert len(gr_team.businesses) == 0
gr_team.prefetch_businesses(gr_business_manager=gr_business_manager)
assert len(gr_team.businesses) == 1
assert isinstance(gr_team.businesses[0], Business)
- assert gr_team.businesses[0].uuid == business.uuid
+ assert gr_team.businesses[0].uuid == gr_business.uuid
def test_products(
self,
@@ -174,7 +175,6 @@ class TestTeamMethods:
gr_user_manager=gr_user_manager,
gr_business_manager=gr_business_manager,
gr_membership_manager=gr_membership_manager,
- thl_web_rr=thl_web_rr,
redis_config=gr_redis_config,
client=client_no_amm,
ds=mnt_filepath,
@@ -192,7 +192,7 @@ class TestTeamMethods:
thl_web_rr: PostgresConfig,
product_factory: Callable[..., Product],
gr_team: Team,
- membership_factory: Callable[..., Membership],
+ gr_membership_factory: Callable[..., Membership],
gr_redis_config: RedisConfig,
mnt_filepath: GRLDatasets,
mnt_gr_api_dir: Path,
@@ -206,14 +206,13 @@ class TestTeamMethods:
from generalresearch.models.gr.team import Team
p1 = product_factory(team=gr_team)
- membership_factory(team=gr_team, gr_user=gr_user)
+ gr_membership_factory(gr_team=gr_team, gr_user=gr_user)
gr_team.set_cache(
product_manager=product_manager,
gr_user_manager=gr_user_manager,
gr_business_manager=gr_business_manager,
gr_membership_manager=gr_membership_manager,
- thl_web_rr=thl_web_rr,
redis_config=gr_redis_config,
client=client_no_amm,
ds=mnt_filepath,
diff --git a/tests/models/thl/test_contest/test_leaderboard_contest.py b/tests/models/thl/test_contest/test_leaderboard_contest.py
index f787bdf..a639261 100644
--- a/tests/models/thl/test_contest/test_leaderboard_contest.py
+++ b/tests/models/thl/test_contest/test_leaderboard_contest.py
@@ -100,14 +100,14 @@ class TestLeaderboardContest(TestContest):
def test_win(
self,
leaderboard_contest: LeaderboardContest,
- thl_redis: Redis,
+ thl_redis_client: Redis,
user_1: User,
user_2: User,
user_3: User,
):
model = leaderboard_contest.leaderboard_model
lbm = LeaderboardManager(
- redis_client=thl_redis,
+ redis_client=thl_redis_client,
board_code=model.board_code,
country_iso=model.country_iso,
freq=model.freq,
diff --git a/tests/models/thl/test_product.py b/tests/models/thl/test_product.py
index 25affcf..97abf0c 100644
--- a/tests/models/thl/test_product.py
+++ b/tests/models/thl/test_product.py
@@ -713,8 +713,6 @@ class TestProductFinancials:
product=p1,
amount=USDCent(50),
created=start + timedelta(days=3),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
assert (
len(
@@ -754,7 +752,7 @@ class TestProductFinancials:
)
assert p1.payouts is not None
assert len(p1.payouts) == 1
- assert p1.payouts_total == 50
+ assert p1.payouts_total == USDCent(50)
assert p1.payouts_total_str == "$0.50"
# -- Now pay ou another!.
@@ -763,8 +761,6 @@ class TestProductFinancials:
product=p1,
amount=USDCent(5),
created=start + timedelta(days=4),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
assert (
len(
@@ -862,8 +858,6 @@ class TestProductBalance:
amount=USDCent(71),
ext_ref_id=uuid4().hex,
created=start + timedelta(days=1, minutes=1),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
@@ -922,8 +916,6 @@ class TestProductBalance:
amount=USDCent(71),
ext_ref_id=uuid4().hex,
created=datetime.now(tz=UTC),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
ledger_collection.initial_load(client=None, sync=True)
pop_ledger_merge.build(client=client_no_amm, ledger_coll=ledger_collection)
@@ -1134,8 +1126,6 @@ class TestProductCache:
amount=USDCent(71),
ext_ref_id=uuid4().hex,
created=start + timedelta(days=1, minutes=1),
- skip_wallet_balance_check=True,
- skip_one_per_day_check=True,
)
# 3. Recon