Skip to content

Commit

Permalink
Add tests for arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi committed Sep 10, 2022
1 parent 2eb2e62 commit 0e460ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 1 addition & 4 deletions jupyter_server/gateway/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,7 @@ def launch_timeout_pad_default(self):
@default("accept_cookies")
def accept_cookies_default(self):
return bool(
os.environ.get(
self.accept_cookies_env,
str(self.accept_cookies_value).lower(),
)
os.environ.get(self.accept_cookies_env, str(self.accept_cookies_value).lower())
not in ["no", "false"]
)

Expand Down
22 changes: 15 additions & 7 deletions tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def init_gateway(monkeypatch):
monkeypatch.setenv("JUPYTER_GATEWAY_REQUEST_TIMEOUT", "44.4")
monkeypatch.setenv("JUPYTER_GATEWAY_CONNECT_TIMEOUT", "44.4")
monkeypatch.setenv("JUPYTER_GATEWAY_LAUNCH_TIMEOUT_PAD", "1.1")
monkeypatch.setenv("JUPYTER_GATEWAY_ACCEPT_COOKIES", "false")
yield
GatewayClient.clear_instance()

Expand All @@ -202,6 +203,7 @@ async def test_gateway_env_options(init_gateway, jp_serverapp):
)
assert jp_serverapp.gateway_config.connect_timeout == 44.4
assert jp_serverapp.gateway_config.launch_timeout_pad == 1.1
assert jp_serverapp.gateway_config.accept_cookies is False

GatewayClient.instance().init_static_args()
assert GatewayClient.instance().KERNEL_LAUNCH_TIMEOUT == 43
Expand Down Expand Up @@ -265,17 +267,23 @@ async def test_gateway_request_timeout_pad_option(


@pytest.mark.parametrize(
"expire_arg,expire_param,existing_cookies,cookie_expired",
"accept_cookies,expire_arg,expire_param,existing_cookies,cookie_exists",
[
(None, None, "EXISTING=1", False),
("Expires", cookie_expire_time, None, False),
("Max-Age", "-360", "EXISTING=1", True),
(False, None, None, "EXISTING=1", False),
(True, None, None, "EXISTING=1", True),
(True, "Expires", cookie_expire_time, None, True),
(True, "Max-Age", "-360", "EXISTING=1", False),
],
)
async def test_gateway_request_with_expiring_cookies(
jp_configurable_serverapp, expire_arg, expire_param, existing_cookies, cookie_expired
jp_configurable_serverapp,
accept_cookies,
expire_arg,
expire_param,
existing_cookies,
cookie_exists,
):
argv = ["--GatewayClient.accept_cookies=true"]
argv = [f"--GatewayClient.accept_cookies={accept_cookies}"]

GatewayClient.clear_instance()
jp_configurable_serverapp(argv=argv)
Expand All @@ -292,7 +300,7 @@ async def test_gateway_request_with_expiring_cookies(
args["headers"] = {"Cookie": existing_cookies}
connection_args = GatewayClient.instance().load_connection_args(**args)

if cookie_expired:
if not cookie_exists:
assert "SERVERID" not in (connection_args["headers"].get("Cookie") or "")
else:
assert "SERVERID" in connection_args["headers"].get("Cookie")
Expand Down

0 comments on commit 0e460ba

Please sign in to comment.