File: test_api.py

package info (click to toggle)
jupyter-notebook 6.4.13-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,860 kB
  • sloc: javascript: 20,765; python: 15,658; makefile: 255; sh: 160
file content (47 lines) | stat: -rw-r--r-- 1,615 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Test the basic /api endpoints"""

from datetime import timedelta

from notebook._tz import isoformat, utcnow
from notebook.utils import url_path_join
from notebook.tests.launchnotebook import NotebookTestBase


class APITest(NotebookTestBase):
    """Test the kernels web service API"""

    def _req(self, verb, path, **kwargs):
        r = self.request(verb, url_path_join('api', path))
        r.raise_for_status()
        return r

    def get(self, path, **kwargs):
        return self._req('GET', path)

    def test_get_spec(self):
        r = self.get('spec.yaml')
        assert r.text

    def test_get_status(self):
        r = self.get('status')
        data = r.json()
        assert data['connections'] == 0
        assert data['kernels'] == 0
        assert data['last_activity'].endswith('Z')
        assert data['started'].endswith('Z')
        assert data['started'] == isoformat(self.notebook.web_app.settings['started'])

    def test_no_track_activity(self):
        # initialize with old last api activity
        old = utcnow() - timedelta(days=1)
        settings = self.notebook.web_app.settings
        settings['api_last_activity'] = old
        # accessing status doesn't update activity
        self.get('status')
        assert settings['api_last_activity'] == old
        # accessing with ?no_track_activity doesn't update activity
        self.get('contents?no_track_activity=1')
        assert settings['api_last_activity'] == old
        # accessing without ?no_track_activity does update activity
        self.get('contents')
        assert settings['api_last_activity'] > old