diff options
Diffstat (limited to 'tests/flow/test_tasks.py')
| -rw-r--r-- | tests/flow/test_tasks.py | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/tests/flow/test_tasks.py b/tests/flow/test_tasks.py index 3a71504..f28a6aa 100644 --- a/tests/flow/test_tasks.py +++ b/tests/flow/test_tasks.py @@ -1,34 +1,36 @@ import logging +from collections.abc import Callable from contextlib import contextmanager -from typing import Callable, Dict, Any +from typing import Any import pytest from botocore.stub import Stubber +from generalresearch.currency import USDCent +from mypy_boto3_mturk import MTurkClient +from mypy_boto3_mturk.type_defs import ( + GetAssignmentResponseTypeDef, +) + from jb.flow.assignment_tasks import process_assignment_submitted from jb.managers.amt import ( - AMTManager, APPROVAL_MESSAGE, + NO_WORK_APPROVAL_MESSAGE, REJECT_MESSAGE_BADDIE, - REJECT_MESSAGE_UNKNOWN_ASSIGNMENT, REJECT_MESSAGE_NO_WORK, - NO_WORK_APPROVAL_MESSAGE, -) -from mypy_boto3_mturk.type_defs import ( - GetAssignmentResponseTypeDef, + REJECT_MESSAGE_UNKNOWN_ASSIGNMENT, + AMTManager, ) -from generalresearchutils.currency import USDCent from jb.managers.assignment import AssignmentManager from jb.managers.bonus import BonusManager from jb.managers.hit import HitManager +from jb.models.assignment import Assignment, AssignmentStub from jb.models.definitions import AssignmentStatus from jb.models.event import MTurkEvent from jb.models.hit import Hit -from jb.models.assignment import Assignment, AssignmentStub -from mypy_boto3_mturk import MTurkClient @contextmanager -def amt_stub_context(amt_client: MTurkClient, responses: list[Dict[str, Any]]): +def amt_stub_context(amt_client: MTurkClient, responses: list[dict[str, Any]]): # ty chatgpt for this with Stubber(amt_client) as stub: @@ -83,7 +85,7 @@ class TestProcessAssignmentSubmitted: mturk_event: MTurkEvent, amt_assignment_id: str, caplog: pytest.LogCaptureFixture, - rejected_assignment_stubs: Callable[..., list[Dict[str, Any]]], + rejected_assignment_stubs: Callable[..., list[dict[str, Any]]], ): # These records are auto cleaned up, so we need to explicitly create @@ -107,9 +109,9 @@ class TestProcessAssignmentSubmitted: ) stub.assert_no_pending_responses() - assert f"No assignment found in DB: {amt_assignment_id}" in caplog.text - assert f"Rejected assignment doesn't exist in DB. Creating ... " in caplog.text - assert f"Rejected assignment: " in caplog.text + # assert f"No assignment found in DB: {amt_assignment_id}" in caplog.text + assert "Rejected assignment doesn't exist in DB. Creating ... " in caplog.text + assert "Rejected assignment: " in caplog.text stub.assert_no_pending_responses() ass = am.get(amt_assignment_id=amt_assignment_id) @@ -128,7 +130,7 @@ class TestProcessAssignmentSubmitted: assignment_stub_record: AssignmentStub, caplog: pytest.LogCaptureFixture, mock_thl_responses: Callable[..., None], - rejected_assignment_stubs: Callable[..., list[Dict[str, Any]]], + rejected_assignment_stubs: Callable[..., list[dict[str, Any]]], ): # An assignment is submitted. The hit and AssignmentStub exist in the # DB. We think we're going to approve the Assignment, but the @@ -140,7 +142,6 @@ class TestProcessAssignmentSubmitted: _ = assignment_stub_record amt_stubs = rejected_assignment_stubs(reject_reason=REJECT_MESSAGE_BADDIE) - mock_thl_responses(user_blocked=True) with amt_stub_context(amt_client, amt_stubs) as stub, caplog.at_level( @@ -151,9 +152,9 @@ class TestProcessAssignmentSubmitted: ) stub.assert_no_pending_responses() - assert f"No assignment found in DB: {amt_assignment_id}" not in caplog.text - assert f"blocked or not exists" in caplog.text - assert f"Rejected assignment: " in caplog.text + # assert f"No assignment found in DB: {amt_assignment_id}" not in caplog.text + assert "blocked or not exists" in caplog.text + assert "Rejected assignment: " in caplog.text ass = am.get(amt_assignment_id=amt_assignment_id) assert ass.status == AssignmentStatus.Rejected @@ -171,7 +172,7 @@ class TestProcessAssignmentSubmitted: assignment_stub_record: AssignmentStub, caplog: pytest.LogCaptureFixture, mock_thl_responses: Callable[..., None], - approved_assignment_stubs: Callable[..., list[Dict[str, Any]]], + approved_assignment_stubs: Callable[..., list[dict[str, Any]]], assignment_response_approved_no_tsid: GetAssignmentResponseTypeDef, assignment_response_no_tsid: GetAssignmentResponseTypeDef, ): @@ -202,8 +203,8 @@ class TestProcessAssignmentSubmitted: stub.assert_no_pending_responses() assert f"No assignment found in DB: {amt_assignment_id}" not in caplog.text - assert f"Assignment submitted with no tsid" in caplog.text - assert f"Approved assignment: " in caplog.text + assert "Assignment submitted with no tsid" in caplog.text + assert "Approved assignment: " in caplog.text ass = am.get(amt_assignment_id=amt_assignment_id) assert ass.status == AssignmentStatus.Approved @@ -222,7 +223,7 @@ class TestProcessAssignmentSubmitted: assignment_stub_record: AssignmentStub, caplog: pytest.LogCaptureFixture, mock_thl_responses: Callable[..., None], - rejected_assignment_stubs: Callable[..., list[Dict[str, Any]]], + rejected_assignment_stubs: Callable[..., list[dict[str, Any]]], assignment_response_factory_rejected_no_tsid: Callable[ ..., GetAssignmentResponseTypeDef ], @@ -273,8 +274,8 @@ class TestProcessAssignmentSubmitted: stub.assert_no_pending_responses() assert f"No assignment found in DB: {amt_assignment_id}" not in caplog.text - assert f"Assignment submitted with no tsid" in caplog.text - assert f"Rejected assignment: " in caplog.text + assert "Assignment submitted with no tsid" in caplog.text + assert "Rejected assignment: " in caplog.text # It will exist in the db since we can validate the model. ass = am.get(amt_assignment_id=amt_assignment_id) @@ -293,7 +294,7 @@ class TestProcessAssignmentSubmitted: assignment_stub_record: Assignment, caplog: pytest.LogCaptureFixture, mock_thl_responses: Callable[..., None], - approved_assignment_stubs: Callable[..., list[Dict[str, Any]]], + approved_assignment_stubs: Callable[..., list[dict[str, Any]]], ): _ = assignment_stub_record # we need this to make the assignment stub in the db @@ -330,7 +331,7 @@ class TestProcessAssignmentSubmitted: assignment_stub_record: Assignment, caplog: pytest.LogCaptureFixture, mock_thl_responses: Callable[..., None], - approved_assignment_stubs_w_bonus: list[Dict[str, Any]], + approved_assignment_stubs_w_bonus: list[dict[str, Any]], ): _ = assignment_stub_record # we need this to make the assignment stub in the db mock_thl_responses(status_complete=True, wallet_redeemable_amount=10) |
