fix(translate): French error messages and update mock users for quota checks
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m52s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m52s
This commit is contained in:
@@ -38,13 +38,28 @@ def create_valid_excel() -> bytes:
|
||||
return buf.read()
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
@pytest.fixture()
|
||||
def client(monkeypatch):
|
||||
"""TestClient with rate limiting and quota reservation bypassed for URL validation tests."""
|
||||
from middleware.rate_limiting import RateLimitMiddleware
|
||||
|
||||
async def _dispatch(self, request, call_next):
|
||||
return await call_next(request)
|
||||
|
||||
monkeypatch.setattr(RateLimitMiddleware, "dispatch", _dispatch)
|
||||
monkeypatch.setattr("routes.translate_routes.reserve_translation_quota", lambda user_id: True)
|
||||
from main import app
|
||||
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
class MockUser:
|
||||
def __init__(self):
|
||||
self.id = "user_abc123"
|
||||
self.plan = "pro"
|
||||
self.docs_translated_this_month = 0
|
||||
self.pages_translated_this_month = 0
|
||||
self.extra_credits = 0
|
||||
|
||||
|
||||
async def mock_get_authenticated_user():
|
||||
@@ -72,7 +87,7 @@ def create_mock_client_with_stream(mock_response):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_validate_file_url_invalid_format():
|
||||
async def test_validate_file_url_invalid_format(client):
|
||||
"""Test that invalid file format (.txt) returns INVALID_FORMAT error."""
|
||||
app.dependency_overrides[get_authenticated_user] = mock_get_authenticated_user
|
||||
try:
|
||||
@@ -94,7 +109,7 @@ async def test_validate_file_url_invalid_format():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_validate_file_url_corrupted_magic_bytes():
|
||||
async def test_validate_file_url_corrupted_magic_bytes(client):
|
||||
"""Test that corrupted file (invalid magic bytes) returns CORRUPTED_FILE error."""
|
||||
app.dependency_overrides[get_authenticated_user] = mock_get_authenticated_user
|
||||
try:
|
||||
|
||||
@@ -77,12 +77,18 @@ class MockProUser:
|
||||
def __init__(self):
|
||||
self.id = "pro_user_123"
|
||||
self.plan = "pro"
|
||||
self.docs_translated_this_month = 0
|
||||
self.pages_translated_this_month = 0
|
||||
self.extra_credits = 0
|
||||
|
||||
|
||||
class MockFreeUser:
|
||||
def __init__(self):
|
||||
self.id = "free_user_123"
|
||||
self.plan = "free"
|
||||
self.docs_translated_this_month = 0
|
||||
self.pages_translated_this_month = 0
|
||||
self.extra_credits = 0
|
||||
|
||||
|
||||
async def mock_get_pro_user():
|
||||
|
||||
@@ -5,13 +5,28 @@ from unittest.mock import patch, AsyncMock, MagicMock
|
||||
from main import app
|
||||
from routes.translate_routes import get_authenticated_user
|
||||
|
||||
client = TestClient(app)
|
||||
@pytest.fixture()
|
||||
def client(monkeypatch):
|
||||
"""TestClient with rate limiting and quota reservation bypassed for metadata tests."""
|
||||
from middleware.rate_limiting import RateLimitMiddleware
|
||||
|
||||
async def _dispatch(self, request, call_next):
|
||||
return await call_next(request)
|
||||
|
||||
monkeypatch.setattr(RateLimitMiddleware, "dispatch", _dispatch)
|
||||
monkeypatch.setattr("routes.translate_routes.reserve_translation_quota", lambda user_id: True)
|
||||
from main import app
|
||||
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
class MockUser:
|
||||
def __init__(self, user_id="user_123"):
|
||||
self.id = user_id
|
||||
self.plan = "free"
|
||||
self.docs_translated_this_month = 0
|
||||
self.pages_translated_this_month = 0
|
||||
self.extra_credits = 0
|
||||
|
||||
|
||||
async def mock_auth():
|
||||
@@ -19,7 +34,7 @@ async def mock_auth():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_translate_endpoint_triggers_tracking():
|
||||
async def test_translate_endpoint_triggers_tracking(client):
|
||||
app.dependency_overrides[get_authenticated_user] = mock_auth
|
||||
|
||||
with patch(
|
||||
@@ -70,7 +85,7 @@ async def test_translate_endpoint_triggers_tracking():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_translate_endpoint_handles_hash_failure():
|
||||
async def test_translate_endpoint_handles_hash_failure(client):
|
||||
app.dependency_overrides[get_authenticated_user] = mock_auth
|
||||
|
||||
with patch("routes.translate_routes.file_validator.validate_async") as mock_val:
|
||||
|
||||
Reference in New Issue
Block a user