Lots more Document data definition
Schedule updates: * Defined Schedule types * Updated schedule loader to validate with pydantic * Added ability to specify predecessor type and lead/lag Other structural/outline stuff as well Oh and added a unit test.
This commit is contained in:
parent
36fcb5f260
commit
373dfe4c3b
16 changed files with 535 additions and 67 deletions
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
0
tests/unit/models/__init__.py
Normal file
0
tests/unit/models/__init__.py
Normal file
53
tests/unit/models/test_document_model.py
Normal file
53
tests/unit/models/test_document_model.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
"""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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue