fix(tests): isolate test DB and sync tier=pro in Pro user fixtures
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m34s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m34s
This commit is contained in:
@@ -1,3 +1,14 @@
|
|||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Use a temporary on-disk SQLite database for the test session so that
|
||||||
|
# both the sync and async engines used by the app point at the same isolated
|
||||||
|
# schema. This avoids relying on (or mutating) the developer's data/translate.db.
|
||||||
|
_test_db_file = tempfile.NamedTemporaryFile(suffix=".db", delete=False)
|
||||||
|
_test_db_file.close()
|
||||||
|
os.environ["SQLITE_PATH"] = _test_db_file.name
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
@@ -14,6 +25,11 @@ TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"
|
|||||||
def initialize_test_database():
|
def initialize_test_database():
|
||||||
Base.metadata.create_all(bind=sync_engine)
|
Base.metadata.create_all(bind=sync_engine)
|
||||||
yield
|
yield
|
||||||
|
# Clean up the temporary test database after the session.
|
||||||
|
try:
|
||||||
|
Path(_test_db_file.name).unlink(missing_ok=True)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ def pro_user_token(client, monkeypatch):
|
|||||||
users = auth_svc.load_users()
|
users = auth_svc.load_users()
|
||||||
if user_id in users:
|
if user_id in users:
|
||||||
users[user_id]["plan"] = "pro"
|
users[user_id]["plan"] = "pro"
|
||||||
|
users[user_id]["tier"] = "pro"
|
||||||
auth_svc.save_users(users)
|
auth_svc.save_users(users)
|
||||||
|
|
||||||
return token, user_id
|
return token, user_id
|
||||||
@@ -235,6 +236,7 @@ class TestGlossaryCRUD:
|
|||||||
users = auth_svc.load_users()
|
users = auth_svc.load_users()
|
||||||
if user_id1 in users:
|
if user_id1 in users:
|
||||||
users[user_id1]["plan"] = "pro"
|
users[user_id1]["plan"] = "pro"
|
||||||
|
users[user_id1]["tier"] = "pro"
|
||||||
auth_svc.save_users(users)
|
auth_svc.save_users(users)
|
||||||
|
|
||||||
# Create user 2 (Pro)
|
# Create user 2 (Pro)
|
||||||
@@ -251,6 +253,7 @@ class TestGlossaryCRUD:
|
|||||||
users = auth_svc.load_users()
|
users = auth_svc.load_users()
|
||||||
if user_id2 in users:
|
if user_id2 in users:
|
||||||
users[user_id2]["plan"] = "pro"
|
users[user_id2]["plan"] = "pro"
|
||||||
|
users[user_id2]["tier"] = "pro"
|
||||||
auth_svc.save_users(users)
|
auth_svc.save_users(users)
|
||||||
|
|
||||||
# Create glossary as user 1
|
# Create glossary as user 1
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ def pro_user_token(client, monkeypatch):
|
|||||||
users = auth_svc.load_users()
|
users = auth_svc.load_users()
|
||||||
if user_id in users:
|
if user_id in users:
|
||||||
users[user_id]["plan"] = "pro"
|
users[user_id]["plan"] = "pro"
|
||||||
|
users[user_id]["tier"] = "pro"
|
||||||
auth_svc.save_users(users)
|
auth_svc.save_users(users)
|
||||||
|
|
||||||
return token, user_id
|
return token, user_id
|
||||||
@@ -269,6 +270,7 @@ class TestPromptCRUD:
|
|||||||
users = auth_svc.load_users()
|
users = auth_svc.load_users()
|
||||||
if user_id1 in users:
|
if user_id1 in users:
|
||||||
users[user_id1]["plan"] = "pro"
|
users[user_id1]["plan"] = "pro"
|
||||||
|
users[user_id1]["tier"] = "pro"
|
||||||
auth_svc.save_users(users)
|
auth_svc.save_users(users)
|
||||||
|
|
||||||
email2 = "pro2@test.com"
|
email2 = "pro2@test.com"
|
||||||
@@ -284,6 +286,7 @@ class TestPromptCRUD:
|
|||||||
users = auth_svc.load_users()
|
users = auth_svc.load_users()
|
||||||
if user_id2 in users:
|
if user_id2 in users:
|
||||||
users[user_id2]["plan"] = "pro"
|
users[user_id2]["plan"] = "pro"
|
||||||
|
users[user_id2]["tier"] = "pro"
|
||||||
auth_svc.save_users(users)
|
auth_svc.save_users(users)
|
||||||
|
|
||||||
with get_sync_session() as session:
|
with get_sync_session() as session:
|
||||||
|
|||||||
Reference in New Issue
Block a user