Files
spoolman2/tests_integration/tests/vendor/test_add.py
Donkie f8cc9f7eda Updated integration tests to not require exact match
This matches how we want clients to behave, they should ignore any extra fields that are sent in the response.
2024-01-23 18:58:58 +01:00

66 lines
1.5 KiB
Python

"""Integration tests for the Vendor API endpoint."""
from datetime import datetime, timezone
import httpx
from ..conftest import assert_dicts_compatible
URL = "http://spoolman:8000"
def test_add_vendor():
"""Test adding a vendor to the database."""
# Execute
name = "John"
comment = "abcdefghåäö"
result = httpx.post(
f"{URL}/api/v1/vendor",
json={"name": name, "comment": comment},
)
result.raise_for_status()
# Verify
vendor = result.json()
assert_dicts_compatible(
vendor,
{
"id": vendor["id"],
"registered": vendor["registered"],
"name": name,
"comment": comment,
},
)
# Verify that registered happened almost now (within 1 minute)
diff = abs((datetime.now(tz=timezone.utc) - datetime.fromisoformat(vendor["registered"])).total_seconds())
assert diff < 60
# Clean up
httpx.delete(f"{URL}/api/v1/vendor/{vendor['id']}").raise_for_status()
def test_add_vendor_required():
"""Test adding a vendor with only the required fields to the database."""
# Execute
name = "John"
result = httpx.post(
f"{URL}/api/v1/vendor",
json={"name": name},
)
result.raise_for_status()
# Verify
vendor = result.json()
assert_dicts_compatible(
vendor,
{
"id": vendor["id"],
"registered": vendor["registered"],
"name": name,
},
)
# Clean up
httpx.delete(f"{URL}/api/v1/vendor/{vendor['id']}").raise_for_status()