diff --git a/tests/conftest.py b/tests/conftest.py index a18089ca..ccc1f619 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,7 @@ from uuid import uuid4 +import socket +import subprocess +import time import pytest @@ -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() diff --git a/tests/test_server.py b/tests/test_server.py new file mode 100644 index 00000000..ae67709d --- /dev/null +++ b/tests/test_server.py @@ -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"