Compare commits

..

2 Commits

Author SHA1 Message Date
itqop 666f661992 fix warnings 2025-12-25 09:57:01 +03:00
itqop 49796a3b41 fix datetime 2025-12-25 09:52:08 +03:00
6 changed files with 34 additions and 34 deletions

View File

@ -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 from datetime import datetime, UTC
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.utcnow().isoformat() + "Z", timestamp=datetime.now(UTC).isoformat().replace('+00:00', '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.utcnow().isoformat() + "Z", timestamp=datetime.now(UTC).isoformat().replace('+00:00', 'Z'),
environment=environment, environment=environment,
response={"answers": response_data} response={"answers": response_data}
) )
except httpx.HTTPStatusError as e: except httpx.HTTPStatusError as e:

View File

@ -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 from datetime import datetime, UTC
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.utcnow().isoformat() + "Z" now = datetime.now(UTC).isoformat().replace('+00:00', 'Z')
body = { body = {
"question": question.body, "question": question.body,
"user_message_id": idx, "user_message_id": idx,

View File

@ -1,6 +1,6 @@
"""JWT token encoding/decoding utilities.""" """JWT token encoding/decoding utilities."""
from datetime import datetime, timedelta from datetime import datetime, timedelta, UTC
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.utcnow() + expires_delta expire = datetime.now(UTC) + expires_delta
else: else:
expire = datetime.utcnow() + timedelta(minutes=settings.JWT_EXPIRE_MINUTES) expire = datetime.now(UTC) + timedelta(minutes=settings.JWT_EXPIRE_MINUTES)
to_encode.update({"exp": int(expire.timestamp())}) to_encode.update({"exp": int(expire.timestamp())})

View File

@ -1,5 +1,5 @@
<?xml version="1.0" ?> <?xml version="1.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"> <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">
<!-- 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>

View File

@ -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 from datetime import datetime, timedelta, UTC
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.utcnow().isoformat() + "Z", last_login_at=datetime.now(UTC).isoformat().replace('+00:00', 'Z'),
created_at=datetime.utcnow().isoformat() + "Z" created_at=datetime.now(UTC).isoformat().replace('+00:00', '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.utcnow().isoformat() + "Z" updated_at=datetime.now(UTC).isoformat().replace('+00:00', 'Z')
) )

View File

@ -7,8 +7,8 @@ from pydantic import BaseModel, ValidationError
from app.interfaces.base import TgBackendInterface from app.interfaces.base import TgBackendInterface
class TestModel(BaseModel): class SampleModel(BaseModel):
"""Test Pydantic model for testing.""" """Sample Pydantic model for testing serialization/deserialization."""
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 = TestModel(name="test", value=42) model = SampleModel(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, TestModel) result = interface._deserialize_response(data, SampleModel)
assert isinstance(result, TestModel) assert isinstance(result, SampleModel)
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, TestModel) interface._deserialize_response(data, SampleModel)
@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, TestModel) result = await interface._handle_response(mock_response, SampleModel)
assert isinstance(result, TestModel) assert isinstance(result, SampleModel)
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=TestModel) result = await interface.get("/users", params={"id": 123}, response_model=SampleModel)
assert isinstance(result, TestModel) assert isinstance(result, SampleModel)
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 = TestModel(name="new", value=50) body = SampleModel(name="new", value=50)
result = await interface.post("/users", body=body, response_model=TestModel) result = await interface.post("/users", body=body, response_model=SampleModel)
assert isinstance(result, TestModel) assert isinstance(result, SampleModel)
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 = TestModel(name="updated", value=75) body = SampleModel(name="updated", value=75)
result = await interface.put("/users/1", body=body, response_model=TestModel) result = await interface.put("/users/1", body=body, response_model=SampleModel)
assert isinstance(result, TestModel) assert isinstance(result, SampleModel)
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 = TestModel(name="test", value=1) body = SampleModel(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)