55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
|
|
"""
|
||
|
|
Integration tests for channel SSE endpoint (/channel/sse).
|
||
|
|
"""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
|
||
|
|
|
||
|
|
|
||
|
|
async def test_sse_with_invalid_session_id_returns_400(test_client, channel_auth_headers):
|
||
|
|
response = await test_client.get(
|
||
|
|
"/channel/sse",
|
||
|
|
params={"session_id": "invalid session!@#"},
|
||
|
|
headers=channel_auth_headers,
|
||
|
|
)
|
||
|
|
if response.status_code == 503:
|
||
|
|
pytest.skip("Channel gateway not initialized")
|
||
|
|
assert response.status_code == 400, response.text
|
||
|
|
assert "invalid session_id" in response.json().get("detail", "").lower()
|
||
|
|
|
||
|
|
|
||
|
|
async def test_sse_with_empty_session_id_returns_422(test_client, channel_auth_headers):
|
||
|
|
response = await test_client.get(
|
||
|
|
"/channel/sse",
|
||
|
|
params={"session_id": ""},
|
||
|
|
headers=channel_auth_headers,
|
||
|
|
)
|
||
|
|
if response.status_code == 503:
|
||
|
|
pytest.skip("Channel gateway not initialized")
|
||
|
|
assert response.status_code == 422
|
||
|
|
|
||
|
|
|
||
|
|
async def test_sse_without_session_id_returns_422(test_client, channel_auth_headers):
|
||
|
|
response = await test_client.get(
|
||
|
|
"/channel/sse",
|
||
|
|
headers=channel_auth_headers,
|
||
|
|
)
|
||
|
|
if response.status_code == 503:
|
||
|
|
pytest.skip("Channel gateway not initialized")
|
||
|
|
assert response.status_code == 422
|
||
|
|
|
||
|
|
|
||
|
|
async def test_sse_with_valid_session_id_format(test_client, channel_auth_headers):
|
||
|
|
response = await test_client.get(
|
||
|
|
"/channel/sse",
|
||
|
|
params={"session_id": "test-session-123"},
|
||
|
|
headers=channel_auth_headers,
|
||
|
|
)
|
||
|
|
if response.status_code == 503:
|
||
|
|
pytest.skip("Channel gateway not initialized")
|
||
|
|
if response.status_code == 200:
|
||
|
|
assert "text/event-stream" in response.headers.get("content-type", "")
|