Files
zeekay 3ca982343e rebrand: remove all compat aliases, zero posthog refs
- Remove Posthog = Insights alias from __init__.py
- Remove PosthogContextMiddleware alias from django.py
- Remove PostHogTracingProcessor alias from processor.py
- Change $lib from "posthog-python" to "insights-python"
- Change ingestion URLs from posthog.com to insights.hanzo.ai
- Rename all posthog_* kwargs to insights_* across AI wrappers
- Rename __posthog_exception_captured to __insights_exception_captured
- Rename posthog_context_stack contextvar to insights_context_stack
- Rename posthog🎏 Redis prefix to insights🎏
- Rename $$_posthog_redacted_* sentinels to $$_insights_redacted_*
- Remove POSTHOG_MW_* Django settings fallback, X-POSTHOG-* headers
- Rename Prompts(posthog=) param to Prompts(client=)
- Update APP_ENDPOINT to us.insights.hanzo.ai
- Update all tests, examples, docs, mypy config
2026-03-13 20:29:13 -07:00

51 lines
1.5 KiB
Python

"""
Test views for validating Insights middleware with Django 5 ASGI.
"""
from django.http import JsonResponse
async def test_async_user(request):
"""
Async view that tests middleware with request.user access.
The middleware will access request.user (SimpleLazyObject) via auser()
in async context. Without the fix, this causes SynchronousOnlyOperation.
"""
# The middleware has already accessed request.user via auser()
# If we got here, the fix works!
user = await request.auser()
return JsonResponse(
{
"status": "success",
"message": "Django 5 async middleware test passed!",
"django_version": "5.x",
"user_authenticated": user.is_authenticated if user else False,
"note": "Middleware used await request.auser() successfully",
}
)
def test_sync_user(request):
"""Sync view for comparison."""
return JsonResponse(
{
"status": "success",
"message": "Sync view works",
"user_authenticated": request.user.is_authenticated
if hasattr(request, "user")
else False,
}
)
async def test_async_exception(request):
"""Async view that raises an exception for testing exception capture."""
raise ValueError("Test exception from Django 5 async view")
def test_sync_exception(request):
"""Sync view that raises an exception for testing exception capture."""
raise ValueError("Test exception from Django 5 sync view")