Skip to content

Commit

Permalink
Add persistence settings test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 22, 2021
1 parent c8eb062 commit a7d377a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from uuid import uuid4
import socket
import subprocess
import time

import pytest

Expand Down Expand Up @@ -34,3 +37,29 @@ def authenticated_user(client):
response = client.get("/auth/users/me")
assert response.status_code != 401
return username


def get_open_port():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 0))
s.listen(1)
port = str(s.getsockname()[1])
s.close()
return port


@pytest.fixture()
def start_jupyverse(auth_mode, clear_users):
port = get_open_port()
command_list = [
"jupyverse",
"--no-open-browser",
f"--authenticator.mode={auth_mode}",
"--authenticator.clear_users=" + str(clear_users).lower(),
f"--port={port}",
]
p = subprocess.Popen(command_list)
url = f"http://127.0.0.1:{port}"
time.sleep(2) # let the server start up
yield url
p.kill()
26 changes: 26 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json

import requests
import pytest


@pytest.mark.parametrize("auth_mode", ("noauth",))
@pytest.mark.parametrize("clear_users", (True,))
def test_settings_persistence_put(start_jupyverse):
url = start_jupyverse
response = requests.put(
url + "/lab/api/settings/@jupyterlab/apputils-extension:themes",
data='{"raw":"my_settings"}',
)
assert response.status_code == 204


@pytest.mark.parametrize("auth_mode", ("noauth",))
@pytest.mark.parametrize("clear_users", (False,))
def test_settings_persistence_get(start_jupyverse):
url = start_jupyverse
response = requests.get(
url + "/lab/api/settings/@jupyterlab/apputils-extension:themes",
)
assert response.status_code == 200
assert json.loads(response.content)["raw"] == "my_settings"

0 comments on commit a7d377a

Please sign in to comment.