Files
spoolman2/tests_integration/tests/vendor/test_add.py
Donkie 9595aec675 Fixed registered field having wrong timezone
This happened with at least Postgres, which took it's server's timezone. It's complicated. Let's just set it from our side instead where we have some control.
2023-10-02 21:36:50 +02:00

58 lines
1.4 KiB
Python

"""Integration tests for the Vendor API endpoint."""
from datetime import datetime, timezone
import httpx
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 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 vendor == {
"id": vendor["id"],
"registered": vendor["registered"],
"name": name,
}
# Clean up
httpx.delete(f"{URL}/api/v1/vendor/{vendor['id']}").raise_for_status()