Use formatted strings

Co-authored-by: Erik Sundell <erik.i.sundell@gmail.com>
This commit is contained in:
Ayaz Salikhov
2022-02-14 14:49:16 +03:00
committed by GitHub
parent 5ebb4bd0f2
commit c89d5ac623
4 changed files with 5 additions and 4 deletions

View File

@@ -20,7 +20,7 @@ def test_cli_args(container: TrackedContainer, http_client: requests.Session) ->
ports={"8888/tcp": None}, ports={"8888/tcp": None},
) )
host_port = container.get_host_port("8888/tcp") host_port = container.get_host_port("8888/tcp")
resp = http_client.get("http://localhost:" + host_port) resp = http_client.get(f"http://localhost:{host_port}")
resp.raise_for_status() resp.raise_for_status()
logs = running_container.logs().decode("utf-8") logs = running_container.logs().decode("utf-8")
LOGGER.debug(logs) LOGGER.debug(logs)
@@ -47,7 +47,7 @@ def test_unsigned_ssl(
# abort the retry logic. Forcing a long sleep for the moment until I have # abort the retry logic. Forcing a long sleep for the moment until I have
# time to dig more. # time to dig more.
time.sleep(5) time.sleep(5)
resp = http_client.get("https://localhost:" + host_port, verify=False) resp = http_client.get(f"https://localhost:{host_port}", verify=False)
resp.raise_for_status() resp.raise_for_status()
assert "login_submit" in resp.text assert "login_submit" in resp.text
logs = running_container.logs().decode("utf-8") logs = running_container.logs().decode("utf-8")

View File

@@ -70,7 +70,7 @@ def test_start_notebook(
# checking if the server is listening # checking if the server is listening
if expected_start: if expected_start:
host_port = container.get_host_port("8888/tcp") host_port = container.get_host_port("8888/tcp")
resp = http_client.get("http://localhost:" + host_port) resp = http_client.get(f"http://localhost:{host_port}")
assert resp.status_code == 200, "Server is not listening" assert resp.status_code == 200, "Server is not listening"

View File

@@ -109,6 +109,7 @@ class TrackedContainer:
return logs return logs
def get_host_port(self, container_port: str) -> str: def get_host_port(self, container_port: str) -> str:
"""Returns the host port associated with the tracked container's port."""
assert isinstance(self.container, Container) assert isinstance(self.container, Container)
self.container.reload() self.container.reload()
return self.container.attrs["NetworkSettings"]["Ports"][container_port][0][ return self.container.attrs["NetworkSettings"]["Ports"][container_port][0][

View File

@@ -12,6 +12,6 @@ def test_secured_server(
"""Notebook server should eventually request user login.""" """Notebook server should eventually request user login."""
container.run_detached(ports={"8888/tcp": None}) container.run_detached(ports={"8888/tcp": None})
host_port = container.get_host_port("8888/tcp") host_port = container.get_host_port("8888/tcp")
resp = http_client.get("http://localhost:" + host_port) resp = http_client.get(f"http://localhost:{host_port}")
resp.raise_for_status() resp.raise_for_status()
assert "login_submit" in resp.text, "User login not requested" assert "login_submit" in resp.text, "User login not requested"