aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-backend
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2024-08-24 19:10:58 +0100
committerGravatar Chris Lovering <[email protected]>2024-08-24 19:10:58 +0100
commita64d57e5d60f283df266ed8000ce6262656a3bba (patch)
tree51d245682f557add722f18e7cf63c1b6b953addb /thallium-backend
parentRun backend tests in CI (diff)
Add voucher tests
Diffstat (limited to 'thallium-backend')
-rw-r--r--thallium-backend/requirements.txt6
-rw-r--r--thallium-backend/tests/test_login.py15
2 files changed, 17 insertions, 4 deletions
diff --git a/thallium-backend/requirements.txt b/thallium-backend/requirements.txt
index 32a9342..48963bc 100644
--- a/thallium-backend/requirements.txt
+++ b/thallium-backend/requirements.txt
@@ -87,9 +87,9 @@ httpcore==0.16.3 ; python_full_version >= "3.12.0" and python_full_version < "4.
httpx==0.23.3 ; python_full_version >= "3.12.0" and python_full_version < "4.0.0" \
--hash=sha256:9818458eb565bb54898ccb9b8b251a28785dd4a55afbc23d0eb410754fe7d0f9 \
--hash=sha256:a211fcce9b1254ea24f0cd6af9869b3d29aba40154e947d2a07bb499b3e310d6
-idna==3.7 ; python_full_version >= "3.12.0" and python_full_version < "4.0.0" \
- --hash=sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc \
- --hash=sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0
+idna==3.8 ; python_full_version >= "3.12.0" and python_full_version < "4.0.0" \
+ --hash=sha256:050b4e5baadcd44d760cedbd2b8e639f2ff89bbc7a5730fcc662954303377aac \
+ --hash=sha256:d838c2c0ed6fced7693d5e8ab8e734d5f8fda53a039c0164afb0b82e771e3603
jinja2==3.1.4 ; python_full_version >= "3.12.0" and python_full_version < "4.0.0" \
--hash=sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369 \
--hash=sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d
diff --git a/thallium-backend/tests/test_login.py b/thallium-backend/tests/test_login.py
index c742d01..b8e7bde 100644
--- a/thallium-backend/tests/test_login.py
+++ b/thallium-backend/tests/test_login.py
@@ -2,13 +2,18 @@ from http import HTTPStatus
import pytest
from httpx import AsyncClient
+from pytest_subtests import SubTests
from sqlalchemy.ext.asyncio import AsyncSession
from src.orm import Voucher
@pytest.mark.asyncio()
-async def test_successful_voucher_login(http_client: AsyncClient, db_session: AsyncSession) -> None:
+async def test_successful_voucher_login(
+ http_client: AsyncClient,
+ db_session: AsyncSession,
+ subtests: SubTests,
+) -> None:
"""Test that a valid voucher can login to the system and receive a JWT."""
db_session.add(Voucher(voucher_code="k1p", balance="13.37"))
await db_session.flush()
@@ -17,3 +22,11 @@ async def test_successful_voucher_login(http_client: AsyncClient, db_session: As
resp_data: dict[str, str] = resp.json()
assert resp.status_code == HTTPStatus.OK
assert {"voucher_code", "jwt"} <= resp_data.keys()
+ jwt = resp_data["jwt"]
+
+ with subtests.test(msg="Test a valid voucher JWT can request own voucher info", jwt=jwt):
+ resp = await http_client.get("/vouchers/me", headers={"Authorization": f"Bearer {jwt}"})
+
+ assert resp.status_code == HTTPStatus.OK
+ resp_data: dict[str, str] = resp.json()
+ assert {"id", "created_at", "updated_at", "voucher_code", "balance", "active"} <= resp_data.keys()