chore: add type annotations to example and test files

This commit is contained in:
9qeklajc
2026-01-10 21:35:16 +01:00
parent 88bcc0edcb
commit d4339287be
2 changed files with 9 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ import sys
import httpx
def create_child_keys(base_url, api_key, count=3):
def create_child_keys(base_url: str, api_key: str, count: int = 3) -> list[str]:
headers = {"Authorization": f"Bearer {api_key}"}
print(f"Requesting {count} child keys from {base_url}...")
@@ -43,4 +43,3 @@ if __name__ == "__main__":
print(json.dumps(keys, indent=2))
else:
print("\nNo child keys were created.")

View File

@@ -1,7 +1,9 @@
import secrets
from typing import Any
import pytest
from fastapi import HTTPException
from sqlmodel.ext.asyncio.session import AsyncSession
from routstr.auth import adjust_payment_for_tokens, pay_for_request
from routstr.balance import create_child_key
@@ -10,7 +12,7 @@ from routstr.core.settings import settings
@pytest.mark.asyncio
async def test_child_key_flow(integration_session):
async def test_child_key_flow(integration_session: AsyncSession) -> None:
# 1. Create a parent key with balance
parent_raw = "parent_test_key_" + secrets.token_hex(4)
parent_key = ApiKey(
@@ -61,7 +63,7 @@ async def test_child_key_flow(integration_session):
import routstr.auth
from routstr.payment.cost_calculation import CostData
async def mock_calculate_cost(*args, **kwargs):
async def mock_calculate_cost(*args: Any, **kwargs: Any) -> CostData:
return CostData(
base_msats=0, input_msats=200, output_msats=200, total_msats=400
)
@@ -95,7 +97,9 @@ async def test_child_key_flow(integration_session):
@pytest.mark.asyncio
async def test_child_key_insufficient_balance(integration_session):
async def test_child_key_insufficient_balance(
integration_session: AsyncSession,
) -> None:
parent_key = ApiKey(
hashed_key="poor_parent_" + secrets.token_hex(4),
balance=500,
@@ -112,7 +116,7 @@ async def test_child_key_insufficient_balance(integration_session):
@pytest.mark.asyncio
async def test_child_key_cannot_create_child(integration_session):
async def test_child_key_cannot_create_child(integration_session: AsyncSession) -> None:
parent_key = ApiKey(
hashed_key="parent_" + secrets.token_hex(4),
balance=10000,