1
0

test_endpoint_docs.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from typing import Set
  2. import pytest
  3. import requests
  4. from nicegui import __version__, ui
  5. from nicegui.testing import Screen
  6. @pytest.fixture(autouse=True)
  7. def activate_fastapi_docs(screen: Screen):
  8. screen.ui_run_kwargs['fastapi_docs'] = True
  9. def get_openapi_paths() -> Set[str]:
  10. return set(requests.get(f'http://localhost:{Screen.PORT}/openapi.json', timeout=5).json()['paths'])
  11. def test_endpoint_documentation_default(screen: Screen):
  12. screen.open('/')
  13. assert get_openapi_paths() == set()
  14. def test_endpoint_documentation_page_only(screen: Screen):
  15. screen.ui_run_kwargs['endpoint_documentation'] = 'page'
  16. screen.open('/')
  17. assert get_openapi_paths() == {'/'}
  18. def test_endpoint_documentation_internal_only(screen: Screen):
  19. screen.ui_run_kwargs['endpoint_documentation'] = 'internal'
  20. ui.markdown('Hey!')
  21. screen.open('/')
  22. assert get_openapi_paths() == {
  23. f'/_nicegui/{__version__}/codehilite.css',
  24. f'/_nicegui/{__version__}/libraries/{{key}}',
  25. f'/_nicegui/{__version__}/components/{{key}}',
  26. f'/_nicegui/{__version__}/resources/{{key}}/{{path}}',
  27. }
  28. def test_endpoint_documentation_all(screen: Screen):
  29. screen.ui_run_kwargs['endpoint_documentation'] = 'all'
  30. ui.markdown('Hey!')
  31. screen.open('/')
  32. assert get_openapi_paths() == {
  33. '/',
  34. f'/_nicegui/{__version__}/codehilite.css',
  35. f'/_nicegui/{__version__}/libraries/{{key}}',
  36. f'/_nicegui/{__version__}/components/{{key}}',
  37. f'/_nicegui/{__version__}/resources/{{key}}/{{path}}',
  38. }