Merge pull request #113 from abhi1693/perf/activity-events-eventtype-createdat

perf(db): index activity_events by (event_type, created_at)
This commit is contained in:
Abhimanyu Saharan
2026-02-14 02:55:37 +05:30
committed by GitHub
6 changed files with 287 additions and 42 deletions

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
import pytest
from fastapi import FastAPI, HTTPException
from fastapi.exceptions import RequestValidationError, ResponseValidationError
from fastapi.testclient import TestClient
from pydantic import BaseModel, Field
from starlette.requests import Request
@@ -17,6 +18,8 @@ from app.core.error_handling import (
_json_safe,
_request_validation_exception_handler,
_response_validation_exception_handler,
_request_validation_handler,
_response_validation_handler,
install_error_handling,
)
@@ -243,3 +246,91 @@ async def test_http_exception_wrapper_rejects_wrong_exception() -> None:
req = Request({"type": "http", "headers": [], "state": {}})
with pytest.raises(TypeError, match="Expected StarletteHTTPException"):
await _http_exception_exception_handler(req, Exception("x"))
@pytest.mark.asyncio
async def test_request_validation_handler_includes_request_id() -> None:
req = Request({"type": "http", "headers": [], "state": {"request_id": "req-1"}})
exc = RequestValidationError(
[
{
"loc": ("query", "limit"),
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
)
resp = await _request_validation_handler(req, exc)
assert resp.status_code == 422
assert resp.body
@pytest.mark.asyncio
async def test_request_validation_exception_wrapper_success_path() -> None:
req = Request({"type": "http", "headers": [], "state": {"request_id": "req-wrap-1"}})
exc = RequestValidationError(
[
{
"loc": ("query", "limit"),
"msg": "value is not a valid integer",
"type": "type_error.integer",
}
]
)
resp = await _request_validation_exception_handler(req, exc)
assert resp.status_code == 422
assert b"request_id" in resp.body
@pytest.mark.asyncio
async def test_response_validation_handler_includes_request_id() -> None:
req = Request(
{
"type": "http",
"method": "GET",
"path": "/x",
"headers": [],
"state": {"request_id": "req-2"},
}
)
exc = ResponseValidationError(
[
{
"loc": ("response", "name"),
"msg": "field required",
"type": "value_error.missing",
}
]
)
resp = await _response_validation_handler(req, exc)
assert resp.status_code == 500
assert resp.body
@pytest.mark.asyncio
async def test_response_validation_exception_wrapper_success_path() -> None:
req = Request(
{
"type": "http",
"method": "GET",
"path": "/x",
"headers": [],
"state": {"request_id": "req-wrap-2"},
}
)
exc = ResponseValidationError(
[
{
"loc": ("response", "name"),
"msg": "field required",
"type": "value_error.missing",
}
]
)
resp = await _response_validation_exception_handler(req, exc)
assert resp.status_code == 500
assert b"request_id" in resp.body