11# Copyright 2023 The MathWorks, Inc.
22
33# This file contains tests for jupyter_matlab_kernel.kernel
4- from jupyter_matlab_kernel .kernel import (
5- start_matlab_proxy ,
6- MATLABConnectionError ,
7- )
8-
4+ import mocks .mock_jupyter_server as MockJupyterServer
95import pytest
106from jupyter_server import serverapp
117from mocks .mock_jupyter_server import MockJupyterServerFixture
12- import mocks .mock_jupyter_server as MockJupyterServer
8+
9+ from jupyter_matlab_kernel .kernel import MATLABConnectionError , start_matlab_proxy
1310
1411
1512def test_start_matlab_proxy_without_jupyter_server ():
@@ -33,7 +30,7 @@ def test_start_matlab_proxy(MockJupyterServerFixture):
3330
3431 url , server , headers = start_matlab_proxy ()
3532 assert server == MockJupyterServer .BASE_URL
36- assert headers == MockJupyterServer .AUTHORISED_HEADERS
33+ assert headers == MockJupyterServer .AUTHORIZED_HEADERS
3734 expected_url = (
3835 "http://localhost:"
3936 + MockJupyterServer .PORT
@@ -73,15 +70,14 @@ def fake_list_running_servers(*args, **kwargs):
7370 assert url == expected_url
7471
7572
76- # TODO: Need to update usage of mock response in this test.
77- # def test_start_matlab_proxy_jh_api_token(monkeypatch, MockJupyterServerFixture):
78- # """
79- # The test checks that start_matlab_proxy makes use of the environment variable
80- # JUPYTERHUB_API_TOKEN if it is set.
81- # """
82-
83- # monkeypatch.setattr(MockJupyterServer, "TEST_TOKEN", None)
73+ def test_start_matlab_proxy_jh_api_token (monkeypatch , MockJupyterServerFixture ):
74+ """
75+ The test checks that start_matlab_proxy makes use of the environment variable
76+ JUPYTERHUB_API_TOKEN if it is set.
77+ """
78+ token = "test_jh_token"
79+ monkeypatch .setattr (MockJupyterServer , "TEST_TOKEN" , None )
8480
85- # monkeypatch.setenv("JUPYTERHUB_API_TOKEN", "test_jh_token" )
86- # _, _, headers = start_matlab_proxy()
87- # assert headers == {"Authorization": "token test_jh_token "}
81+ monkeypatch .setenv ("JUPYTERHUB_API_TOKEN" , token )
82+ _ , _ , headers = start_matlab_proxy ()
83+ assert headers == {"Authorization" : f "token { token } " }
0 commit comments