diff options
| author | Greg Stupp | 2026-10-13 15:53:56 +0000 |
|---|---|---|
| committer | Greg Stupp | 2026-10-13 15:53:56 +0000 |
| commit | c265cc29d7a864651377c94be8695c9cf9b79bf1 (patch) | |
| tree | ad6fae9db1762ab83a373a71f67e9a796ac6726a /tests | |
| parent | c975021688d2c195f8d585ebd919b9cbdacb09ad (diff) | |
| parent | c53c0f938684bbc98b7cccac2d886a6926b6e7f2 (diff) | |
| download | generalresearch-3.8.0.tar.gz generalresearch-3.8.0.zip | |
Merges pull request #9
v3.8.0
Pagination and ordering of business and product payouts
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/managers/gr/test_business.py | 24 | ||||
| -rw-r--r-- | tests/managers/thl/test_ledger/test_thl_pem.py | 14 | ||||
| -rw-r--r-- | tests/models/gr/test_business.py | 8 | ||||
| -rw-r--r-- | tests/models/gr/test_team.py | 4 |
4 files changed, 44 insertions, 6 deletions
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], diff --git a/tests/models/gr/test_business.py b/tests/models/gr/test_business.py index 8de2a47..7e0932c 100644 --- a/tests/models/gr/test_business.py +++ b/tests/models/gr/test_business.py @@ -218,7 +218,9 @@ class TestBusiness: assert isinstance(gr_business.teams, list) assert len(gr_business.teams) == 0 - gr_team_manager.add_business(team=gr_team, business=gr_business) + gr_team_manager.add_business( + team_id=gr_team.id, business_id=gr_business.id + ) assert len(gr_business.teams) == 0 gr_business.prefetch_teams(pg_config=gr_db) assert len(gr_business.teams) == 1 @@ -1246,7 +1248,9 @@ class TestBusinessMethods: p1 = product_factory(team=gr_team, business=gr_business) u1 = user_factory(product=p1) - gr_team_manager.add_business(team=gr_team, business=gr_business) + gr_team_manager.add_business( + team_id=gr_team.id, business_id=gr_business.id + ) # Business needs tx & incite to build balance delete_ledger_db() diff --git a/tests/models/gr/test_team.py b/tests/models/gr/test_team.py index 7c93209..8cc00c8 100644 --- a/tests/models/gr/test_team.py +++ b/tests/models/gr/test_team.py @@ -117,7 +117,9 @@ class TestTeam: assert isinstance(gr_team.businesses, list) assert len(gr_team.businesses) == 0 - gr_team_manager.add_business(team=gr_team, business=gr_business) + gr_team_manager.add_business( + team_id=gr_team.id, business_id=gr_business.id + ) assert len(gr_team.businesses) == 0 gr_team.prefetch_businesses(gr_business_manager=gr_business_manager) assert len(gr_team.businesses) == 1 |
