Compare commits
No commits in common. "666f66199281154d666d7a1275876e325f4096e0" and "74cdc196c64f34b54d7bf72429c975b53d3650f5" have entirely different histories.
666f661992
...
74cdc196c6
|
|
@ -14,7 +14,7 @@ from app.services.rag_service import RagService
|
||||||
from app.dependencies import get_db_client, get_current_user
|
from app.dependencies import get_db_client, get_current_user
|
||||||
import httpx
|
import httpx
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -90,10 +90,10 @@ async def bench_query(
|
||||||
request_id=request_id
|
request_id=request_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
return QueryResponse(
|
return QueryResponse(
|
||||||
request_id=request_id,
|
request_id=request_id,
|
||||||
timestamp=datetime.now(UTC).isoformat().replace('+00:00', 'Z'),
|
timestamp=datetime.utcnow().isoformat() + "Z",
|
||||||
environment=environment,
|
environment=environment,
|
||||||
response=response_data
|
response=response_data
|
||||||
)
|
)
|
||||||
|
|
@ -178,12 +178,12 @@ async def backend_query(
|
||||||
reset_session=request.reset_session
|
reset_session=request.reset_session
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
return QueryResponse(
|
return QueryResponse(
|
||||||
request_id=request_id,
|
request_id=request_id,
|
||||||
timestamp=datetime.now(UTC).isoformat().replace('+00:00', 'Z'),
|
timestamp=datetime.utcnow().isoformat() + "Z",
|
||||||
environment=environment,
|
environment=environment,
|
||||||
response={"answers": response_data}
|
response={"answers": response_data}
|
||||||
)
|
)
|
||||||
|
|
||||||
except httpx.HTTPStatusError as e:
|
except httpx.HTTPStatusError as e:
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import logging
|
||||||
import httpx
|
import httpx
|
||||||
import uuid
|
import uuid
|
||||||
from typing import List, Dict, Optional, Any
|
from typing import List, Dict, Optional, Any
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.models.query import QuestionRequest, RagResponseBenchList
|
from app.models.query import QuestionRequest, RagResponseBenchList
|
||||||
|
|
||||||
|
|
@ -276,8 +276,8 @@ class RagService:
|
||||||
responses = []
|
responses = []
|
||||||
|
|
||||||
for idx, question in enumerate(questions, start=1):
|
for idx, question in enumerate(questions, start=1):
|
||||||
|
|
||||||
now = datetime.now(UTC).isoformat().replace('+00:00', 'Z')
|
now = datetime.utcnow().isoformat() + "Z"
|
||||||
body = {
|
body = {
|
||||||
"question": question.body,
|
"question": question.body,
|
||||||
"user_message_id": idx,
|
"user_message_id": idx,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""JWT token encoding/decoding utilities."""
|
"""JWT token encoding/decoding utilities."""
|
||||||
|
|
||||||
from datetime import datetime, timedelta, UTC
|
from datetime import datetime, timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from jose import JWTError, jwt
|
from jose import JWTError, jwt
|
||||||
|
|
@ -22,9 +22,9 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -
|
||||||
to_encode = data.copy()
|
to_encode = data.copy()
|
||||||
|
|
||||||
if expires_delta:
|
if expires_delta:
|
||||||
expire = datetime.now(UTC) + expires_delta
|
expire = datetime.utcnow() + expires_delta
|
||||||
else:
|
else:
|
||||||
expire = datetime.now(UTC) + timedelta(minutes=settings.JWT_EXPIRE_MINUTES)
|
expire = datetime.utcnow() + timedelta(minutes=settings.JWT_EXPIRE_MINUTES)
|
||||||
|
|
||||||
to_encode.update({"exp": int(expire.timestamp())})
|
to_encode.update({"exp": int(expire.timestamp())})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" ?>
|
<?xml version="1.0" ?>
|
||||||
<coverage version="7.13.0" timestamp="1766645611374" lines-valid="617" lines-covered="594" line-rate="0.9627" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
|
<coverage version="7.13.0" timestamp="1766645017585" lines-valid="617" lines-covered="594" line-rate="0.9627" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
|
||||||
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.13.0 -->
|
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.13.0 -->
|
||||||
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
|
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
|
||||||
<sources>
|
<sources>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ if test_env_path.exists():
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import AsyncMock, MagicMock
|
from unittest.mock import AsyncMock, MagicMock
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from datetime import datetime, timedelta, UTC
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from app.main import app
|
from app.main import app
|
||||||
from app.dependencies import get_db_client, get_current_user
|
from app.dependencies import get_db_client, get_current_user
|
||||||
|
|
@ -52,8 +52,8 @@ def test_user_response(test_user):
|
||||||
return UserResponse(
|
return UserResponse(
|
||||||
user_id=test_user["user_id"],
|
user_id=test_user["user_id"],
|
||||||
login=test_user["login"],
|
login=test_user["login"],
|
||||||
last_login_at=datetime.now(UTC).isoformat().replace('+00:00', 'Z'),
|
last_login_at=datetime.utcnow().isoformat() + "Z",
|
||||||
created_at=datetime.now(UTC).isoformat().replace('+00:00', 'Z')
|
created_at=datetime.utcnow().isoformat() + "Z"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ def test_settings():
|
||||||
"psi": env_settings.model_copy(),
|
"psi": env_settings.model_copy(),
|
||||||
"prod": env_settings.model_copy()
|
"prod": env_settings.model_copy()
|
||||||
},
|
},
|
||||||
updated_at=datetime.now(UTC).isoformat().replace('+00:00', 'Z')
|
updated_at=datetime.utcnow().isoformat() + "Z"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ from pydantic import BaseModel, ValidationError
|
||||||
from app.interfaces.base import TgBackendInterface
|
from app.interfaces.base import TgBackendInterface
|
||||||
|
|
||||||
|
|
||||||
class SampleModel(BaseModel):
|
class TestModel(BaseModel):
|
||||||
"""Sample Pydantic model for testing serialization/deserialization."""
|
"""Test Pydantic model for testing."""
|
||||||
name: str
|
name: str
|
||||||
value: int
|
value: int
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ class TestTgBackendInterface:
|
||||||
"""Test serializing Pydantic model to dict."""
|
"""Test serializing Pydantic model to dict."""
|
||||||
with patch('app.interfaces.base.httpx.AsyncClient'):
|
with patch('app.interfaces.base.httpx.AsyncClient'):
|
||||||
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
||||||
model = SampleModel(name="test", value=42)
|
model = TestModel(name="test", value=42)
|
||||||
|
|
||||||
result = interface._serialize_body(model)
|
result = interface._serialize_body(model)
|
||||||
|
|
||||||
|
|
@ -113,9 +113,9 @@ class TestTgBackendInterface:
|
||||||
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
||||||
data = {"name": "test", "value": 42}
|
data = {"name": "test", "value": 42}
|
||||||
|
|
||||||
result = interface._deserialize_response(data, SampleModel)
|
result = interface._deserialize_response(data, TestModel)
|
||||||
|
|
||||||
assert isinstance(result, SampleModel)
|
assert isinstance(result, TestModel)
|
||||||
assert result.name == "test"
|
assert result.name == "test"
|
||||||
assert result.value == 42
|
assert result.value == 42
|
||||||
|
|
||||||
|
|
@ -137,7 +137,7 @@ class TestTgBackendInterface:
|
||||||
data = {"name": "test"}
|
data = {"name": "test"}
|
||||||
|
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
interface._deserialize_response(data, SampleModel)
|
interface._deserialize_response(data, TestModel)
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_handle_response_success(self):
|
async def test_handle_response_success(self):
|
||||||
|
|
@ -151,9 +151,9 @@ class TestTgBackendInterface:
|
||||||
mock_response.json.return_value = {"name": "test", "value": 42}
|
mock_response.json.return_value = {"name": "test", "value": 42}
|
||||||
mock_response.raise_for_status = MagicMock()
|
mock_response.raise_for_status = MagicMock()
|
||||||
|
|
||||||
result = await interface._handle_response(mock_response, SampleModel)
|
result = await interface._handle_response(mock_response, TestModel)
|
||||||
|
|
||||||
assert isinstance(result, SampleModel)
|
assert isinstance(result, TestModel)
|
||||||
assert result.name == "test"
|
assert result.name == "test"
|
||||||
mock_response.raise_for_status.assert_called_once()
|
mock_response.raise_for_status.assert_called_once()
|
||||||
|
|
||||||
|
|
@ -237,9 +237,9 @@ class TestTgBackendInterface:
|
||||||
with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client):
|
with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client):
|
||||||
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
||||||
|
|
||||||
result = await interface.get("/users", params={"id": 123}, response_model=SampleModel)
|
result = await interface.get("/users", params={"id": 123}, response_model=TestModel)
|
||||||
|
|
||||||
assert isinstance(result, SampleModel)
|
assert isinstance(result, TestModel)
|
||||||
assert result.name == "test"
|
assert result.name == "test"
|
||||||
mock_client.get.assert_called_once()
|
mock_client.get.assert_called_once()
|
||||||
call_args = mock_client.get.call_args
|
call_args = mock_client.get.call_args
|
||||||
|
|
@ -259,11 +259,11 @@ class TestTgBackendInterface:
|
||||||
|
|
||||||
with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client):
|
with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client):
|
||||||
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
||||||
body = SampleModel(name="new", value=50)
|
body = TestModel(name="new", value=50)
|
||||||
|
|
||||||
result = await interface.post("/users", body=body, response_model=SampleModel)
|
result = await interface.post("/users", body=body, response_model=TestModel)
|
||||||
|
|
||||||
assert isinstance(result, SampleModel)
|
assert isinstance(result, TestModel)
|
||||||
assert result.name == "created"
|
assert result.name == "created"
|
||||||
mock_client.post.assert_called_once()
|
mock_client.post.assert_called_once()
|
||||||
call_args = mock_client.post.call_args
|
call_args = mock_client.post.call_args
|
||||||
|
|
@ -303,11 +303,11 @@ class TestTgBackendInterface:
|
||||||
|
|
||||||
with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client):
|
with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client):
|
||||||
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
||||||
body = SampleModel(name="updated", value=75)
|
body = TestModel(name="updated", value=75)
|
||||||
|
|
||||||
result = await interface.put("/users/1", body=body, response_model=SampleModel)
|
result = await interface.put("/users/1", body=body, response_model=TestModel)
|
||||||
|
|
||||||
assert isinstance(result, SampleModel)
|
assert isinstance(result, TestModel)
|
||||||
assert result.name == "updated"
|
assert result.name == "updated"
|
||||||
mock_client.put.assert_called_once()
|
mock_client.put.assert_called_once()
|
||||||
call_args = mock_client.put.call_args
|
call_args = mock_client.put.call_args
|
||||||
|
|
@ -373,7 +373,7 @@ class TestTgBackendInterface:
|
||||||
|
|
||||||
with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client):
|
with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client):
|
||||||
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
interface = TgBackendInterface(api_prefix="http://api.example.com")
|
||||||
body = SampleModel(name="test", value=1)
|
body = TestModel(name="test", value=1)
|
||||||
|
|
||||||
with pytest.raises(httpx.HTTPStatusError):
|
with pytest.raises(httpx.HTTPStatusError):
|
||||||
await interface.post("/users", body=body)
|
await interface.post("/users", body=body)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue