Skip to content

Commit b06f7d6

Browse files
committed
add tests for eventlog
1 parent ea9e352 commit b06f7d6

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

jupyter_server/event-schemas/contentsmanager-actions/v1.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"$id": eventlogging.jupyter.org/notebook/contentsmanager-actions
1+
"$id": eventlogging.jupyter.org/jupyter_server/contentsmanager-actions
22
version: 1
33
title: Contents Manager activities
44
personal-data: true
@@ -80,4 +80,4 @@ properties:
8080
category: personally-identifiable-information
8181
type: string
8282
description: |
83-
Source path of an operation when action is 'copy' or 'rename'
83+
Source path of an operation when action is 'copy' or 'rename'

tests/test_eventlog.py

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
1+
import io
2+
import json
3+
import logging
14

5+
import jsonschema
6+
import pytest
7+
from traitlets.config import Config
28

3-
def test_eventlog(serverapp):
4-
pass
9+
from jupyter_server.utils import eventlogging_schema_fqn
10+
from .services.contents.test_api import contents, contents_dir, dirs
11+
12+
13+
@pytest.fixture
14+
def eventlog_sink(configurable_serverapp):
15+
"""Return eventlog and sink objects"""
16+
sink = io.StringIO()
17+
handler = logging.StreamHandler(sink)
18+
19+
cfg = Config()
20+
cfg.EventLog.handlers = [handler]
21+
serverapp = configurable_serverapp(config=cfg)
22+
yield serverapp, sink
23+
24+
25+
@pytest.mark.parametrize('path, name', dirs)
26+
async def test_eventlog_list_notebooks(eventlog_sink, fetch, contents, path, name):
27+
schema, version = (eventlogging_schema_fqn('contentsmanager-actions'), 1)
28+
serverapp, sink = eventlog_sink
29+
serverapp.eventlog.allowed_schemas = [schema]
30+
31+
r = await fetch(
32+
'api',
33+
'contents',
34+
path,
35+
method='GET',
36+
)
37+
assert r.code == 200
38+
39+
output = sink.getvalue()
40+
assert output
41+
data = json.loads(output)
42+
jsonschema.validate(data, serverapp.eventlog.schemas[(schema, version)])
43+
expected = {'action': 'get', 'path': path}
44+
assert expected.items() <= data.items()

0 commit comments

Comments
 (0)