# Path: tests/utils.py
# CONTAINER_NAME = "uwsgi-nginx-test"
# 
# def get_logs(container: Container) -> str:
#     logs = container.logs()
#     return logs.decode("utf-8")
# 
# def get_nginx_config(container: Container) -> str:
#     result = container.exec_run(f"/usr/sbin/nginx -T")
#     return result.output.decode()
# 
# def get_response_text1() -> str:
#     python_version = os.getenv("PYTHON_VERSION")
#     return f"Hello World from a default Nginx uWSGI Python {python_version} app in a Docker container (default)"
# 
# def remove_previous_container(client: DockerClient) -> None:
#     try:
#         previous = client.containers.get(CONTAINER_NAME)
#         previous.stop()
#         previous.remove()
#     except NotFound:
#         return None


import os
import time
import docker
import requests
from docker.models.containers import Container
from ..utils import (
    CONTAINER_NAME,
    get_logs,
    get_nginx_config,
    get_response_text1,
    remove_previous_container,
)
    assert "hook-master-start = unix_signal:15 gracefully_kill_them_all" in logs
    assert "need-app = true" in logs
    assert "die-on-term = true" in logs
    assert "show-config = true" in logs
    assert "wsgi-file = /app/main.py" in logs
    assert "processes = 8" in logs
    assert "cheaper = 3" in logs
    assert "Checking for script in /app/prestart.sh" in logs
    assert "Running script /app/prestart.sh" in logs
    assert (
        "Running inside /app/prestart.sh, you could add migrations to this file" in logs
    )
    assert "spawned uWSGI master process" in logs
    assert "spawned uWSGI worker 1" in logs
    assert "spawned uWSGI worker 2" in logs
    assert "spawned uWSGI worker 3" in logs
    assert "spawned uWSGI worker 4" not in logs
    assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs
    assert "success: nginx entered RUNNING state, process has stayed up for" in logs
    assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs


def test_env_vars_1() -> None:
    name = os.getenv("NAME")
    image = f"tiangolo/uwsgi-nginx:{name}"
    response_text = get_response_text1()
    sleep_time = int(os.getenv("SLEEP_TIME", 3))
    remove_previous_container(client)
    container = client.containers.run(
        image,

# Path: tests/utils.py
# CONTAINER_NAME = "uwsgi-nginx-test"
# 
# def get_logs(container: Container) -> str:
#     logs = container.logs()
#     return logs.decode("utf-8")
# 
# def get_nginx_config(container: Container) -> str:
#     result = container.exec_run(f"/usr/sbin/nginx -T")
#     return result.output.decode()
# 
# def get_response_text1() -> str:
#     python_version = os.getenv("PYTHON_VERSION")
#     return f"Hello World from a default Nginx uWSGI Python {python_version} app in a Docker container (default)"
# 
# def remove_previous_container(client: DockerClient) -> None:
#     try:
#         previous = client.containers.get(CONTAINER_NAME)
#         previous.stop()
#         previous.remove()
#     except NotFound:
#         return None


# Path: tests/test_01_main/test_env_vars_1.py
import os
import time
import docker
import requests
from docker.models.containers import Container
from ..utils import (
    CONTAINER_NAME,
    get_logs,
    get_nginx_config,
    get_response_text1,
    remove_previous_container,
)

    assert "hook-master-start = unix_signal:15 gracefully_kill_them_all" in logs
    assert "need-app = true" in logs
    assert "die-on-term = true" in logs
    assert "show-config = true" in logs
    assert "wsgi-file = /app/main.py" in logs
    assert "processes = 8" in logs
    assert "cheaper = 3" in logs
    assert "Checking for script in /app/prestart.sh" in logs
    assert "Running script /app/prestart.sh" in logs
    assert (
        "Running inside /app/prestart.sh, you could add migrations to this file" in logs
    )
    assert "spawned uWSGI master process" in logs
    assert "spawned uWSGI worker 1" in logs
    assert "spawned uWSGI worker 2" in logs
    assert "spawned uWSGI worker 3" in logs
    assert "spawned uWSGI worker 4" not in logs
    assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs
    assert "success: nginx entered RUNNING state, process has stayed up for" in logs
    assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs


def test_env_vars_1() -> None:
    name = os.getenv("NAME")
    image = f"tiangolo/uwsgi-nginx:{name}"
    response_text = get_response_text1()
    sleep_time = int(os.getenv("SLEEP_TIME", 3))
    remove_previous_container(client)
    container = client.containers.run(
        image,

        name=CONTAINER_NAME,