54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
|
|
"""Tests for Document model."""
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
from pydantic import ValidationError
|
||
|
|
|
||
|
|
from nrsk.models import Document
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def valid_document_data(): # noqa: D103
|
||
|
|
return {
|
||
|
|
"uuid": "2deac04a-d1d1-4e42-b1a7-cc941d9da9b5",
|
||
|
|
"title": "Project Proposal Q4",
|
||
|
|
"revision": "2",
|
||
|
|
"type": "CALC",
|
||
|
|
"originators": ["jane@example.com"],
|
||
|
|
"review_status": "IN REVIEW",
|
||
|
|
"status": "RESERVED",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def test_document_model_success(valid_document_data):
|
||
|
|
"""Test that valid input data correctly creates a Document instance."""
|
||
|
|
doc = Document(**valid_document_data)
|
||
|
|
|
||
|
|
assert isinstance(doc, Document)
|
||
|
|
assert doc.title == "Project Proposal Q4"
|
||
|
|
assert doc.status == Document.STATUS.RESERVED
|
||
|
|
assert doc.status.value == "RESERVED"
|
||
|
|
assert doc.status_category == "Not Yet Approved"
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize(
|
||
|
|
"invalid_status",
|
||
|
|
[
|
||
|
|
"Reserved", # Capitalized (case sensitive)
|
||
|
|
"re-served", # Hyphenated (typo)
|
||
|
|
"finalized", # Non-existent status
|
||
|
|
123, # Wrong type (integer)
|
||
|
|
],
|
||
|
|
)
|
||
|
|
def test_document_status_invalid_enum(valid_document_data, invalid_status):
|
||
|
|
"""Tests that the model raises ValidationError for invalid status strings."""
|
||
|
|
data = valid_document_data.copy()
|
||
|
|
data["status"] = invalid_status
|
||
|
|
|
||
|
|
with pytest.raises(ValidationError) as excinfo:
|
||
|
|
Document(**data)
|
||
|
|
|
||
|
|
assert any("status" in err["loc"] for err in excinfo.value.errors())
|
||
|
|
assert "Input should be " in str(excinfo.value)
|