7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
65 lines
2.8 KiB
Python
65 lines
2.8 KiB
Python
# allow: no-sut-import — black-box HTTP test; drives real routes through the Flask test client
|
|
"""
|
|
Tests for chat page routes (GET /chat/ and GET /chat/<session_id>).
|
|
|
|
These tests verify:
|
|
- Page routes require login
|
|
- Page renders with and without session_id
|
|
- Invalid session_id is handled gracefully
|
|
"""
|
|
|
|
import json
|
|
|
|
|
|
class TestChatPageRoutes:
|
|
"""Tests for chat page rendering endpoints."""
|
|
|
|
def test_chat_page_requires_login(self, client):
|
|
"""Test that GET /chat/ requires authentication."""
|
|
response = client.get("/chat/", follow_redirects=False)
|
|
# Should redirect to login page
|
|
assert response.status_code in (302, 303)
|
|
assert "/login" in response.location or response.status_code == 401
|
|
|
|
def test_chat_page_renders_without_session_id(self, authenticated_client):
|
|
"""Test that GET /chat/ renders successfully for authenticated users."""
|
|
response = authenticated_client.get("/chat/")
|
|
assert response.status_code == 200
|
|
# The response should be HTML (from render_template)
|
|
assert b"<!DOCTYPE html>" in response.data or b"<html" in response.data
|
|
|
|
def test_chat_page_renders_with_valid_session_id(
|
|
self, authenticated_client
|
|
):
|
|
"""Test that GET /chat/<session_id> renders with a session ID."""
|
|
# First create a session
|
|
create_response = authenticated_client.post(
|
|
"/api/chat/sessions",
|
|
json={"initial_query": "Test query"},
|
|
content_type="application/json",
|
|
)
|
|
session_id = json.loads(create_response.data)["session_id"]
|
|
|
|
# Now load the chat page with that session
|
|
response = authenticated_client.get(f"/chat/{session_id}")
|
|
assert response.status_code == 200
|
|
assert b"<!DOCTYPE html>" in response.data or b"<html" in response.data
|
|
|
|
def test_chat_page_handles_invalid_session_id(self, authenticated_client):
|
|
"""Test that GET /chat/<session_id> with invalid session_id still renders.
|
|
|
|
The page should render (status 200) because session validation happens
|
|
client-side via JavaScript API calls, not server-side during page load.
|
|
"""
|
|
invalid_session_id = "non-existent-session-id-12345"
|
|
response = authenticated_client.get(f"/chat/{invalid_session_id}")
|
|
# Page should still render - session validation is client-side
|
|
assert response.status_code == 200
|
|
|
|
def test_chat_page_with_session_requires_login(self, client):
|
|
"""Test that GET /chat/<session_id> requires authentication."""
|
|
response = client.get("/chat/some-session-id", follow_redirects=False)
|
|
# Should redirect to login page
|
|
assert response.status_code in (302, 303)
|
|
assert "/login" in response.location or response.status_code == 401
|