fix: improve maintenance and synchronize live conversations
This commit is contained in:
1 parent
bb541bd212
commit
ef86a5d3af
297 files changed
+2983
-1274
No files matched your search
@@ -16,7 +16,7 @@ limitations under the License.
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock, AsyncMock
|
||||
from fastapi import HTTPException, Request, Depends
|
||||
from fastapi import HTTPException, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ limitations under the License.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock, AsyncMock
|
||||
from unittest.mock import patch, MagicMock
|
||||
from app.core.auth_utils import (
|
||||
refresh_access_token,
|
||||
authenticate_socket,
|
||||
@@ -26,8 +26,7 @@ from app.models.user import User
|
||||
from app.models.widget import Widget
|
||||
from uuid import uuid4
|
||||
import http.cookies
|
||||
from datetime import datetime, timezone
|
||||
from app.core.security import verify_token, verify_conversation_token, create_access_token, create_refresh_token, create_conversation_token
|
||||
from app.core.security import verify_token, create_access_token, create_refresh_token
|
||||
from app.models.auth_session import AuthSession
|
||||
from app.services.auth_sessions import issue_tokens, revoke_session
|
||||
|
||||
@@ -297,13 +296,13 @@ async def test_authenticate_socket_conversation_token_missing_widget(mock_db):
|
||||
mock_db.query.return_value.filter.return_value.first.return_value = None
|
||||
|
||||
with patch('app.core.auth_utils.verify_conversation_token') as mock_verify, \
|
||||
patch('app.core.auth_utils.get_db') as mock_get_db:
|
||||
patch('app.core.auth_utils.SessionLocal') as mock_session_local:
|
||||
mock_verify.return_value = {
|
||||
"widget_id": widget_id,
|
||||
"sub": customer_id,
|
||||
"type": "conversation"
|
||||
}
|
||||
mock_get_db.return_value.__next__.return_value = mock_db
|
||||
mock_session_local.return_value.__enter__.return_value = mock_db
|
||||
|
||||
# Execute
|
||||
result = await authenticate_socket_conversation_token(sid, auth)
|
||||
@@ -325,13 +324,13 @@ async def test_authenticate_socket_conversation_token_wrong_type(mock_db, mock_w
|
||||
mock_db.query.return_value.filter.return_value.first.return_value = mock_widget
|
||||
|
||||
with patch('app.core.auth_utils.verify_conversation_token') as mock_verify, \
|
||||
patch('app.core.auth_utils.get_db') as mock_get_db:
|
||||
patch('app.core.auth_utils.SessionLocal') as mock_session_local:
|
||||
mock_verify.return_value = {
|
||||
"widget_id": str(mock_widget.id),
|
||||
"sub": customer_id,
|
||||
"type": "access" # Wrong token type
|
||||
}
|
||||
mock_get_db.return_value.__next__.return_value = mock_db
|
||||
mock_session_local.return_value.__enter__.return_value = mock_db
|
||||
|
||||
# Execute
|
||||
result = await authenticate_socket_conversation_token(sid, auth)
|
||||
|
||||
@@ -18,10 +18,9 @@ import pytest
|
||||
from unittest.mock import patch, MagicMock, AsyncMock
|
||||
from app.knowledge.knowledge_base import KnowledgeManager
|
||||
from app.models.knowledge import Knowledge, SourceType
|
||||
from app.models.knowledge_to_agent import KnowledgeToAgent
|
||||
from uuid import UUID, uuid4
|
||||
from uuid import uuid4
|
||||
import os
|
||||
from agno.vectordb.pgvector import PgVector, SearchType
|
||||
from agno.vectordb.pgvector import PgVector
|
||||
|
||||
@pytest.fixture
|
||||
def mock_db():
|
||||
@@ -29,13 +28,6 @@ def mock_db():
|
||||
db = MagicMock()
|
||||
return db
|
||||
|
||||
@pytest.fixture
|
||||
def mock_ai_config():
|
||||
"""Create a mock AI config"""
|
||||
config = MagicMock()
|
||||
config.encrypted_api_key = "encrypted_key"
|
||||
return config
|
||||
|
||||
@pytest.fixture
|
||||
def mock_knowledge():
|
||||
"""Create a mock knowledge entry"""
|
||||
@@ -59,20 +51,15 @@ def mock_vector_db():
|
||||
return vector_db
|
||||
|
||||
@pytest.fixture
|
||||
def knowledge_manager(mock_db, mock_ai_config, mock_vector_db):
|
||||
def knowledge_manager(mock_db, mock_vector_db):
|
||||
"""Create a KnowledgeManager instance with mocked dependencies"""
|
||||
org_id = uuid4()
|
||||
agent_id = uuid4()
|
||||
|
||||
with patch('app.knowledge.knowledge_base.SessionLocal') as mock_session_local, \
|
||||
patch('app.knowledge.knowledge_base.AIConfigRepository') as mock_ai_config_repo, \
|
||||
patch('app.knowledge.knowledge_base.OptimizedPgVector') as mock_pg_vector, \
|
||||
with patch('app.knowledge.knowledge_base.OptimizedPgVector') as mock_pg_vector, \
|
||||
patch('app.knowledge.knowledge_base.KnowledgeRepository') as mock_knowledge_repo, \
|
||||
patch('app.knowledge.knowledge_base.KnowledgeToAgentRepository') as mock_link_repo:
|
||||
|
||||
# Configure basic mocks
|
||||
mock_session_local.return_value.__enter__.return_value = mock_db
|
||||
mock_ai_config_repo.return_value.get_active_config.return_value = mock_ai_config
|
||||
mock_pg_vector.return_value = mock_vector_db
|
||||
|
||||
# Configure repository mocks
|
||||
@@ -174,7 +161,7 @@ async def test_add_pdf_files_success(knowledge_manager, mock_knowledge):
|
||||
files = ["/path/to/test.pdf"]
|
||||
|
||||
with patch('app.knowledge.knowledge_base.EnhancedPDFKnowledgeBase') as mock_pdf_kb, \
|
||||
patch('app.knowledge.knowledge_base.PDFImageReader') as mock_pdf_reader, \
|
||||
patch('app.knowledge.knowledge_base.PDFImageReader'), \
|
||||
patch('os.path.exists') as mock_exists, \
|
||||
patch('os.path.getsize') as mock_getsize, \
|
||||
patch('os.path.basename') as mock_basename, \
|
||||
|
||||
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
@patch('app.core.redis.redis')
|
||||
|
||||
@@ -17,9 +17,8 @@ limitations under the License.
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock, AsyncMock
|
||||
from fastapi import UploadFile, HTTPException
|
||||
from io import BytesIO
|
||||
from unittest.mock import patch, MagicMock
|
||||
from fastapi import HTTPException
|
||||
from app.core.s3 import (
|
||||
S3_MAX_PRESIGN_SECONDS,
|
||||
delete_file_from_s3,
|
||||
|
||||
@@ -18,7 +18,7 @@ import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
import socketio
|
||||
|
||||
from app.core.socketio import configure_socketio, sio, socket_app
|
||||
from app.core.socketio import configure_socketio, sio
|
||||
|
||||
|
||||
def test_configure_socketio_with_cors():
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
Reference in new issue
Block a user