aboutsummaryrefslogtreecommitdiffstats
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
parentRun backend tests in CI (diff)
Add voucher tests
-rw-r--r--poetry.lock64
-rw-r--r--pyproject.toml2
-rw-r--r--thallium-backend/requirements.txt6
-rw-r--r--thallium-backend/tests/test_login.py15
4 files changed, 50 insertions, 37 deletions
diff --git a/poetry.lock b/poetry.lock
index c06bc81..9ec409f 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -51,6 +51,25 @@ test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypo
trio = ["trio (>=0.23)"]
[[package]]
+name = "attrs"
+version = "24.2.0"
+description = "Classes Without Boilerplate"
+optional = false
+python-versions = ">=3.7"
+files = [
+ {file = "attrs-24.2.0-py3-none-any.whl", hash = "sha256:81921eb96de3191c8258c199618104dd27ac608d9366f5e35d011eae1867ede2"},
+ {file = "attrs-24.2.0.tar.gz", hash = "sha256:5cfb1b9148b5b086569baec03f20d7b6bf3bcacc9a42bebf87ffaaca362f6346"},
+]
+
+[package.extras]
+benchmark = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-codspeed", "pytest-mypy-plugins", "pytest-xdist[psutil]"]
+cov = ["cloudpickle", "coverage[toml] (>=5.3)", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"]
+dev = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"]
+docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier (<24.7)"]
+tests = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"]
+tests-mypy = ["mypy (>=1.11.1)", "pytest-mypy-plugins"]
+
+[[package]]
name = "build"
version = "1.2.1"
description = "A simple, correct Python build frontend"
@@ -493,20 +512,6 @@ paramiko = ["paramiko"]
pgp = ["gpg"]
[[package]]
-name = "execnet"
-version = "2.1.1"
-description = "execnet: rapid multi-Python deployment"
-optional = false
-python-versions = ">=3.8"
-files = [
- {file = "execnet-2.1.1-py3-none-any.whl", hash = "sha256:26dee51f1b80cebd6d0ca8e74dd8745419761d3bef34163928cbebbdc4749fdc"},
- {file = "execnet-2.1.1.tar.gz", hash = "sha256:5189b52c6121c24feae288166ab41b32549c7e2348652736540b9e6e7d4e72e3"},
-]
-
-[package.extras]
-testing = ["hatch", "pre-commit", "pytest", "tox"]
-
-[[package]]
name = "fastapi"
version = "0.112.1"
description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production"
@@ -698,13 +703,13 @@ license = ["ukkonen"]
[[package]]
name = "idna"
-version = "3.7"
+version = "3.8"
description = "Internationalized Domain Names in Applications (IDNA)"
optional = false
-python-versions = ">=3.5"
+python-versions = ">=3.6"
files = [
- {file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"},
- {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"},
+ {file = "idna-3.8-py3-none-any.whl", hash = "sha256:050b4e5baadcd44d760cedbd2b8e639f2ff89bbc7a5730fcc662954303377aac"},
+ {file = "idna-3.8.tar.gz", hash = "sha256:d838c2c0ed6fced7693d5e8ab8e734d5f8fda53a039c0164afb0b82e771e3603"},
]
[[package]]
@@ -1443,24 +1448,19 @@ docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"]
testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"]
[[package]]
-name = "pytest-xdist"
-version = "3.6.1"
-description = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs"
+name = "pytest-subtests"
+version = "0.13.1"
+description = "unittest subTest() support and subtests fixture"
optional = false
-python-versions = ">=3.8"
+python-versions = ">=3.7"
files = [
- {file = "pytest_xdist-3.6.1-py3-none-any.whl", hash = "sha256:9ed4adfb68a016610848639bb7e02c9352d5d9f03d04809919e2dafc3be4cca7"},
- {file = "pytest_xdist-3.6.1.tar.gz", hash = "sha256:ead156a4db231eec769737f57668ef58a2084a34b2e55c4a8fa20d861107300d"},
+ {file = "pytest_subtests-0.13.1-py3-none-any.whl", hash = "sha256:ab616a22f64cd17c1aee65f18af94dbc30c444f8683de2b30895c3778265e3bd"},
+ {file = "pytest_subtests-0.13.1.tar.gz", hash = "sha256:989e38f0f1c01bc7c6b2e04db7d9fd859db35d77c2c1a430c831a70cbf3fde2d"},
]
[package.dependencies]
-execnet = ">=2.1"
-pytest = ">=7.0.0"
-
-[package.extras]
-psutil = ["psutil (>=3.0)"]
-setproctitle = ["setproctitle"]
-testing = ["filelock"]
+attrs = ">=19.2.0"
+pytest = ">=7.0"
[[package]]
name = "python-dotenv"
@@ -2075,4 +2075,4 @@ test = ["pytest"]
[metadata]
lock-version = "2.0"
python-versions = "^3.12.0"
-content-hash = "06293ac0e3c0214477061a6e64bda9613ff2191f639a7dbf350acd57485dcd1c"
+content-hash = "ff0efc0bc637076e8e66281e7de20b5ce785a9ad02f6ae7f9685c7a43a75576d"
diff --git a/pyproject.toml b/pyproject.toml
index df50e47..409bafb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -31,7 +31,7 @@ poetry-plugin-export = "*"
[tool.poetry.group.test.dependencies]
pytest = "^8.3.2"
pytest-asyncio = "^0.23.8"
-pytest-xdist = "^3.6.1"
+pytest-subtests = "^0.13.1"
[build-system]
requires = ["poetry-core>=1.5.0"]
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()