From 58970ea4f2fc850687ee3a7552199edb9859804a Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 17 Aug 2023 15:59:13 +0200 Subject: [PATCH] Replace curl by requests Replace the curl utility by the python requests library to avoid another host-dependency. --- tests/test_nginx.py | 20 ++++++++++++++++---- tox.ini | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/test_nginx.py b/tests/test_nginx.py index 76bb5278..aba1129c 100644 --- a/tests/test_nginx.py +++ b/tests/test_nginx.py @@ -1,15 +1,27 @@ """This module contains the tests for the nginx container, the image with nginx pre-installed. """ -from bci_tester.data import NGINX_CONTAINER +import requests +from tenacity import retry +from tenacity import stop_after_attempt +from tenacity import wait_exponential +from bci_tester.data import NGINX_CONTAINER CONTAINER_IMAGES = (NGINX_CONTAINER,) -def test_nginx_welcome_page(auto_container, host): +def test_nginx_welcome_page(auto_container): """test that the default welcome page is served by the container.""" host_port = auto_container.forwarded_ports[0].host_port - assert "Welcome to nginx" in host.check_output( - f"curl -sf --retry 5 --retry-connrefused http://localhost:{host_port}/" + # Retry 5 times with exponential backoff delay + @retry( + wait=wait_exponential(multiplier=1, min=4, max=10), + stop=stop_after_attempt(5), ) + def check_nginx_response(): + resp = requests.get(f"http://localhost:{host_port}/", timeout=30) + resp.raise_for_status() + assert "Welcome to nginx" in resp.text + + check_nginx_response() diff --git a/tox.ini b/tox.ini index 290d1370..3331e91e 100644 --- a/tox.ini +++ b/tox.ini @@ -11,6 +11,8 @@ deps = dataclasses ; python_version < "3.7" pytest-rerunfailures typing_extensions + requests + tenacity git+https://github.com/dcermak/pytest_container doc: Sphinx