This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
breakpilot-pwa/voice-service/tests/test_sessions.py
Benjamin Admin 21a844cb8a fix: Restore all files lost during destructive rebase
A previous `git pull --rebase origin main` dropped 177 local commits,
losing 3400+ files across admin-v2, backend, studio-v2, website,
klausur-service, and many other services. The partial restore attempt
(660295e2) only recovered some files.

This commit restores all missing files from pre-rebase ref 98933f5e
while preserving post-rebase additions (night-scheduler, night-mode UI,
NightModeWidget dashboard integration).

Restored features include:
- AI Module Sidebar (FAB), OCR Labeling, OCR Compare
- GPU Dashboard, RAG Pipeline, Magic Help
- Klausur-Korrektur (8 files), Abitur-Archiv (5+ files)
- Companion, Zeugnisse-Crawler, Screen Flow
- Full backend, studio-v2, website, klausur-service
- All compliance SDKs, agent-core, voice-service
- CI/CD configs, documentation, scripts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 09:51:32 +01:00

95 lines
3.3 KiB
Python

"""
Tests for Session API
"""
import pytest
class TestSessionAPI:
"""Tests for session management."""
def test_health_check(self, client):
"""Test health endpoint returns healthy status."""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert data["service"] == "voice-service"
assert data["dsgvo_compliance"]["audio_persistence"] is False
def test_root_endpoint(self, client):
"""Test root endpoint returns service info."""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["service"] == "Breakpilot Voice Service"
assert "endpoints" in data
assert data["privacy"]["audio_stored"] is False
def test_create_session(self, client):
"""Test session creation."""
response = client.post(
"/api/v1/sessions",
json={
"namespace_id": "test-ns-12345678",
"key_hash": "sha256:eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHg=", # 32 bytes base64
"device_type": "pwa",
"client_version": "1.0.0",
},
)
assert response.status_code == 200
data = response.json()
assert "id" in data
assert data["namespace_id"] == "test-ns-12345678"
assert data["status"] == "created"
assert "websocket_url" in data
def test_create_session_invalid_key_hash(self, client):
"""Test session creation with invalid key hash."""
response = client.post(
"/api/v1/sessions",
json={
"namespace_id": "test-ns-12345678",
"key_hash": "invalid",
"device_type": "pwa",
},
)
assert response.status_code == 401
assert "Invalid encryption key hash" in response.json()["detail"]
def test_get_session_not_found(self, client):
"""Test getting non-existent session."""
response = client.get("/api/v1/sessions/nonexistent-session")
assert response.status_code == 404
def test_session_lifecycle(self, client):
"""Test full session lifecycle."""
# Create session
create_response = client.post(
"/api/v1/sessions",
json={
"namespace_id": "test-ns-lifecycle",
"key_hash": "sha256:eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHg=",
},
)
assert create_response.status_code == 200
session_id = create_response.json()["id"]
# Get session
get_response = client.get(f"/api/v1/sessions/{session_id}")
assert get_response.status_code == 200
assert get_response.json()["id"] == session_id
# Get session stats
stats_response = client.get(f"/api/v1/sessions/{session_id}/stats")
assert stats_response.status_code == 200
assert "message_count" in stats_response.json()
# Delete session
delete_response = client.delete(f"/api/v1/sessions/{session_id}")
assert delete_response.status_code == 200
assert delete_response.json()["status"] == "closed"
# Verify session is gone
get_again = client.get(f"/api/v1/sessions/{session_id}")
assert get_again.status_code == 404