diff options
| author | Max Nanis | 2026-02-21 02:15:52 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-02-21 02:15:52 -0500 |
| commit | 67ab724561e4ceb8fe8fb4031de277168f7d9724 (patch) | |
| tree | 4d85619973491e7239f0e83dc5cdd85618f0f248 /tests/http/test_statuses.py | |
| parent | af8057d58ff152f511f5161a7626b0fffa9d661a (diff) | |
| download | amt-jb-67ab724561e4ceb8fe8fb4031de277168f7d9724.tar.gz amt-jb-67ab724561e4ceb8fe8fb4031de277168f7d9724.zip | |
More pytest conf, some views, and defining more attrs on the settings config
Diffstat (limited to 'tests/http/test_statuses.py')
| -rw-r--r-- | tests/http/test_statuses.py | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/http/test_statuses.py b/tests/http/test_statuses.py new file mode 100644 index 0000000..ffc98fd --- /dev/null +++ b/tests/http/test_statuses.py @@ -0,0 +1,102 @@ +from datetime import datetime, timezone, timedelta +from urllib.parse import urlencode + +import pytest +from uuid import uuid4 +from httpx import AsyncClient + +from jb.config import settings + + +@pytest.mark.anyio +async def test_get_statuses(httpxclient: AsyncClient, no_limit, amt_worker_id): + # Expects settings.fsb_host to point to a functional thl-fsb + client = httpxclient + now = datetime.now(tz=timezone.utc) + + params = {"worker_id": amt_worker_id} + res = await client.get(f"/statuses/", params=params) + assert res.status_code == 200 + assert res.json() == [] + + params = {"worker_id": amt_worker_id, "started_after": now.isoformat()} + res = await client.get(f"/statuses/", params=params) + assert res.status_code == 422 + assert "Input should be a valid integer" in res.text + + +@pytest.fixture +def fsb_get_statuses_example_response(amt_worker_id, tsid1, tsid2): + return { + "tasks_status": [ + { + "tsid": tsid1, + "product_id": settings.product_id, + "bpuid": amt_worker_id, + "started": "2025-06-12T03:27:24.902280Z", + "finished": "2025-06-12T03:29:37.626481Z", + "status": 2, + "payout": 0, + "user_payout": None, + "payout_format": None, + "user_payout_string": None, + "kwargs": {}, + "status_code_1": "SESSION_START_QUALITY_FAIL", + "status_code_2": "ENTRY_URL_MODIFICATION", + }, + { + "tsid": tsid2, + "product_id": settings.product_id, + "bpuid": amt_worker_id, + "started": "2025-06-12T03:30:18.176826Z", + "finished": "2025-06-12T03:36:58.789059Z", + "status": 2, + "payout": 0, + "user_payout": None, + "payout_format": None, + "user_payout_string": None, + "kwargs": {}, + "status_code_1": "BUYER_QUALITY_FAIL", + "status_code_2": None, + }, + ] + } + + +@pytest.mark.anyio +async def test_get_statuses_mock( + httpxclient: AsyncClient, + no_limit, + amt_worker_id, + mock_requests, + fsb_get_statuses_example_response, + tsid1, + tsid2, +): + client = httpxclient + now = datetime.now(tz=timezone.utc) + started_after = now - timedelta(minutes=5) + + # The fsb call we are mocking ------v + params = { + "bpuid": amt_worker_id, + "started_after": round(started_after.timestamp()), + "started_before": round(now.timestamp()), + } + url = f"{settings.fsb_host}{settings.product_id}/status/" + "?" + urlencode(params) + mock_requests.get(url, json=fsb_get_statuses_example_response, status_code=200) + # ---- end mock + + params = { + "worker_id": amt_worker_id, + "started_after": round(started_after.timestamp()), + "started_before": round(now.timestamp()), + } + result = await client.get(f"/statuses/", params=params) + assert result.status_code == 200 + res = result.json() + assert len(res) == 2 + assert res == [ + {"status": 2, "tsid": tsid1}, + {"status": 2, "tsid": tsid2}, + ] |
