mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 07:23:00 +00:00
test custom hub routespecs
This commit is contained in:
@@ -905,8 +905,7 @@ class JupyterHub(Application):
|
|||||||
routespec = routespec + "/"
|
routespec = routespec + "/"
|
||||||
if not self.subdomain_host and not routespec.startswith("/"):
|
if not self.subdomain_host and not routespec.startswith("/"):
|
||||||
routespec = "/" + routespec
|
routespec = "/" + routespec
|
||||||
if routespec != proposal.value:
|
return routespec
|
||||||
return routespec
|
|
||||||
|
|
||||||
@observe("hub_routespec")
|
@observe("hub_routespec")
|
||||||
def _hub_routespec_changed(self, change):
|
def _hub_routespec_changed(self, change):
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
"""Test the JupyterHub entry point"""
|
"""Test the JupyterHub entry point"""
|
||||||
import binascii
|
import binascii
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@@ -329,3 +330,41 @@ def test_url_config(hub_config, expected):
|
|||||||
# validate additional properties
|
# validate additional properties
|
||||||
for key, value in expected.items():
|
for key, value in expected.items():
|
||||||
assert getattr(app, key) == value
|
assert getattr(app, key) == value
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"base_url, hub_routespec, expected_routespec, should_warn, bad_prefix",
|
||||||
|
[
|
||||||
|
(None, None, "/", False, False),
|
||||||
|
("/", "/", "/", False, False),
|
||||||
|
("/base", "/base", "/base/", False, False),
|
||||||
|
("/", "/hub", "/hub/", True, False),
|
||||||
|
(None, "hub/api", "/hub/api/", True, False),
|
||||||
|
("/base", "/hub/", "/hub/", True, True),
|
||||||
|
(None, "/hub/api/health", "/hub/api/health/", True, True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_hub_routespec(
|
||||||
|
base_url, hub_routespec, expected_routespec, should_warn, bad_prefix, caplog
|
||||||
|
):
|
||||||
|
cfg = Config()
|
||||||
|
if base_url:
|
||||||
|
cfg.JupyterHub.base_url = base_url
|
||||||
|
if hub_routespec:
|
||||||
|
cfg.JupyterHub.hub_routespec = hub_routespec
|
||||||
|
with caplog.at_level(logging.WARNING):
|
||||||
|
app = JupyterHub(config=cfg, log=logging.getLogger())
|
||||||
|
app.init_hub()
|
||||||
|
hub = app.hub
|
||||||
|
assert hub.routespec == expected_routespec
|
||||||
|
|
||||||
|
if should_warn:
|
||||||
|
assert "custom route for Hub" in caplog.text
|
||||||
|
assert hub_routespec in caplog.text
|
||||||
|
else:
|
||||||
|
assert "custom route for Hub" not in caplog.text
|
||||||
|
|
||||||
|
if bad_prefix:
|
||||||
|
assert "may not receive" in caplog.text
|
||||||
|
else:
|
||||||
|
assert "may not receive" not in caplog.text
|
||||||
|
Reference in New Issue
Block a user