mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 17:18:40 +08:00
test: migrate document indexing task tests to SQLAlchemy 2.0 select API (#35145)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
173e0d6f35
commit
a951cc996b
@ -9,6 +9,7 @@ The task is responsible for removing document segments from the search index whe
|
|||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from core.rag.index_processor.constant.index_type import IndexStructureType, IndexTechniqueType
|
from core.rag.index_processor.constant.index_type import IndexStructureType, IndexTechniqueType
|
||||||
@ -471,9 +472,9 @@ class TestDisableSegmentsFromIndexTask:
|
|||||||
db_session_with_containers.refresh(segments[1])
|
db_session_with_containers.refresh(segments[1])
|
||||||
|
|
||||||
# Check that segments are re-enabled after error
|
# Check that segments are re-enabled after error
|
||||||
updated_segments = (
|
updated_segments = db_session_with_containers.scalars(
|
||||||
db_session_with_containers.query(DocumentSegment).where(DocumentSegment.id.in_(segment_ids)).all()
|
select(DocumentSegment).where(DocumentSegment.id.in_(segment_ids))
|
||||||
)
|
).all()
|
||||||
|
|
||||||
for segment in updated_segments:
|
for segment in updated_segments:
|
||||||
assert segment.enabled is True
|
assert segment.enabled is True
|
||||||
|
|||||||
@ -2,6 +2,7 @@ from unittest.mock import MagicMock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
from sqlalchemy import func, select
|
||||||
|
|
||||||
from core.rag.index_processor.constant.index_type import IndexStructureType, IndexTechniqueType
|
from core.rag.index_processor.constant.index_type import IndexStructureType, IndexTechniqueType
|
||||||
from models import Account, Tenant, TenantAccountJoin, TenantAccountRole
|
from models import Account, Tenant, TenantAccountJoin, TenantAccountRole
|
||||||
@ -123,13 +124,13 @@ class TestDocumentIndexingUpdateTask:
|
|||||||
db_session_with_containers.expire_all()
|
db_session_with_containers.expire_all()
|
||||||
|
|
||||||
# Assert document status updated before reindex
|
# Assert document status updated before reindex
|
||||||
updated = db_session_with_containers.query(Document).where(Document.id == document.id).first()
|
updated = db_session_with_containers.scalar(select(Document).where(Document.id == document.id).limit(1))
|
||||||
assert updated.indexing_status == IndexingStatus.PARSING
|
assert updated.indexing_status == IndexingStatus.PARSING
|
||||||
assert updated.processing_started_at is not None
|
assert updated.processing_started_at is not None
|
||||||
|
|
||||||
# Segments should be deleted
|
# Segments should be deleted
|
||||||
remaining = (
|
remaining = db_session_with_containers.scalar(
|
||||||
db_session_with_containers.query(DocumentSegment).where(DocumentSegment.document_id == document.id).count()
|
select(func.count()).select_from(DocumentSegment).where(DocumentSegment.document_id == document.id)
|
||||||
)
|
)
|
||||||
assert remaining == 0
|
assert remaining == 0
|
||||||
|
|
||||||
@ -167,8 +168,8 @@ class TestDocumentIndexingUpdateTask:
|
|||||||
mock_external_dependencies["runner_instance"].run.assert_called_once()
|
mock_external_dependencies["runner_instance"].run.assert_called_once()
|
||||||
|
|
||||||
# Segments should remain (since clean failed before DB delete)
|
# Segments should remain (since clean failed before DB delete)
|
||||||
remaining = (
|
remaining = db_session_with_containers.scalar(
|
||||||
db_session_with_containers.query(DocumentSegment).where(DocumentSegment.document_id == document.id).count()
|
select(func.count()).select_from(DocumentSegment).where(DocumentSegment.document_id == document.id)
|
||||||
)
|
)
|
||||||
assert remaining > 0
|
assert remaining > 0
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user