71 lines
No EOL
2.3 KiB
Python
71 lines
No EOL
2.3 KiB
Python
"""
|
|
Test module for chat workflow functionality.
|
|
Tests the workflow process with analysis tasks.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
from datetime import datetime, UTC
|
|
from unittest.mock import patch
|
|
|
|
# Add gateway directory to Python path
|
|
gateway_dir = Path(__file__).parent.parent
|
|
sys.path.append(str(gateway_dir))
|
|
sys.path.append(str(gateway_dir.parent))
|
|
|
|
from modules.workflow.workflowManager import WorkflowManager
|
|
from modules.interfaces.serviceChatModel import ChatWorkflow, UserInputRequest, ChatStat
|
|
from modules.workflow.chatManager import getChatManager
|
|
from modules.interfaces.serviceManagementModel import FileItem
|
|
|
|
def test_workflow_process():
|
|
# Initialize workflow manager
|
|
workflowManager = WorkflowManager()
|
|
|
|
# Create test workflow
|
|
workflow = ChatWorkflow(
|
|
id="test-workflow",
|
|
mandateId="test-mandate",
|
|
status="running",
|
|
currentRound=1,
|
|
lastActivity=datetime.now(UTC).isoformat(),
|
|
startedAt=datetime.now(UTC).isoformat(),
|
|
messages=[],
|
|
stats=ChatStat(),
|
|
tasks=[]
|
|
)
|
|
|
|
# Initialize chat manager with workflow
|
|
chatManager = getChatManager()
|
|
chatManager.initialize(workflow)
|
|
|
|
# Create mock file
|
|
mock_file = FileItem(
|
|
id="550e8400-e29b-41d4-a716-446655440000",
|
|
mandateId="test-mandate",
|
|
filename="test_file.txt",
|
|
mimeType="text/plain",
|
|
fileHash="test_hash",
|
|
fileSize=1024,
|
|
creationDate=datetime.now(UTC).isoformat()
|
|
)
|
|
|
|
# Mock the getFile function
|
|
with patch.object(chatManager.serviceManagement, 'getFile', return_value=mock_file):
|
|
# Create test user input
|
|
userInput = UserInputRequest(
|
|
prompt="Test prompt",
|
|
listFileId=["550e8400-e29b-41d4-a716-446655440000"] # UUID string
|
|
)
|
|
|
|
# Process workflow
|
|
result = workflowManager.workflowProcess(userInput, workflow)
|
|
|
|
# Verify workflow completed successfully
|
|
assert result.status in ["completed", "failed"], f"Unexpected workflow status: {result.status}"
|
|
assert len(result.messages) > 0, "No messages were generated"
|
|
assert result.messages[-1].role == "assistant", "Last message should be from assistant"
|
|
|
|
if __name__ == "__main__":
|
|
test_workflow_process() |