Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add persistence settings test #66

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(3) # 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"