style: apply ruff formatting and move TYPE_CHECKING imports in tests

This commit is contained in:
2026-02-04 01:08:32 +00:00
parent d7966f7e96
commit fc88f84f4a
6 changed files with 53 additions and 66 deletions

View File

@@ -14,7 +14,7 @@ Comprehensive tests covering:
from __future__ import annotations
from typing import AsyncGenerator
from typing import TYPE_CHECKING
import pytest
from fastapi import FastAPI, Request
@@ -23,12 +23,15 @@ from httpx import ASGITransport, AsyncClient
from fastapi_traffic import (
MemoryBackend,
RateLimitExceeded,
RateLimiter,
RateLimitExceeded,
rate_limit,
)
from fastapi_traffic.core.limiter import set_limiter
if TYPE_CHECKING:
from collections.abc import AsyncGenerator
class TestRateLimitDecorator:
"""Tests for the @rate_limit decorator."""
@@ -175,9 +178,7 @@ class TestCustomKeyExtractor:
) -> None:
"""Test that different API keys have separate rate limits."""
for _ in range(2):
response = await client.get(
"/by-api-key", headers={"X-API-Key": "key-a"}
)
response = await client.get("/by-api-key", headers={"X-API-Key": "key-a"})
assert response.status_code == 200
response = await client.get("/by-api-key", headers={"X-API-Key": "key-a"})
@@ -186,9 +187,7 @@ class TestCustomKeyExtractor:
response = await client.get("/by-api-key", headers={"X-API-Key": "key-b"})
assert response.status_code == 200
async def test_anonymous_key_for_missing_header(
self, client: AsyncClient
) -> None:
async def test_anonymous_key_for_missing_header(self, client: AsyncClient) -> None:
"""Test that missing API key uses anonymous."""
for _ in range(2):
response = await client.get("/by-api-key")
@@ -255,8 +254,6 @@ class TestExemptionCallback:
assert response.status_code == 429
class TestCostParameter:
"""Tests for the cost parameter."""