aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Nanis2026-02-27 02:35:47 -0500
committerMax Nanis2026-02-27 02:35:47 -0500
commit205449a8e59c78f3b1032a3b996463d22588f05f (patch)
treefdb706dc4ed6ab5e173d0ad4d39fcdd198a91ab8
parentdadd9643feceac94a2b84d9a3d3dda667f17583d (diff)
downloadamt-jb-205449a8e59c78f3b1032a3b996463d22588f05f.tar.gz
amt-jb-205449a8e59c78f3b1032a3b996463d22588f05f.zip
tests.flow all pass. Now everything is GREEN ✅
-rw-r--r--jb/managers/assignment.py4
-rw-r--r--jb/managers/thl.py2
-rw-r--r--tests/fixtures/flow.py25
-rw-r--r--tests/fixtures/models.py4
-rw-r--r--tests/flow/__init__.py16
-rw-r--r--tests/flow/test_tasks.py17
6 files changed, 52 insertions, 16 deletions
diff --git a/jb/managers/assignment.py b/jb/managers/assignment.py
index c0a168e..6104bc5 100644
--- a/jb/managers/assignment.py
+++ b/jb/managers/assignment.py
@@ -2,7 +2,7 @@ from datetime import datetime, timezone
from typing import Optional
from psycopg import sql
-from pydantic import NonNegativeInt
+from pydantic import NonNegativeInt, PositiveInt
from jb.managers import PostgresManager
from jb.models.assignment import AssignmentStub, Assignment
@@ -215,7 +215,7 @@ class AssignmentManager(PostgresManager):
return None
def missing_tsid_count(
- self, amt_worker_id: str, lookback_hrs: int = 24
+ self, amt_worker_id: str, lookback_hrs: PositiveInt = 24
) -> NonNegativeInt:
"""
Look at this user's previous N hrs of submitted assignments.
diff --git a/jb/managers/thl.py b/jb/managers/thl.py
index 83f49f6..44b6496 100644
--- a/jb/managers/thl.py
+++ b/jb/managers/thl.py
@@ -23,6 +23,7 @@ import requests
def get_user_profile(amt_worker_id: str) -> UserProfile:
url = f"{settings.fsb_host}{settings.product_id}/user/{amt_worker_id}/profile/"
res = requests.get(url).json()
+
if res.get("detail") == "user not found":
raise ValueError("user not found")
@@ -39,6 +40,7 @@ def get_user_blocked_or_not_exists(amt_worker_id: str) -> Optional[bool]:
try:
res = get_user_profile(amt_worker_id=amt_worker_id)
return res.user.blocked if res.user.blocked is not None else False
+
except ValueError as e:
if e.args[0] == "user not found":
return True
diff --git a/tests/fixtures/flow.py b/tests/fixtures/flow.py
index 5ee2026..dd2f83e 100644
--- a/tests/fixtures/flow.py
+++ b/tests/fixtures/flow.py
@@ -27,10 +27,10 @@ from generalresearchutils.models.thl.definitions import PayoutStatus
@pytest.fixture
def approved_assignment_stubs(
assignment_response: GetAssignmentResponseTypeDef,
- assignment_response_approved: Callable[[str], GetAssignmentResponseTypeDef],
+ assignment_response_factory_approved: Callable[[str], GetAssignmentResponseTypeDef],
amt_assignment_id: str,
amt_hit_id: str,
- get_hit_response_reviewing: GetHITResponseTypeDef,
+ hit_response_reviewing: GetHITResponseTypeDef,
) -> Callable[..., list[Dict[str, Any]]]:
# These are the AMT_CLIENT stubs/mocks that need to be set when running
@@ -43,8 +43,8 @@ def approved_assignment_stubs(
) -> list[Dict[str, Any]]:
response = override_response or assignment_response
- approve_response = override_approve_response or assignment_response_approved(
- feedback
+ approve_response = (
+ override_approve_response or assignment_response_factory_approved(feedback)
)
return [
@@ -74,7 +74,7 @@ def approved_assignment_stubs(
},
{
"operation": "get_hit",
- "response": get_hit_response_reviewing,
+ "response": hit_response_reviewing,
"expected_params": {"HITId": amt_hit_id},
},
]
@@ -218,7 +218,15 @@ def mock_thl_responses(
class MockThlProfileResponse:
def json(self):
- return {"user_profile": {"user": {"blocked": user_blocked}}}
+ return {
+ "user_profile": {
+ "user": {
+ "product_id": settings.product_id,
+ "product_user_id": amt_worker_id,
+ "blocked": user_blocked,
+ }
+ }
+ }
return MockThlProfileResponse()
@@ -227,7 +235,10 @@ def mock_thl_responses(
class MockThlWalletResponse:
def json(self) -> Dict[str, Any]:
return {
- "wallet": {"redeemable_amount": wallet_redeemable_amount}
+ "wallet": {
+ "amount": wallet_redeemable_amount,
+ "redeemable_amount": wallet_redeemable_amount,
+ }
}
return MockThlWalletResponse()
diff --git a/tests/fixtures/models.py b/tests/fixtures/models.py
index 03bd8a2..bdb4e12 100644
--- a/tests/fixtures/models.py
+++ b/tests/fixtures/models.py
@@ -242,7 +242,7 @@ def assignment_record(
@pytest.fixture
-def assignment_factory(hit: Hit) -> Callable[[Optional[str]], Assignment]:
+def assignment_factory(hit_record: Hit) -> Callable[[Optional[str]], Assignment]:
def _inner(amt_worker_id: Optional[str] = None) -> Assignment:
now = datetime.now(tz=timezone.utc)
@@ -251,7 +251,7 @@ def assignment_factory(hit: Hit) -> Callable[[Optional[str]], Assignment]:
return Assignment(
amt_assignment_id=amt_assignment_id,
- amt_hit_id=hit.amt_hit_id,
+ amt_hit_id=hit_record.amt_hit_id,
amt_worker_id=amt_worker_id,
status=AssignmentStatus.Submitted,
modified_at=now,
diff --git a/tests/flow/__init__.py b/tests/flow/__init__.py
index e69de29..3c88c7e 100644
--- a/tests/flow/__init__.py
+++ b/tests/flow/__init__.py
@@ -0,0 +1,16 @@
+# def test_a_hit():
+# hit_type = HitType(
+# title="Sandbox Test 2026-02-04",
+# description="test description",
+# reward=USDCent(5),
+# keywords="a,b,c",
+# min_active=10,
+# )
+# AMTManager.create_hit_type(hit_type=hit_type)
+# HTM.create(hit_type)
+
+# hit_type = HTM.get(amt_hit_type_id=hit_type.amt_hit_type_id)
+# hit = create_hit_from_hittype(hit_type)
+
+# hit_type = HTM.get(amt_hit_type_id="3QMCR5SRRVWV0O3UDSC64VSB8KL4GL")
+# hit = create_hit_from_hittype(hit_type)
diff --git a/tests/flow/test_tasks.py b/tests/flow/test_tasks.py
index 2aeffb9..3a71504 100644
--- a/tests/flow/test_tasks.py
+++ b/tests/flow/test_tasks.py
@@ -227,8 +227,8 @@ class TestProcessAssignmentSubmitted:
..., GetAssignmentResponseTypeDef
],
assignment_response_no_tsid: GetAssignmentResponseTypeDef,
- assignment_factory: Callable[..., Assignment],
- hit_record: Hit,
+ assignment_record_factory: Callable[..., Assignment],
+ hit_record: Hit, # used in assignment_factory
amt_worker_id: str,
):
# An assignment is submitted. The hit and assignment stub exist in the DB.
@@ -237,9 +237,16 @@ class TestProcessAssignmentSubmitted:
# Going to create and submit 3 assignments w no work
# (all on the same hit, which we don't do in JB for real,
# but doesn't matter here)
- _a1 = assignment_factory(hit_id=hit_record.id, amt_worker_id=amt_worker_id)
- _a2 = assignment_factory(hit_id=hit_record.id, amt_worker_id=amt_worker_id)
- _a3 = assignment_factory(hit_id=hit_record.id, amt_worker_id=amt_worker_id)
+ _a1 = assignment_record_factory(
+ hit_id=hit_record.id, amt_worker_id=amt_worker_id
+ )
+ _a2 = assignment_record_factory(
+ hit_id=hit_record.id, amt_worker_id=amt_worker_id
+ )
+ _a3 = assignment_record_factory(
+ hit_id=hit_record.id, amt_worker_id=amt_worker_id
+ )
+
assert am.missing_tsid_count(amt_worker_id=amt_worker_id) == 3
# So now, we'll reject, b/c they've already gotten 3 warnings