File size: 1,314 Bytes
c4e128a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Unit tests for Pydantic models and CorpusRecord."""

import pytest
from pydantic import ValidationError

from app.models.corpus import CorpusRecord
from app.models.document import Category, DocumentMeta, Language


def test_document_meta_valid(sample_meta: DocumentMeta) -> None:
    assert sample_meta.filename == "test.pdf"
    assert sample_meta.language == Language.mixed
    assert sample_meta.category == Category.research_paper
    assert sample_meta.pages == 2
    assert sample_meta.file_size_bytes == 2048


def test_document_meta_invalid_filename() -> None:
    with pytest.raises(ValidationError):
        DocumentMeta(
            filename="test.docx",
            language=Language.en,
            category=Category.other,
            pages=1,
            file_size_bytes=100,
        )


def test_document_meta_invalid_sha256() -> None:
    with pytest.raises(ValidationError):
        DocumentMeta(
            filename="test.pdf",
            language=Language.en,
            category=Category.other,
            pages=1,
            file_size_bytes=100,
            sha256="invalid_short_hash",
        )


def test_corpus_record_polars_schema() -> None:
    schema = CorpusRecord.polars_schema()
    assert "id" in schema
    assert "sha256" in schema
    assert "file_size_bytes" in schema