# 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 requests import Response
from ..utils import (
    CONTAINER_NAME,
    get_logs,
    get_nginx_config,
    get_response_text1,
    remove_previous_container,
)



client = docker.from_env()


def verify_container(container: Container, response_text: str) -> None:
    response: Response = requests.get("http://127.0.0.1:8000")
    assert response.text == response_text
    nginx_config = get_nginx_config(container)
    assert "client_max_body_size 0;" in nginx_config
    assert "worker_processes 1;" in nginx_config
    assert "listen 80;" in nginx_config
    assert "worker_connections 1024;" in nginx_config
    assert "worker_rlimit_nofile;" not in nginx_config
    assert "daemon off;" in nginx_config
    assert "include uwsgi_params;" in nginx_config
    assert "uwsgi_pass unix:///tmp/uwsgi.sock;" in nginx_config

# 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_defaults.py
import os
import time
import docker
import requests
from docker.models.containers import Container
from requests import Response
from ..utils import (
    CONTAINER_NAME,
    get_logs,
    get_nginx_config,
    get_response_text1,
    remove_previous_container,
)




client = docker.from_env()


def verify_container(container: Container, response_text: str) -> None:
    response: Response = requests.get("http://127.0.0.1:8000")
    assert response.text == response_text
    nginx_config = get_nginx_config(container)
    assert "client_max_body_size 0;" in nginx_config
    assert "worker_processes 1;" in nginx_config
    assert "listen 80;" in nginx_config
    assert "worker_connections 1024;" in nginx_config
    assert "worker_rlimit_nofile;" not in nginx_config
    assert "daemon off;" in nginx_config
    assert "include uwsgi_params;" in nginx_config
    assert "uwsgi_pass unix:///tmp/uwsgi.sock;" in nginx_config

    logs = get_logs(container)