mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
test: migrate restore archived workflow run tests to testcontainers (#34083)
This commit is contained in:
parent
59639ca9b2
commit
b7b9b003c9
@ -2,17 +2,43 @@
|
|||||||
Testcontainers integration tests for workflow run restore functionality.
|
Testcontainers integration tests for workflow run restore functionality.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
||||||
from models.workflow import WorkflowPause
|
from models.workflow import WorkflowPause, WorkflowRun
|
||||||
from services.retention.workflow_run.restore_archived_workflow_run import WorkflowRunRestore
|
from services.retention.workflow_run.restore_archived_workflow_run import WorkflowRunRestore
|
||||||
|
|
||||||
|
|
||||||
class TestWorkflowRunRestore:
|
class TestWorkflowRunRestore:
|
||||||
"""Tests for the WorkflowRunRestore class."""
|
"""Tests for the WorkflowRunRestore class."""
|
||||||
|
|
||||||
|
def test_restore_initialization(self):
|
||||||
|
"""Restore service should respect dry_run flag."""
|
||||||
|
restore = WorkflowRunRestore(dry_run=True)
|
||||||
|
|
||||||
|
assert restore.dry_run is True
|
||||||
|
|
||||||
|
def test_convert_datetime_fields(self):
|
||||||
|
"""ISO datetime strings should be converted to datetime objects."""
|
||||||
|
record = {
|
||||||
|
"id": "test-id",
|
||||||
|
"created_at": "2024-01-01T12:00:00",
|
||||||
|
"finished_at": "2024-01-01T12:05:00",
|
||||||
|
"name": "test",
|
||||||
|
}
|
||||||
|
|
||||||
|
restore = WorkflowRunRestore()
|
||||||
|
result = restore._convert_datetime_fields(record, WorkflowRun)
|
||||||
|
|
||||||
|
assert isinstance(result["created_at"], datetime)
|
||||||
|
assert result["created_at"].year == 2024
|
||||||
|
assert result["created_at"].month == 1
|
||||||
|
assert result["name"] == "test"
|
||||||
|
|
||||||
def test_restore_table_records_returns_rowcount(self, db_session_with_containers):
|
def test_restore_table_records_returns_rowcount(self, db_session_with_containers):
|
||||||
"""Restore should return inserted rowcount."""
|
"""Restore should return inserted rowcount."""
|
||||||
restore = WorkflowRunRestore()
|
restore = WorkflowRunRestore()
|
||||||
|
|||||||
@ -1,37 +0,0 @@
|
|||||||
"""
|
|
||||||
Unit tests for workflow run restore functionality.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
class TestWorkflowRunRestore:
|
|
||||||
"""Tests for the WorkflowRunRestore class."""
|
|
||||||
|
|
||||||
def test_restore_initialization(self):
|
|
||||||
"""Restore service should respect dry_run flag."""
|
|
||||||
from services.retention.workflow_run.restore_archived_workflow_run import WorkflowRunRestore
|
|
||||||
|
|
||||||
restore = WorkflowRunRestore(dry_run=True)
|
|
||||||
|
|
||||||
assert restore.dry_run is True
|
|
||||||
|
|
||||||
def test_convert_datetime_fields(self):
|
|
||||||
"""ISO datetime strings should be converted to datetime objects."""
|
|
||||||
from models.workflow import WorkflowRun
|
|
||||||
from services.retention.workflow_run.restore_archived_workflow_run import WorkflowRunRestore
|
|
||||||
|
|
||||||
record = {
|
|
||||||
"id": "test-id",
|
|
||||||
"created_at": "2024-01-01T12:00:00",
|
|
||||||
"finished_at": "2024-01-01T12:05:00",
|
|
||||||
"name": "test",
|
|
||||||
}
|
|
||||||
|
|
||||||
restore = WorkflowRunRestore()
|
|
||||||
result = restore._convert_datetime_fields(record, WorkflowRun)
|
|
||||||
|
|
||||||
assert isinstance(result["created_at"], datetime)
|
|
||||||
assert result["created_at"].year == 2024
|
|
||||||
assert result["created_at"].month == 1
|
|
||||||
assert result["name"] == "test"
|
|
||||||
Loading…
Reference in New Issue
Block a user