45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
"""Tests for the versioned parsed-document artifact codec."""
|
|
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
from ekp_core.parsed_document_artifact import (
|
|
ParsedDocumentArtifactError,
|
|
deserialize_parsed_document,
|
|
serialize_parsed_document,
|
|
)
|
|
from ekp_domain import ParsedBlock, ParsedBlockType, ParsedDocument
|
|
|
|
|
|
def test_parsed_document_artifact_round_trip() -> None:
|
|
document = ParsedDocument(
|
|
document_id=uuid4(),
|
|
filename="制度.md",
|
|
blocks=(
|
|
ParsedBlock(
|
|
"退款规则",
|
|
ParsedBlockType.PARAGRAPH,
|
|
page_number=2,
|
|
section_path=("售后",),
|
|
),
|
|
),
|
|
)
|
|
|
|
restored = deserialize_parsed_document(serialize_parsed_document(document))
|
|
|
|
assert restored == document
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"payload",
|
|
[
|
|
b"not-json",
|
|
b'{"schema_version":2}',
|
|
b'{"schema_version":1,"document_id":"bad","filename":"x","blocks":[]}',
|
|
],
|
|
)
|
|
def test_parsed_document_artifact_rejects_invalid_payload(payload: bytes) -> None:
|
|
with pytest.raises(ParsedDocumentArtifactError):
|
|
deserialize_parsed_document(payload)
|