diff options
| author | Max Nanis | 2026-02-26 20:29:41 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-02-26 20:29:41 -0500 |
| commit | af66829e26cb05f182bef36ac06d58c7baa0ec1e (patch) | |
| tree | 2848a9223e7d4d680f3e93fc8dfcc7545f716abd /tests/managers | |
| parent | 0bf32fadd85d5938ae29d489efdd82e2cd137300 (diff) | |
| download | amt-jb-af66829e26cb05f182bef36ac06d58c7baa0ec1e.tar.gz amt-jb-af66829e26cb05f182bef36ac06d58c7baa0ec1e.zip | |
AMTManager moved to fixture, and dectorator with parameters on tasks and init / non-static class appraoch. More assertion checks and typing. TestMTurkClient seperated from TestAMTManger
Diffstat (limited to 'tests/managers')
| -rw-r--r-- | tests/managers/test_amt.py | 84 | ||||
| -rw-r--r-- | tests/managers/test_hit.py | 14 |
2 files changed, 81 insertions, 17 deletions
diff --git a/tests/managers/test_amt.py b/tests/managers/test_amt.py index 63d3737..372cb07 100644 --- a/tests/managers/test_amt.py +++ b/tests/managers/test_amt.py @@ -2,35 +2,101 @@ from jb.managers.amt import AMTManager from jb.models.hit import HitType, HitQuestion from jb.managers.hit import HitQuestionManager, HitTypeManager, HitManager +from mypy_boto3_mturk import MTurkClient +from mypy_boto3_mturk.type_defs import ( + GetAssignmentResponseTypeDef, + GetAccountBalanceResponseTypeDef, + ListHITsResponseTypeDef, +) + + +class TestMTurkClient: + + def test_sandbox(self, amt_client: MTurkClient): + assert amt_client is not None + assert "mturk-requester-sandbox" in amt_client.meta.endpoint_url + + balance: GetAccountBalanceResponseTypeDef = amt_client.get_account_balance() + assert balance["AvailableBalance"] == "10000.00" + + # def test_create_hit() + + # def test_delete_hit() + + # def test_get_assignment(self, amt_client: MTurkClient): + + # def test_get_hit + + def test_list_hits(self, amt_client: MTurkClient, amtm: AMTManager): + res: ListHITsResponseTypeDef = amt_client.list_hits() + assert isinstance(res, dict) + assert isinstance(res.get("HITs"), list) + + for hit in res["HITs"]: + assert isinstance(hit, dict) + + assert isinstance(hit.get("HITId"), str) + assert isinstance(hit.get("HITTypeId"), str) + assert isinstance(hit.get("HITGroupId"), str) + assert isinstance(hit.get("Title"), str) + + # botocore.errorfactory.RequestError: An error occurred + # (RequestError) when calling the DeleteHIT operation: This + # HIT is currently in the state 'Assignable'. This operation + # can be called with a status of: Reviewing, Reviewable + # (1772146028380 s) + + if hit["HITStatus"] in ["Reviewing", "Reviewable"]: + print( + f"Deleting HIT with id {hit['HITId']} and status {hit['HITStatus']}" + ) + amt_client.delete_hit(HITId=hit["HITId"]) + + elif hit["HITStatus"] == "Assignable": + # I don't know... just let expire I guess. To changes it's + # status you need to do manage Assignments (I think) + + # amt_client.update_hit_review_status(HITId=hit["HITId"], Revert=True) + pass + + amtm.expire_all_hits() class TestAMTManager: - def test_create_hit_type(self, hit_type: HitType): + def test_create_hit_type(self, amtm: AMTManager, hit_type: HitType): assert hit_type.amt_hit_type_id is None - AMTManager.create_hit_type(hit_type=hit_type) + + amtm.create_hit_type(hit_type=hit_type) assert hit_type.amt_hit_type_id is not None def test_create_hit_with_hit_type( self, - hqm: HitQuestionManager, + amtm: AMTManager, htm: HitTypeManager, hm: HitManager, hit_type_record_with_amt_id: HitType, question_record: HitQuestion, ): - hit_type = hit_type_record_with_amt_id - hit_type = [ + sandbox_amt_hit_type_id = hit_type_record_with_amt_id.amt_hit_type_id + assert isinstance(sandbox_amt_hit_type_id, str) + + res = [ x for x in htm.filter_active() - if x.amt_hit_type_id == hit_type.amt_hit_type_id - ][0] + if x.amt_hit_type_id == sandbox_amt_hit_type_id + ] + + assert len(res) == 1 + sandbox_hit_type = res[0] - hit = AMTManager.create_hit_with_hit_type( - hit_type=hit_type, question=question_record + hit = amtm.create_hit_with_hit_type( + hit_type=sandbox_hit_type, question=question_record ) + assert hit.amt_hit_id is not None assert hit.id is None + hm.create(hit) assert hit.id is not None diff --git a/tests/managers/test_hit.py b/tests/managers/test_hit.py index 56a4f53..974bd18 100644 --- a/tests/managers/test_hit.py +++ b/tests/managers/test_hit.py @@ -11,21 +11,19 @@ class TestHitQuestionManager: class TestHitTypeManager: - def test_create(self, htm: HitTypeManager, hit_type_record_with_amt_id: HitType): + def test_create(self, htm: HitTypeManager, hit_type_record: HitType): - _ = hit_type_record_with_amt_id - - assert isinstance(hit_type_record_with_amt_id.id, int) - assert isinstance(hit_type_record_with_amt_id.amt_hit_type_id, str) + assert isinstance(hit_type_record.id, int) + assert isinstance(hit_type_record.amt_hit_type_id, str) count1 = len(htm.filter_active()) # assert count1 == 1 - hit_type_record_with_amt_id.min_active = 0 - htm.set_min_active(hit_type=hit_type_record_with_amt_id) + hit_type_record.min_active = 0 + htm.set_min_active(hit_type=hit_type_record) count2 = len(htm.filter_active()) - assert count2 == 0 + assert count1 - 1 == count2 class TestHitManager: |
