aboutsummaryrefslogtreecommitdiff
path: root/tests/http/test_status.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/http/test_status.py')
-rw-r--r--tests/http/test_status.py78
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}