Start of integration tests

This commit is contained in:
Donkie
2023-05-18 14:38:28 +02:00
parent d3703d0d92
commit c6ee7df535
8 changed files with 133 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
"""Integration tests for the API."""
import httpx
URL = "http://spoolman:8000"
def test_add_vendor():
"""Test adding a vendor to the database."""
name = "John"
comment = "abcdefghåäö"
result = httpx.post(
f"{URL}/api/v1/vendor",
json={"name": name, "comment": comment},
)
result.raise_for_status()
vendor = result.json()
assert vendor["name"] == name
assert vendor["comment"] == comment
assert vendor["id"] is not None
assert vendor["registered"] is not None
def test_get_vendor():
"""Test getting a vendor from the database."""
name = "John"
comment = "abcdefghåäö"
result = httpx.post(
f"{URL}/api/v1/vendor",
json={"name": name, "comment": comment},
)
result.raise_for_status()
added_vendor = result.json()
result = httpx.get(
f"{URL}/api/v1/vendor/{added_vendor['id']}",
)
result.raise_for_status()
vendor = result.json()
assert vendor["name"] == name
assert vendor["comment"] == comment
assert vendor["id"] == added_vendor["id"]
assert vendor["registered"] == added_vendor["registered"]