36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from app.model.models import AccessAuthorizationCreate, UserUpdate
|
|
|
|
|
|
def test_user_update_fields_are_optional():
|
|
"""Partial update models must leave unspecified fields as None."""
|
|
user_update = UserUpdate(name="Updated Name")
|
|
assert user_update.name == "Updated Name"
|
|
assert user_update.email is None
|
|
|
|
|
|
def test_access_authorization_type_is_validated():
|
|
"""AA validation test"""
|
|
base = {"name": "AA", "is_active": True}
|
|
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
AccessAuthorizationCreate(type="timetable", **base)
|
|
assert exc_info.value.errors()[0]["type"] == "literal_error"
|
|
|
|
# A oneshot type without its oneshot payload is incomplete.
|
|
with pytest.raises(ValueError, match="require a oneshot object"):
|
|
AccessAuthorizationCreate(type="oneshot", **base)
|
|
|
|
with pytest.raises(ValueError, match="not jet implemented"):
|
|
AccessAuthorizationCreate(type="somefuturespec", **base)
|
|
|
|
valid = AccessAuthorizationCreate(
|
|
type="oneshot",
|
|
name="AA",
|
|
is_active=True,
|
|
oneshot={"uses": 1, "ends_at": "2029-07-27"},
|
|
)
|
|
assert valid.type == "oneshot"
|