Spaces:
Sleeping
Sleeping
Download tests/test_api_openapi.py from thanhnv2323/humanize-text-python: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/tests/test_api_openapi.py
- Command line
-
hf download hf://spaces/thanhnv2323/humanize-text-python/tests/test_api_openapi.py
-
curl -L -o test_api_openapi.py https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/tests/test_api_openapi.py
2.45 kB
| """OpenAPI contract checks for the public REST API surface.""" | |
| import pytest as pytest | |
| fastapi = pytest.importorskip('fastapi') | |
| unused_fastapi = fastapi | |
| API_PATHS = [ | |
| '/' 'health', | |
| '/v1/auth/register', | |
| '/v1/auth/validate', | |
| '/v1/personas', | |
| '/v1/personas/{persona_id}/profile', | |
| '/v1/personas/{persona_id}/system-prompt', | |
| '/v1/' 'chat', | |
| '/v1/ingestion/upload', | |
| '/v1/reports/{persona_id}', | |
| '/api/surveys', | |
| '/api/surveys/{survey_id}', | |
| '/api/groups', | |
| '/api/groups/countries', | |
| '/api/groups/{group_id}', | |
| '/api/surveys/{survey_id}/simulate', | |
| '/api/surveys/{survey_id}/responses', | |
| '/api/surveys/{survey_id}/statistics', | |
| ] | |
| def _build_app(): | |
| from adsp.app.api_server import create_app | |
| return create_app() | |
| def _schema() -> dict: | |
| app = _build_app() | |
| schema = app.openapi() | |
| assert isinstance(schema, dict) | |
| return schema | |
| def _paths() -> dict: | |
| schema = _schema() | |
| paths = schema.get('paths', {}) | |
| assert isinstance(paths, dict) | |
| return paths | |
| def test_schema_has_paths_block(): | |
| schema = _schema() | |
| assert 'paths' in schema | |
| assert isinstance(schema['paths'], dict) | |
| def test_paths_include_required_endpoints(): | |
| paths = _paths() | |
| required = set(API_PATHS) | |
| assert required.issubset(set(paths.keys())) | |
| def test_paths_include_core_endpoints(): | |
| paths = _paths() | |
| assert '/health' in paths | |
| assert '/v1/chat' in paths | |
| assert '/v1/personas' in paths | |
| def test_paths_use_string_keys(): | |
| paths = _paths() | |
| for path in paths: | |
| assert isinstance(path, str) | |
| assert path.startswith('/') | |
| def test_path_items_are_mappings(): | |
| paths = _paths() | |
| for path, item in paths.items(): | |
| assert isinstance(path, str) | |
| assert isinstance(item, dict) | |
| def test_schema_has_info_block(): | |
| schema = _schema() | |
| info = schema.get('info', {}) | |
| assert isinstance(info, dict) | |
| assert isinstance(info.get('title'), str) | |
| assert isinstance(info.get('version'), str) | |
| def test_schema_has_openapi_version(): | |
| schema = _schema() | |
| assert isinstance(schema.get('openapi'), str) | |
| def test_survey_and_group_paths_expose_get_and_post(): | |
| paths = _paths() | |
| assert 'get' in paths['/api/surveys'] | |
| assert 'post' in paths['/api/surveys'] | |
| assert 'get' in paths['/api/groups'] | |
| assert 'post' in paths['/api/groups'] | |
| assert 'get' in paths['/api/surveys/{survey_id}/statistics'] | |