From 6e5313a2a6aece8073efc9753adf0538c83c0977 Mon Sep 17 00:00:00 2001 From: Ben Mares <15216687+maresb@users.noreply.github.com> Date: Sun, 2 Aug 2020 20:15:48 +0200 Subject: [PATCH] Add tests --- tests/resources/jupyter_server_config.py | 4 ++++ tests/test_proxies.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tests/resources/jupyter_server_config.py b/tests/resources/jupyter_server_config.py index 8005cde5..c3d5eb52 100644 --- a/tests/resources/jupyter_server_config.py +++ b/tests/resources/jupyter_server_config.py @@ -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}'], @@ -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 } diff --git a/tests/test_proxies.py b/tests/test_proxies.py index 746b3cde..d6f5dfec 100644 --- a/tests/test_proxies.py +++ b/tests/test_proxies.py @@ -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 @@ -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='),