fix: improve maintenance and synchronize live conversations

This commit is contained in:
WangShen007 committed 2026-10-29 09:46:21 +08:00
1 parent bb541bd212
commit ef86a5d3af
297 files changed
+2983 -1274

No files matched your search

+2 -2
View File
@@ -15,7 +15,7 @@ limitations under the License.
"""
import pytest
from app.models.agent import Agent, AgentType
from app.models.agent import AgentType
from app.repositories.agent import AgentRepository
import json
@@ -90,7 +90,7 @@ def test_get_org_agents(agent_repo, test_organization_id):
org_id=test_organization_id,
is_active=True
)
agent2 = agent_repo.create_agent(
agent_repo.create_agent(
name="Agent 2",
agent_type=AgentType.CUSTOMER_SUPPORT,
instructions=["Instruction"],
+1 -2
View File
@@ -15,10 +15,9 @@ limitations under the License.
"""
import pytest
from app.models.ai_config import AIConfig, AIModelType
from app.models.ai_config import AIModelType
from app.repositories.ai_config import AIConfigRepository
from app.core.security import decrypt_api_key
from uuid import UUID
from app.models.organization import Organization
@pytest.fixture
+1 -1
View File
@@ -23,7 +23,7 @@ from app.models.customer import Customer
from app.models.agent import Agent, AgentType
from app.models.session_to_agent import SessionToAgent, SessionStatus
from app.models.user import User, UserGroup
from uuid import uuid4, UUID
from uuid import uuid4
from app.channels.interactive import from_options
from app.channels.sent_choices import SENT_CHOICES_ATTRIBUTE, encode_sent_choices
from app.models.schemas.chat import ChatDetailResponse
+1 -1
View File
@@ -195,7 +195,7 @@ class TestCrmSyncJobRepository:
def test_skip_pending_for_connection(
self, job_repo, test_organization, test_lead_response):
job = job_repo.enqueue(test_organization.id, test_lead_response.id, "hubspot")
job_repo.enqueue(test_organization.id, test_lead_response.id, "hubspot")
count = job_repo.skip_pending_for_connection(
test_organization.id, "hubspot", "app uninstalled")
assert count == 1
+1 -3
View File
@@ -15,9 +15,8 @@ limitations under the License.
"""
import pytest
from app.models.customer import Customer
from app.repositories.customer import CustomerRepository
from uuid import UUID, uuid4
from uuid import uuid4
@pytest.fixture
def customer_repo(db):
@@ -446,7 +445,6 @@ class TestPhoneIdentityHazards:
# Simulate losing the race: our lookup saw nothing, the insert collides.
calls = {"n": 0}
real_create = customer_repo.create_customer
def racing_create(*args, **kwargs):
calls["n"] += 1
@@ -15,10 +15,8 @@ limitations under the License.
"""
import pytest
from datetime import datetime
from uuid import uuid4
from app.repositories.file_attachment import FileAttachmentRepository
from app.models.file_attachment import FileAttachment
from app.models.chat_history import ChatHistory
from app.models.customer import Customer
from app.models.user import User, UserGroup
+1 -1
View File
@@ -17,7 +17,7 @@ limitations under the License.
import pytest
from app.repositories.group import GroupRepository
from app.models.user import UserGroup, User
from uuid import uuid4, UUID
from uuid import uuid4
@pytest.fixture
def group_repo(db):
@@ -18,7 +18,6 @@ import pytest
from app.repositories.knowledge_queue import KnowledgeQueueRepository
from app.models.knowledge_queue import KnowledgeQueue, QueueStatus
from app.models.user import User
from uuid import uuid4
@pytest.fixture
def queue_repo(db):
@@ -19,7 +19,6 @@ from app.repositories.knowledge import KnowledgeRepository
from app.models.knowledge import Knowledge, SourceType
from app.models.knowledge_to_agent import KnowledgeToAgent
from app.models.agent import Agent, AgentType
from uuid import uuid4
@pytest.fixture
def knowledge_repo(db):
@@ -15,7 +15,6 @@ limitations under the License.
"""
import pytest
from app.models.organization import Organization
from app.repositories.organization import OrganizationRepository
@pytest.fixture
+1 -1
View File
@@ -190,7 +190,7 @@ def test_phone_identifies_and_is_searchable(repo, db, test_organization_id):
def test_update_person_edits_and_guards(repo, db, test_organization_id):
person = _customer(db, test_organization_id)
other = _customer(db, test_organization_id, phone="+15550001111")
_customer(db, test_organization_id, phone="+15550001111")
# Set + correct (overwrite is allowed here — it's the explicit human path)
updated, error = repo.update_person(test_organization_id, person.id,
-1
View File
@@ -20,7 +20,6 @@ from app.models.role import Role
from app.models.permission import Permission
from app.models.user import User
from app.models.organization import Organization
from uuid import uuid4, UUID
@pytest.fixture
def test_organization(db):
@@ -182,13 +182,13 @@ def test_close_session(session_repo, test_session):
def test_get_agent_sessions(session_repo, test_agent, test_organization_id, test_customer):
"""Test retrieving all sessions for an agent"""
# Create multiple sessions
session1 = session_repo.create_session(
session_repo.create_session(
session_id=uuid4(),
agent_id=test_agent.id,
customer_id=test_customer.id,
organization_id=test_organization_id
)
session2 = session_repo.create_session(
session_repo.create_session(
session_id=uuid4(),
agent_id=test_agent.id,
customer_id=test_customer.id,
@@ -239,7 +239,7 @@ def test_get_open_sessions(session_repo, test_session):
def test_get_customer_sessions(session_repo, test_session, test_customer):
"""Test retrieving all sessions for a customer"""
# Create another session for the same customer
session2 = session_repo.create_session(
session_repo.create_session(
session_id=uuid4(),
agent_id=test_session.agent_id,
customer_id=test_customer.id,
+2 -3
View File
@@ -17,7 +17,6 @@ limitations under the License.
import pytest
from app.models.user import User
from app.repositories.user import UserRepository
from uuid import UUID, uuid4
from app.models.organization import Organization
@pytest.fixture
@@ -81,13 +80,13 @@ def test_get_users_by_organization(user_repo, test_organization_id):
"""Test retrieving all users for an organization"""
# Create multiple users
hashed_password = User.get_password_hash("testpassword")
user1 = user_repo.create_user(
user_repo.create_user(
email="user1@example.com",
hashed_password=hashed_password,
full_name="User One",
organization_id=test_organization_id
)
user2 = user_repo.create_user(
user_repo.create_user(
email="user2@example.com",
hashed_password=hashed_password,
full_name="User Two",
+1 -2
View File
@@ -18,12 +18,11 @@ import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.database import Base
from app.models.widget import Widget
from app.models.schemas.widget import WidgetCreate
from app.repositories.widget import WidgetRepository
from app.models.agent import Agent, AgentType
from app.models.organization import Organization
from uuid import UUID, uuid4
from uuid import uuid4
# Test database URL
SQLALCHEMY_DATABASE_URL = "sqlite:///:memory:"