aboutsummaryrefslogtreecommitdiff
path: root/tests/managers
diff options
context:
space:
mode:
authorGreg Stupp2026-10-13 15:53:56 +0000
committerGreg Stupp2026-10-13 15:53:56 +0000
commitc265cc29d7a864651377c94be8695c9cf9b79bf1 (patch)
treead6fae9db1762ab83a373a71f67e9a796ac6726a /tests/managers
parentc975021688d2c195f8d585ebd919b9cbdacb09ad (diff)
parentc53c0f938684bbc98b7cccac2d886a6926b6e7f2 (diff)
downloadgeneralresearch-c265cc29d7a864651377c94be8695c9cf9b79bf1.tar.gz
generalresearch-c265cc29d7a864651377c94be8695c9cf9b79bf1.zip
Merges pull request #9 v3.8.0
Pagination and ordering of business and product payouts
Diffstat (limited to 'tests/managers')
-rw-r--r--tests/managers/gr/test_business.py24
-rw-r--r--tests/managers/thl/test_ledger/test_thl_pem.py14
2 files changed, 35 insertions, 3 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],