refactor: replace sa.String with EnumText in mapped_column for type s… (#33332)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
tmimmanuel
2026-03-14 04:38:27 +00:00
committed by GitHub
parent 6043ec4423
commit e64f4d6039
40 changed files with 218 additions and 138 deletions

View File

@ -3331,7 +3331,7 @@ class TestRegisterService:
TenantService.create_tenant_member(tenant, account, role="normal")
# Change tenant status to non-normal
tenant.status = "suspended"
tenant.status = "archive"
db_session_with_containers.commit()

View File

@ -2,6 +2,7 @@ import uuid
from unittest.mock import ANY, MagicMock, patch
import pytest
import sqlalchemy as sa
from faker import Faker
from sqlalchemy.orm import Session
@ -492,20 +493,20 @@ class TestAppGenerateService:
)
# Manually set invalid mode after creation
# With EnumText, invalid values are rejected at the DB level during flush,
# raising StatementError wrapping ValueError
app.mode = "invalid_mode"
# Setup test arguments
args = {"inputs": {"query": fake.text(max_nb_chars=50)}, "response_mode": "streaming"}
# Execute the method under test and expect ValueError
with pytest.raises(ValueError) as exc_info:
# Execute the method under test and expect either ValueError (direct) or
# StatementError (from EnumText validation during autoflush)
with pytest.raises((ValueError, sa.exc.StatementError)):
AppGenerateService.generate(
app_model=app, user=account, args=args, invoke_from=InvokeFrom.SERVICE_API, streaming=True
)
# Verify error message
assert "Invalid app mode" in str(exc_info.value)
def test_generate_with_workflow_id_format_error(
self, db_session_with_containers: Session, mock_external_service_dependencies
):

View File

@ -163,7 +163,7 @@ class TestSavedMessageService:
answer_unit_price=0.002,
total_price=0.003,
currency="USD",
status="success",
status="normal",
)
db_session_with_containers.add(message)

View File

@ -62,7 +62,7 @@ class TestWorkflowService:
tenant = Tenant(
name=f"Test Tenant {fake.company()}",
plan="basic",
status="active",
status="normal",
)
tenant.id = account.current_tenant_id
tenant.created_at = fake.date_time_this_year()
@ -1090,20 +1090,19 @@ class TestWorkflowService:
This test ensures that the service correctly handles feature validation
for unsupported app modes, preventing invalid operations.
With EnumText, invalid values are rejected at the DB level during flush,
raising StatementError wrapping ValueError.
"""
# Arrange
fake = Faker()
app = self._create_test_app(db_session_with_containers, fake)
app.mode = "invalid_mode" # Invalid mode
db_session_with_containers.commit()
# Act & Assert - EnumText validation rejects invalid values at DB flush
import sqlalchemy as sa
workflow_service = WorkflowService()
features = {"test": "value"}
# Act & Assert
with pytest.raises(ValueError, match="Invalid app mode: invalid_mode"):
workflow_service.validate_features_structure(app_model=app, features=features)
with pytest.raises((ValueError, sa.exc.StatementError)):
db_session_with_containers.commit()
def test_update_workflow_success(self, db_session_with_containers: Session):
"""

View File

@ -110,7 +110,7 @@ class TestCleanDatasetTask:
tenant = Tenant(
name=fake.company(),
plan="basic",
status="active",
status="normal",
)
db_session_with_containers.add(tenant)

View File

@ -48,7 +48,7 @@ class TestDeleteSegmentFromIndexTask:
Tenant: Created test tenant instance
"""
fake = fake or Faker()
tenant = Tenant(name=f"Test Tenant {fake.company()}", plan="basic", status="active")
tenant = Tenant(name=f"Test Tenant {fake.company()}", plan="basic", status="normal")
tenant.id = fake.uuid4()
tenant.created_at = fake.date_time_this_year()
tenant.updated_at = tenant.created_at

View File

@ -65,7 +65,7 @@ class TestDisableSegmentsFromIndexTask:
tenant = Tenant(
name=f"Test Tenant {fake.company()}",
plan="basic",
status="active",
status="normal",
)
tenant.id = account.tenant_id
tenant.created_at = fake.date_time_this_year()

View File

@ -118,7 +118,7 @@ class TestSendEmailCodeLoginMailTask:
tenant = Tenant(
name=fake.company(),
plan="basic",
status="active",
status="normal",
)
db_session_with_containers.add(tenant)