test_api.py 943 B

1234567891011121314151617181920212223242526272829303132
  1. """Test the basic /api endpoints"""
  2. import requests
  3. from notebook._tz import isoformat
  4. from notebook.utils import url_path_join
  5. from notebook.tests.launchnotebook import NotebookTestBase
  6. class KernelAPITest(NotebookTestBase):
  7. """Test the kernels web service API"""
  8. def _req(self, verb, path, **kwargs):
  9. r = self.request(verb, url_path_join('api', path))
  10. r.raise_for_status()
  11. return r
  12. def get(self, path, **kwargs):
  13. return self._req('GET', path)
  14. def test_get_spec(self):
  15. r = self.get('spec.yaml')
  16. assert r.text
  17. def test_get_status(self):
  18. r = self.get('status')
  19. data = r.json()
  20. assert data['connections'] == 0
  21. assert data['kernels'] == 0
  22. assert data['last_activity'].endswith('Z')
  23. assert data['started'].endswith('Z')
  24. assert data['started'] == isoformat(self.notebook.web_app.settings['started'])