Spaces:
Running
Running
Download tests/test_connection_docs.py from Leon4gr45/brain: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/Leon4gr45/brain/resolve/main/tests/test_connection_docs.py
- Command line
-
hf download hf://spaces/Leon4gr45/brain/tests/test_connection_docs.py
-
curl -L -o test_connection_docs.py https://huggingface.co/spaces/Leon4gr45/brain/resolve/main/tests/test_connection_docs.py
1.4 kB
| from unittest.mock import patch | |
| from fastapi import FastAPI | |
| from fastapi.testclient import TestClient | |
| from src.services.api.connection_docs import CONNECTION_GUIDE, connection_docs_router | |
| from src.services.api.middlewares.auth import BrainPATMiddleware | |
| from src.services.api.middlewares.brains import BrainMiddleware | |
| def test_public_guide_serves_committed_content_without_auth_or_brain_access(): | |
| app = FastAPI() | |
| app.include_router(connection_docs_router) | |
| app.add_middleware(BrainPATMiddleware) | |
| app.add_middleware(BrainMiddleware) | |
| with patch('src.services.api.middlewares.auth.get_auth_service', side_effect=AssertionError('auth touched')), \ | |
| patch('src.services.api.middlewares.brains.resolve_workspace_scope', side_effect=AssertionError('brain touched')): | |
| client = TestClient(app) | |
| response = client.get('/api-docs', follow_redirects=False) | |
| assert response.status_code == 200 | |
| assert response.text == CONNECTION_GUIDE.read_text() | |
| assert response.headers['content-type'].startswith('text/plain') | |
| assert response.headers['content-disposition'].startswith('inline;') | |
| assert response.headers['x-content-type-options'] == 'nosniff' | |
| head = client.head('/api-docs') | |
| assert head.status_code == 200 and head.content == b'' | |
| assert head.headers['content-length'] == response.headers['content-length'] | |