Spaces:
Sleeping
Sleeping
File size: 1,382 Bytes
aef804e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """
Factory for AgentExecution model.
"""
import factory
from factory import fuzzy
from datetime import datetime, timedelta
from tests.factories.base import BaseFactory
from core.models import AgentExecution
class AgentExecutionFactory(BaseFactory):
"""Factory for creating AgentExecution instances."""
class Meta:
model = AgentExecution
# Required fields
id = factory.Faker('uuid4')
agent_id = factory.Faker('uuid4')
workspace_id = factory.Faker('uuid4')
# Execution metadata
status = fuzzy.FuzzyChoice(['running', 'completed', 'failed', 'cancelled'])
triggered_by = fuzzy.FuzzyChoice(['manual', 'schedule', 'websocket', 'event'])
# Input/Output
input_summary = factory.Faker('text', max_nb_chars=200)
# Timing
started_at = factory.Faker('date_time_this_year')
completed_at = factory.LazyAttribute(
lambda o: o.started_at + timedelta(seconds=fuzzy.FuzzyInteger(1, 300).fuzz())
if o.status in ['completed', 'failed', 'cancelled'] else None
)
# Results
result_summary = factory.LazyAttribute(
lambda o: f"Result summary for {o.id}" if o.status == 'completed' else None
)
error_message = factory.LazyAttribute(
lambda o: "Test error message" if o.status == 'failed' else None
)
# Resource tracking
duration_seconds = fuzzy.FuzzyFloat(0.0, 300.0)
|