Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maresb committed Aug 2, 2020
1 parent d74f956 commit 6e5313a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/resources/jupyter_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def mappathf(path):
c.ServerProxy.servers = {
'python-http': {
'command': ['python3', './tests/resources/httpinfo.py', '{port}'],
'rewrite_response': lambda host, port, path, response: response.body.replace(b"ciao", b"hello")
},
'python-http-abs': {
'command': ['python3', './tests/resources/httpinfo.py', '{port}'],
Expand All @@ -29,6 +30,9 @@ def mappathf(path):
}
}

c.ServerProxy.non_service_rewrite_response = \
lambda host, port, path, response: response.body.replace(b"bar", b"foo")

import sys
sys.path.append('./tests/resources')
c.NotebookApp.nbserver_extensions = { 'proxyextension': True }
Expand Down
15 changes: 15 additions & 0 deletions tests/test_proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def test_server_proxy_minimal_proxy_path_encoding_complement():
assert 'GET /{}?token='.format(test_url) in s


def test_server_rewrite_response():
r = request_get(PORT, '/python-http/ciao-a-tutti', TOKEN)
assert r.code == 200
s = r.read().decode('ascii')
assert s.startswith('GET /hello-a-tutti?token=')


def test_server_proxy_non_absolute():
r = request_get(PORT, '/python-http/abc', TOKEN)
assert r.code == 200
Expand Down Expand Up @@ -92,6 +99,14 @@ def test_server_proxy_port_absolute():
assert 'X-Proxycontextpath' not in s


def test_server_proxy_port_non_service_rewrite_response():
"""Test that 'bar' is replaced by 'foo'."""
r = request_get(PORT, '/proxy/54321/baz-bar-foo', TOKEN)
assert r.code == 200
s = r.read().decode('ascii')
assert s.startswith('GET /baz-foo-foo?token=')


@pytest.mark.parametrize(
"requestpath,expected", [
('/', '/index.html?token='),
Expand Down

0 comments on commit 6e5313a

Please sign in to comment.