1
1
# Copyright 2023 The MathWorks, Inc.
2
2
3
3
# 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
9
5
import pytest
10
6
from jupyter_server import serverapp
11
7
from 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
13
10
14
11
15
12
def test_start_matlab_proxy_without_jupyter_server ():
@@ -33,7 +30,7 @@ def test_start_matlab_proxy(MockJupyterServerFixture):
33
30
34
31
url , server , headers = start_matlab_proxy ()
35
32
assert server == MockJupyterServer .BASE_URL
36
- assert headers == MockJupyterServer .AUTHORISED_HEADERS
33
+ assert headers == MockJupyterServer .AUTHORIZED_HEADERS
37
34
expected_url = (
38
35
"http://localhost:"
39
36
+ MockJupyterServer .PORT
@@ -73,15 +70,14 @@ def fake_list_running_servers(*args, **kwargs):
73
70
assert url == expected_url
74
71
75
72
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 )
84
80
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