Add pytest coverage and XML reporting configuration

Co-authored-by: db2002dominic <db2002dominic@gmail.com>
This commit is contained in:
Cursor Agent
2025-08-22 21:00:18 +00:00
co-authored by db2002dominic
parent d7e35887de
commit 06050196d4
6 changed files with 1896 additions and 25 deletions
+1866
View File
File diff suppressed because it is too large Load Diff
+4
View File
@@ -47,6 +47,10 @@ addopts = [
"--disable-warnings",
"-p",
"no:warnings",
"--junit-xml=pytest.xml",
"--cov=routstr",
"--cov-report=xml",
"--cov-report=term-missing:skip-covered",
]
markers = [
"asyncio: marks tests as async (deselect with '-m \"not asyncio\"')",
+1
View File
File diff suppressed because one or more lines are too long
-1
View File
@@ -13,7 +13,6 @@ from .payment.cost_caculation import (
MaxCostData,
calculate_cost,
)
from .payment.helpers import get_max_cost_for_model
from .wallet import (
PRIMARY_MINT_URL,
TRUSTED_MINTS,
+2 -1
View File
@@ -8,8 +8,9 @@ import pytest
import pytest_asyncio
from fastapi import FastAPI
from httpx import AsyncClient
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.ext.asyncio import create_async_engine
from sqlmodel import select
from sqlmodel.ext.asyncio.session import AsyncSession
from routstr.core.logging import get_logger
@@ -5,6 +5,7 @@ import uuid
import pytest
from httpx import AsyncClient
from sqlmodel.ext.asyncio.session import AsyncSession
from routstr.core.db import ApiKey, create_session
@@ -132,32 +133,31 @@ async def test_reserved_balance_with_successful_requests(
@pytest.mark.asyncio
async def test_insufficient_reserved_balance_for_revert() -> None:
async def test_insufficient_reserved_balance_for_revert(integration_session: AsyncSession) -> None:
"""Test revert_pay_for_request behavior with insufficient reserved balance."""
from routstr.auth import revert_pay_for_request
async with create_session() as session:
# Create key with zero reserved balance
unique_key = f"test_revert_key_{uuid.uuid4().hex[:8]}"
test_key = ApiKey(
hashed_key=unique_key,
balance=1000,
reserved_balance=0,
)
session.add(test_key)
await session.commit()
# Create key with zero reserved balance
unique_key = f"test_revert_key_{uuid.uuid4().hex[:8]}"
test_key = ApiKey(
hashed_key=unique_key,
balance=1000,
reserved_balance=0,
)
integration_session.add(test_key)
await integration_session.commit()
# Try to revert more than available
# Note: Current implementation allows reserved_balance to go negative
await revert_pay_for_request(test_key, session, 100)
# Try to revert more than available
# Note: Current implementation allows reserved_balance to go negative
await revert_pay_for_request(test_key, integration_session, 100)
# Refresh to get updated values
await session.refresh(test_key)
# Refresh to get updated values
await integration_session.refresh(test_key)
# Current implementation allows negative reserved balance
assert test_key.reserved_balance == -100, (
f"Expected reserved_balance to be -100, got: {test_key.reserved_balance}"
)
assert test_key.total_requests == -1, (
f"Expected total_requests to be -1, got: {test_key.total_requests}"
)
# Current implementation allows negative reserved balance
assert test_key.reserved_balance == -100, (
f"Expected reserved_balance to be -100, got: {test_key.reserved_balance}"
)
assert test_key.total_requests == -1, (
f"Expected total_requests to be -1, got: {test_key.total_requests}"
)