From 1746411f8dd0b880b3d069afc0b008a176fd811a Mon Sep 17 00:00:00 2001 From: stuppie Date: Mon, 12 Oct 2026 16:59:03 -0700 Subject: BusinessCreate model. Remove payouts from Product (query for me). Pagination and ordering of business and product payouts --- tests/managers/gr/test_business.py | 24 ++++++++++++++++++++++-- tests/managers/thl/test_ledger/test_thl_pem.py | 14 +++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) (limited to 'tests/managers') diff --git a/tests/managers/gr/test_business.py b/tests/managers/gr/test_business.py index 022086a..f5ea9f0 100644 --- a/tests/managers/gr/test_business.py +++ b/tests/managers/gr/test_business.py @@ -136,13 +136,13 @@ class TestBusinessManager: # Add the Business to the Team... now the Business should be available # to the gr_user - gr_team_manager.add_business(team=t1, business=b1) + gr_team_manager.add_business(team_id=t1.id, business_id=b1.id) res = gr_business_manager.get_by_user_id(user_id=gr_user.id) assert len(res) == 1 # Add another Business to the Team! b2 = gr_business_factory() - gr_team_manager.add_business(team=t1, business=b2) + gr_team_manager.add_business(team_id=t1.id, business_id=b2.id) res = gr_business_manager.get_by_user_id(user_id=gr_user.id) assert len(res) == 2 @@ -164,6 +164,26 @@ class TestBusinessManager: assert isinstance(instance, Business) assert gr_business.uuid == instance.uuid + def test_get_methods_include_cached_fields( + self, gr_business: Business, gr_business_manager: BusinessManager + ): + gr_business.users_active_7d = 11 + gr_business.task_completes_7d = 22 + gr_business.balance_net_7d = 33 + gr_business_manager.update_cached_fields(gr_business) + + by_id = gr_business_manager.get_by_id(business_id=gr_business.id) + by_uuid = gr_business_manager.get_by_uuid(business_uuid=gr_business.uuid) + filtered = gr_business_manager.filter(business_id=gr_business.id) + + assert by_id is not None + assert by_uuid is not None + assert len(filtered) == 1 + for business in (by_id, by_uuid, filtered[0]): + assert business.users_active_7d == 11 + assert business.task_completes_7d == 22 + assert business.balance_net_7d == 33 + def test_cache_key(self, gr_business: Business): assert "business:" in gr_business.cache_key diff --git a/tests/managers/thl/test_ledger/test_thl_pem.py b/tests/managers/thl/test_ledger/test_thl_pem.py index 348a02d..ddf9bc9 100644 --- a/tests/managers/thl/test_ledger/test_thl_pem.py +++ b/tests/managers/thl/test_ledger/test_thl_pem.py @@ -69,13 +69,25 @@ class TestThlPayoutEventManager: accounts = thl_ledger_manager.get_accounts_bp_wallet_for_products( product_uuids=[i.uuid for i in products] ) - res = brokerage_product_payout_event_manager.filter_by( + res, count = brokerage_product_payout_event_manager.filter_by( debit_account_uuids=[i.uuid for i in accounts] ) assert len(res) == (N_PRODUCTS * N_PAYOUT_EVENTS) + assert count == len(res) assert sum([i.amount for i in res]) == sum(amounts) + page, count = brokerage_product_payout_event_manager.filter_by( + debit_account_uuids=[i.uuid for i in accounts], + page=1, + size=2, + order_field="created", + descending=True, + ) + assert len(page) == 2 + assert count == (N_PRODUCTS * N_PAYOUT_EVENTS) + assert page == sorted(page, key=lambda payout: payout.created, reverse=True) + def test_get_bp_payout_events_for_product( self, product_factory: Callable[..., Product], -- cgit v1.2.3