Skip to content

Commit 4f7d49c

Browse files
committed
Test mappath
1 parent 4b4dbe2 commit 4f7d49c

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

tests/resources/jupyter_server_config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
def mappathf(path):
2+
p = path + 'mapped'
3+
return p
4+
15
c.ServerProxy.servers = {
26
'python-http': {
37
'command': ['python3', './tests/resources/httpinfo.py', '{port}'],
@@ -10,9 +14,15 @@
1014
'command': ['python3', './tests/resources/httpinfo.py', '{port}'],
1115
'port': 54321,
1216
},
13-
'python-http-indexpage': {
17+
'python-http-mappath': {
18+
'command': ['python3', './tests/resources/httpinfo.py', '{port}'],
19+
'mappath': {
20+
'/': '/index.html',
21+
}
22+
},
23+
'python-http-mappathf': {
1424
'command': ['python3', './tests/resources/httpinfo.py', '{port}'],
15-
'indexpage': 'index.html',
25+
'mappath': mappathf,
1626
},
1727
}
1828

tests/test_proxies.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import os
22
from http.client import HTTPConnection
3+
import pytest
34

45
PORT = os.getenv('TEST_PORT', 8888)
56
TOKEN = os.getenv('JUPYTER_TOKEN', 'secret')
67

78

89
def request_get(port, path, token, host='localhost'):
910
h = HTTPConnection(host, port, 10)
10-
h.request('GET', '{}?token={}'.format(path, token))
11+
if '?' in path:
12+
url = '{}&token={}'.format(path, token)
13+
else:
14+
url = '{}?token={}'.format(path, token)
15+
h.request('GET', url)
1116
return h.getresponse()
1217

1318

@@ -59,22 +64,36 @@ def test_server_proxy_port_absolute():
5964
assert 'X-Proxycontextpath' not in s
6065

6166

62-
def test_server_proxy_indexpage_index():
63-
r = request_get(PORT, '/python-http-indexpage/', TOKEN)
67+
@pytest.mark.parametrize(
68+
"requestpath,expected", [
69+
('/', '/index.html?token='),
70+
('/?q=1', '/index.html?q=1&token='),
71+
('/pqr?q=2', '/pqr?q=2&token='),
72+
]
73+
)
74+
def test_server_proxy_mappath_dict(requestpath, expected):
75+
r = request_get(PORT, '/python-http-mappath' + requestpath, TOKEN)
6476
assert r.code == 200
6577
s = r.read().decode('ascii')
66-
assert s.startswith('GET /index.html?token=')
67-
assert 'X-Forwarded-Context: /python-http-indexpage\n' in s
68-
assert 'X-Proxycontextpath: /python-http-indexpage\n' in s
69-
70-
71-
def test_server_proxy_indexpage_other():
72-
r = request_get(PORT, '/python-http-indexpage/pqr', TOKEN)
78+
assert s.startswith('GET ' + expected)
79+
assert 'X-Forwarded-Context: /python-http-mappath\n' in s
80+
assert 'X-Proxycontextpath: /python-http-mappath\n' in s
81+
82+
83+
@pytest.mark.parametrize(
84+
"requestpath,expected", [
85+
('/', '/mapped?token='),
86+
('/?q=1', '/mapped?q=1&token='),
87+
('/stu?q=2', '/stumapped?q=2&token='),
88+
]
89+
)
90+
def test_server_proxy_mappath_callable(requestpath, expected):
91+
r = request_get(PORT, '/python-http-mappathf' + requestpath, TOKEN)
7392
assert r.code == 200
7493
s = r.read().decode('ascii')
75-
assert s.startswith('GET /pqr?token=')
76-
assert 'X-Forwarded-Context: /python-http-indexpage\n' in s
77-
assert 'X-Proxycontextpath: /python-http-indexpage\n' in s
94+
assert s.startswith('GET ' + expected)
95+
assert 'X-Forwarded-Context: /python-http-mappathf\n' in s
96+
assert 'X-Proxycontextpath: /python-http-mappathf\n' in s
7897

7998

8099
def test_server_proxy_remote():

0 commit comments

Comments
 (0)