test_endpoint_docs.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from typing import Set
  2. import requests
  3. from nicegui import __version__
  4. from nicegui.testing import Screen
  5. def get_openapi_paths() -> Set[str]:
  6. return set(requests.get(f'http://localhost:{Screen.PORT}/openapi.json', timeout=5).json()['paths'])
  7. def test_endpoint_documentation_default(screen: Screen):
  8. screen.open('/')
  9. assert get_openapi_paths() == set()
  10. def test_endpoint_documentation_page_only(screen: Screen):
  11. screen.ui_run_kwargs['endpoint_documentation'] = 'page'
  12. screen.open('/')
  13. assert get_openapi_paths() == {'/'}
  14. def test_endpoint_documentation_internal_only(screen: Screen):
  15. screen.ui_run_kwargs['endpoint_documentation'] = 'internal'
  16. screen.open('/')
  17. assert get_openapi_paths() == {
  18. f'/_nicegui/{__version__}/libraries/{{key}}',
  19. f'/_nicegui/{__version__}/components/{{key}}',
  20. f'/_nicegui/{__version__}/resources/{{key}}/{{path}}',
  21. }
  22. def test_endpoint_documentation_all(screen: Screen):
  23. screen.ui_run_kwargs['endpoint_documentation'] = 'all'
  24. screen.open('/')
  25. assert get_openapi_paths() == {
  26. '/',
  27. f'/_nicegui/{__version__}/libraries/{{key}}',
  28. f'/_nicegui/{__version__}/components/{{key}}',
  29. f'/_nicegui/{__version__}/resources/{{key}}/{{path}}',
  30. }