diff options
| author | Max Nanis | 2026-02-25 16:20:18 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-02-25 16:20:18 -0500 |
| commit | 04aee0dc7e908ce020d2d2c3f8ffb4a96424b883 (patch) | |
| tree | efb99622da9a962a73921a945373c019f98e6273 /tests/http/test_work.py | |
| parent | 8c1940445503fd6678d0961600f2be81622793a2 (diff) | |
| download | amt-jb-04aee0dc7e908ce020d2d2c3f8ffb4a96424b883.tar.gz amt-jb-04aee0dc7e908ce020d2d2c3f8ffb4a96424b883.zip | |
test_notification (for sns mgmt), along with more type hinting on pytest conftest
Diffstat (limited to 'tests/http/test_work.py')
| -rw-r--r-- | tests/http/test_work.py | 98 |
1 files changed, 95 insertions, 3 deletions
diff --git a/tests/http/test_work.py b/tests/http/test_work.py index c69118b..66251f6 100644 --- a/tests/http/test_work.py +++ b/tests/http/test_work.py @@ -1,5 +1,9 @@ import pytest from httpx import AsyncClient +from jb.models.hit import Hit +from jb.models.assignment import AssignmentStub + +from jb.managers.assignment import AssignmentManager class TestWork: @@ -8,17 +12,105 @@ class TestWork: async def test_work( self, httpxclient: AsyncClient, - hit_record, - amt_assignment_id, - amt_worker_id, + hit_record: Hit, + amt_assignment_id: str, + amt_worker_id: str, ): client = httpxclient + assert isinstance(hit_record.id, int) + params = { "workerId": amt_worker_id, "assignmentId": amt_assignment_id, "hitId": hit_record.amt_hit_id, } res = await client.get("/work/", params=params) + assert res.status_code == 200 + + @pytest.mark.anyio + async def test_work_no_hit_record( + self, + httpxclient: AsyncClient, + hit: Hit, + amt_assignment_id: str, + amt_worker_id: str, + ): + client = httpxclient + + # Because no AssignmentStub record is created, and we're just using + # random strings as IDs, we should also confirm that the Hit record + # is not a saved record. + assert hit.id is None + + params = { + "workerId": amt_worker_id, + "assignmentId": amt_assignment_id, + "hitId": hit.amt_hit_id, + } + res = await client.get("/work/", params=params) + assert res.status_code == 500 + + @pytest.mark.anyio + async def test_work_assignment_stub_existing( + self, + httpxclient: AsyncClient, + am: AssignmentManager, + hit: Hit, + assignment_stub_record: AssignmentStub, + amt_assignment_id: str, + amt_worker_id: str, + ): + client = httpxclient + + # Because the AssignmentStub is created with a reference to the Hit, + # the Hit is actually a "Hit Record" (with a primary key), so it's + # saved in the database + assert isinstance(hit.id, int) + + # Confirm that it exists in the database before the call + res = am.get_stub_if_exists(amt_assignment_id=amt_assignment_id) + assert isinstance(res, AssignmentStub) + assert isinstance(res.id, int) + + params = { + "workerId": amt_worker_id, + "assignmentId": assignment_stub_record.amt_assignment_id, + "hitId": hit.amt_hit_id, + } + res = await client.get("/work/", params=params) + assert res.status_code == 200 + + # Confirm that it exists in the database + res = am.get_stub_if_exists(amt_assignment_id=amt_assignment_id) + assert isinstance(res, AssignmentStub) + assert isinstance(res.id, int) + + @pytest.mark.anyio + async def test_work_assignment_stub_created( + self, + httpxclient: AsyncClient, + am: AssignmentManager, + hit_record: Hit, + assignment_stub: AssignmentStub, + amt_assignment_id: str, + amt_worker_id: str, + ): + client = httpxclient + + # Confirm that it exists in the database before the call + res = am.get_stub_if_exists(amt_assignment_id=amt_assignment_id) + assert res is None + params = { + "workerId": amt_worker_id, + "assignmentId": assignment_stub.amt_assignment_id, + "hitId": hit_record.amt_hit_id, + } + res = await client.get("/work/", params=params) assert res.status_code == 200 + + # Confirm that it exists in the database + res = am.get_stub_if_exists(amt_assignment_id=amt_assignment_id) + assert isinstance(res, AssignmentStub) + assert isinstance(res.id, int) |
