test: services router
This commit is contained in:
parent
c4b4000d62
commit
b8b6e6c7ee
1 changed files with 90 additions and 0 deletions
90
test/test_service.py
Normal file
90
test/test_service.py
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
"""
|
||||||
|
409 on [POST]/service/ not tested because SQLite throws a different error than Postgres
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
from httpx import AsyncClient
|
||||||
|
|
||||||
|
from .conftest import client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_get_services_success(client: AsyncClient):
|
||||||
|
resp = await client.get("/service/?org_id=1")
|
||||||
|
data = resp.json()
|
||||||
|
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert "services" in data
|
||||||
|
assert data["services"][0]["id"] == 1
|
||||||
|
assert data["services"][0]["name"] == "Test Service"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"query, expected_status",
|
||||||
|
[
|
||||||
|
("org_id=2", 404),
|
||||||
|
("org_id=banana", 422),
|
||||||
|
("", 422),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_get_services_failure(client: AsyncClient, query: str, expected_status: int):
|
||||||
|
resp = await client.get(f"/service/?{query}")
|
||||||
|
|
||||||
|
assert resp.status_code == expected_status
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_post_service_success(client: AsyncClient):
|
||||||
|
resp = await client.post("/service/", json={"name": "New Test Service"})
|
||||||
|
data = resp.json()
|
||||||
|
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert "service" in data
|
||||||
|
assert data["service"]["name"] == "New Test Service"
|
||||||
|
assert data["service"]["id"] == 2
|
||||||
|
assert type(data["service"]["api_key"]) == str
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"body, expected_status",
|
||||||
|
[
|
||||||
|
({"name": 42}, 422),
|
||||||
|
({}, 422),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_post_services_failure(client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||||
|
resp = await client.post("/service/", json=body)
|
||||||
|
|
||||||
|
assert resp.status_code == expected_status
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_patch_service_success(client: AsyncClient):
|
||||||
|
resp = await client.patch("/service/key", json={"service_id": 1})
|
||||||
|
data = resp.json()
|
||||||
|
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert "service" in data
|
||||||
|
assert data["service"]["name"] == "Test Service"
|
||||||
|
assert data["service"]["id"] == 1
|
||||||
|
assert type(data["service"]["api_key"]) == str
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"body, expected_status",
|
||||||
|
[
|
||||||
|
({"service_id": 42}, 404),
|
||||||
|
({"service_id": "Test Service"}, 422),
|
||||||
|
({"service_id": ""}, 422),
|
||||||
|
({}, 422),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_patch_services_failure(client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||||
|
resp = await client.patch("/service/key", json=body)
|
||||||
|
|
||||||
|
assert resp.status_code == expected_status
|
||||||
Loading…
Add table
Add a link
Reference in a new issue