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_status.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_status.py')
| -rw-r--r-- | tests/http/test_status.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/http/test_status.py b/tests/http/test_status.py new file mode 100644 index 0000000..d88ff65 --- /dev/null +++ b/tests/http/test_status.py @@ -0,0 +1,78 @@ +from uuid import uuid4 + +import pytest +from httpx import AsyncClient + +from jb.config import settings +from tests import generate_amt_id + + +@pytest.mark.anyio +async def test_get_status_args(httpxclient: AsyncClient, no_limit): + client = httpxclient + + # tsid misformatted + res = await client.get(f"/status/{uuid4().hex[:-1]}/") + assert res.status_code == 422 + assert "String should have at least 32 characters" in res.text + + +@pytest.mark.anyio +async def test_get_status_error(httpxclient: AsyncClient, no_limit): + # Expects settings.fsb_host to point to a functional thl-fsb + client = httpxclient + + # tsid doesn't exist + res = await client.get(f"/status/{uuid4().hex}/") + assert res.status_code == 502 + assert res.json()["detail"] == "Failed to fetch status" + + +@pytest.mark.anyio +async def test_get_status_complete(httpxclient: AsyncClient, no_limit, mock_requests): + client = httpxclient + + tsid = uuid4().hex + url = f"{settings.fsb_host}{settings.product_id}/status/{tsid}/" + + mock_response = { + "tsid": tsid, + "product_id": settings.product_id, + "bpuid": generate_amt_id(length=21), + "started": "2022-06-29T23:43:48.247777Z", + "finished": "2022-06-29T23:56:57.632634Z", + "status": 3, + "payout": 81, + "user_payout": 77, + "payout_format": "${payout/100:.2f}", + "user_payout_string": "$0.77", + "kwargs": {}, + } + mock_requests.get(url, json=mock_response, status_code=200) + res = await client.get(f"/status/{tsid}/") + assert res.status_code == 200 + assert res.json() == {"status": 3, "payout": "$0.77"} + + +@pytest.mark.anyio +async def test_get_status_failure(httpxclient: AsyncClient, no_limit, mock_requests): + client = httpxclient + + tsid = uuid4().hex + url = f"{settings.fsb_host}{settings.product_id}/status/{tsid}/" + + mock_response = { + "tsid": tsid, + "product_id": settings.product_id, + "bpuid": "123ABC", + "status": 2, + "payout": 0, + "user_payout": 0, + "payout_format": "${payout/100:.2f}", + "user_payout_string": None, + "kwargs": {}, + } + mock_requests.get(url, json=mock_response, status_code=200) + res = await client.get(f"/status/{tsid}/") + assert res.status_code == 200 + assert res.json() == {"status": 2, "payout": None} |
