mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
27 lines
714 B
Python
27 lines
714 B
Python
|
|
import pytest
|
||
|
|
|
||
|
|
from modules.docs.models import Doc
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def doc_factory(test_session, test_directory):
|
||
|
|
"""Factory for creating Doc records for testing."""
|
||
|
|
count = 0
|
||
|
|
|
||
|
|
def factory(file_group=None, **kwargs):
|
||
|
|
nonlocal count
|
||
|
|
count += 1
|
||
|
|
if file_group is None:
|
||
|
|
from wrolpi.files.models import FileGroup
|
||
|
|
path = test_directory / f'test_doc_{count}.pdf'
|
||
|
|
path.write_bytes(b'%PDF-1.4 test')
|
||
|
|
file_group = FileGroup.from_paths(test_session, path)
|
||
|
|
test_session.flush()
|
||
|
|
|
||
|
|
doc = Doc(file_group=file_group, **kwargs)
|
||
|
|
test_session.add(doc)
|
||
|
|
test_session.flush()
|
||
|
|
return doc
|
||
|
|
|
||
|
|
return factory
|