Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions papermerge/core/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
get_document_types,
get_document_type,
get_document_types_without_pagination,
get_document_types_grouped_by_owner_without_pagination,
get_document_types_by_owner_without_pagination,
delete_document_type,
update_document_type,
document_type_cf_count
Expand Down Expand Up @@ -95,7 +95,7 @@
"get_document_types",
"get_document_type",
"get_document_types_without_pagination",
"get_document_types_grouped_by_owner_without_pagination",
"get_document_types_by_owner_without_pagination",
"delete_document_type",
"update_document_type",
"document_type_cf_count",
Expand Down
91 changes: 57 additions & 34 deletions papermerge/core/features/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

from core.utils.tz import utc_now
from papermerge.core import schema
from papermerge.core.utils.tz import utc_now
from papermerge.core.tests.resource_file import ResourceFile
from papermerge.core.types import OCRStatusEnum
from papermerge.core.features.auth.scopes import SCOPES
Expand Down Expand Up @@ -550,16 +551,38 @@ async def document_type_groceries(db_session: AsyncSession, user, make_custom_fi
@pytest.fixture
def make_document_type_without_cf(db_session: AsyncSession, user, make_custom_field):
async def _make_document_type(name: str):
create_data = schema.CreateDocumentType(
name=name,
custom_field_ids=[],
owner_type=OwnerType.USER,
owner_id=user.id
)
return await dbapi.create_document_type(
db_session,
name=name,
custom_field_ids=[], # no custom fields
user_id=user.id,
data=create_data
)

return _make_document_type


@pytest.fixture
async def document_type_zdf(db_session: AsyncSession, user, make_custom_field_v2):
cf1 = await make_custom_field_v2(name="Start Date", type_handler=CustomFieldType.date)
cf2 = await make_custom_field_v2(name="End Date", type_handler=CustomFieldType.date)
cf3 = await make_custom_field_v2(name="Total Due", type_handler=CustomFieldType.monetary)

create_data = schema.CreateDocumentType(
name="ZDF",
custom_field_ids=[cf1.id, cf2.id, cf3.id],
owner_type=OwnerType.USER,
owner_id=user.id
)

return await dbapi.create_document_type(
db_session,
data=create_data
)


@pytest.fixture
def make_document_zdf(db_session: AsyncSession, document_type_zdf):
Expand Down Expand Up @@ -685,31 +708,30 @@ def make_document_type(db_session, user):
UPDATED: Create document type with ownership
"""
async def _maker(
name: str,
custom_fields: list = None,
user: orm.User | None = None,
group_id: UUID | None = None
name: str,
custom_fields: list = None,
path_template: str | None = None,
user: orm.User | None = None,
group_id: UUID | None = None
):
if custom_fields is None:
custom_fields = []

# Determine owner
if group_id:
owner_type = OwnerType.GROUP
owner_id = group_id
else:
owner_type = OwnerType.USER
owner_id = user.id if user else user.id

# Create document type WITHOUT user_id/group_id
dt = orm.DocumentType(
id=uuid.uuid4(),
path_template=path_template,
name=name
)
db_session.add(dt)
await db_session.flush()

# Set ownership
await ownership_api.set_owner(
session=db_session,
resource_type=ResourceType.DOCUMENT_TYPE,
Expand All @@ -736,24 +758,46 @@ async def _maker(

@pytest.fixture
def make_document_receipt(db_session: AsyncSession, document_type_groceries):
async def _make_receipt(title: str, user: orm.User, parent=None):
async def _make_receipt(
title: str,
user: orm.User,
parent=None,
group_id: UUID | None = None
):
if parent is None:
parent_id = user.home_folder_id
else:
parent_id = parent.id

# Determine owner
if group_id:
owner_type = OwnerType.GROUP
owner_id = group_id
else:
owner_type = OwnerType.USER
owner_id = user.id if user else user.id

doc_id = uuid.uuid4()
doc = orm.Document(
id=doc_id,
ctype="document",
title=title,
user=user,
document_type_id=document_type_groceries.id,
parent_id=parent_id,
lang="deu",
)

db_session.add(doc)
await db_session.flush()

# Set ownership
await ownership_api.set_owner(
session=db_session,
resource_type=ResourceType.NODE,
resource_id=doc.id,
owner_type=owner_type,
owner_id=owner_id
)

await db_session.commit()

Expand Down Expand Up @@ -898,27 +942,6 @@ def _generator():
return _generator


@pytest.fixture
def make_document_zdf(db_session: AsyncSession, document_type_zdf):
async def _make_receipt(title: str, user: orm.User):
doc = orm.Document(
id=uuid.uuid4(),
ctype="document",
title=title,
user=user,
document_type_id=document_type_zdf.id,
parent_id=user.home_folder_id,
)

db_session.add(doc)

await db_session.commit()

return doc

return _make_receipt


@pytest.fixture
def make_custom_field_v2(db_session: AsyncSession, user):
"""
Expand Down
Loading
Loading