Skip to content

Commit 6ee5bc2

Browse files
committed
test ?no_track_activity=1 tracking
1 parent 91afb1e commit 6ee5bc2

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
"""Test the basic /api endpoints"""
22

3-
import requests
3+
from datetime import timedelta
44

5-
from notebook._tz import isoformat
5+
from notebook._tz import isoformat, utcnow
66
from notebook.utils import url_path_join
77
from notebook.tests.launchnotebook import NotebookTestBase
88

99

10-
class KernelAPITest(NotebookTestBase):
10+
class APITest(NotebookTestBase):
1111
"""Test the kernels web service API"""
12-
12+
1313
def _req(self, verb, path, **kwargs):
1414
r = self.request(verb, url_path_join('api', path))
1515
r.raise_for_status()
1616
return r
17-
17+
1818
def get(self, path, **kwargs):
1919
return self._req('GET', path)
20-
20+
2121
def test_get_spec(self):
2222
r = self.get('spec.yaml')
2323
assert r.text
24-
24+
2525
def test_get_status(self):
2626
r = self.get('status')
2727
data = r.json()
@@ -30,3 +30,18 @@ def test_get_status(self):
3030
assert data['last_activity'].endswith('Z')
3131
assert data['started'].endswith('Z')
3232
assert data['started'] == isoformat(self.notebook.web_app.settings['started'])
33+
34+
def test_no_track_activity(self):
35+
# initialize with old last api activity
36+
old = utcnow() - timedelta(days=1)
37+
settings = self.notebook.web_app.settings
38+
settings['api_last_activity'] = old
39+
# accessing status doesn't update activity
40+
self.get('status')
41+
assert settings['api_last_activity'] == old
42+
# accessing with ?no_track_activity doesn't update activity
43+
self.get('contents?no_track_activity=1')
44+
assert settings['api_last_activity'] == old
45+
# accessing without ?no_track_activity does update activity
46+
self.get('contents')
47+
assert settings['api_last_activity'] > old

0 commit comments

Comments
 (0)