Better warnings

This commit is contained in:
Ayaz Salikhov
2022-01-22 09:17:26 +02:00
parent 77297fc332
commit e12ecdb67a
3 changed files with 13 additions and 20 deletions

View File

@@ -23,9 +23,7 @@ def test_cli_args(container: TrackedContainer, http_client: requests.Session) ->
logs = running_container.logs().decode("utf-8")
LOGGER.debug(logs)
assert "ERROR" not in logs
warnings = [
warning for warning in logs.split("\n") if warning.startswith("WARNING")
]
warnings = TrackedContainer.get_warnings(logs)
assert not warnings
assert "login_submit" not in resp.text
@@ -48,9 +46,7 @@ def test_unsigned_ssl(
assert "login_submit" in resp.text
logs = running_container.logs().decode("utf-8")
assert "ERROR" not in logs
warnings = [
warning for warning in logs.split("\n") if warning.startswith("WARNING")
]
warnings = TrackedContainer.get_warnings(logs)
assert not warnings
@@ -218,9 +214,7 @@ def test_group_add(container: TrackedContainer) -> None:
group_add=["users"], # Ensures write access to /home/jovyan
command=["start.sh", "id"],
)
warnings = [
warning for warning in logs.split("\n") if warning.startswith("WARNING")
]
warnings = TrackedContainer.get_warnings(logs)
assert len(warnings) == 1
assert "Try setting gid=0" in warnings[0]
assert "uid=1010 gid=1010 groups=1010,100(users)" in logs
@@ -239,9 +233,7 @@ def test_set_uid(container: TrackedContainer) -> None:
command=["start.sh", "id"],
)
assert "uid=1010(jovyan) gid=0(root)" in logs
warnings = [
warning for warning in logs.split("\n") if warning.startswith("WARNING")
]
warnings = TrackedContainer.get_warnings(logs)
assert len(warnings) == 1
assert "--group-add=users" in warnings[0]
@@ -257,9 +249,7 @@ def test_set_uid_and_nb_user(container: TrackedContainer) -> None:
command=["start.sh", "id"],
)
assert "uid=1010(kitten) gid=0(root)" in logs
warnings = [
warning for warning in logs.split("\n") if warning.startswith("WARNING")
]
warnings = TrackedContainer.get_warnings(logs)
assert len(warnings) == 1
assert "user is kitten but home is /home/jovyan" in warnings[0]

View File

@@ -5,7 +5,6 @@ import logging
from typing import Optional
import pytest
import requests
import re
import time
from conftest import TrackedContainer
@@ -65,10 +64,8 @@ def test_start_notebook(
assert "ERROR" not in logs, "ERROR(s) found in logs"
for exp_warning in expected_warnings:
assert exp_warning in logs, f"Expected warning {exp_warning} not found in logs"
warnings = re.findall(r"^WARNING", logs, flags=re.MULTILINE)
assert len(expected_warnings) == len(
warnings
), "Not found the number of expected warnings in logs"
warnings = TrackedContainer.get_warnings(logs)
assert len(expected_warnings) == len(warnings)
# checking if the server is listening
if expected_start:
resp = http_client.get("http://localhost:8888")

View File

@@ -107,6 +107,12 @@ class TrackedContainer:
assert rv == 0 or rv["StatusCode"] == 0
return logs
@staticmethod
def get_warnings(logs: str) -> list[str]:
return [
warning for warning in logs.split("\n") if warning.startswith("WARNING")
]
def remove(self):
"""Kills and removes the tracked docker container."""
if self.container: