Skip to content

Commit

Permalink
Replace curl by requests
Browse files Browse the repository at this point in the history
Replace the curl utility by the python requests library to avoid another
host-dependency.
  • Loading branch information
grisu48 committed Aug 17, 2023
1 parent 06fb816 commit 23f4c96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/test_nginx.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""This module contains the tests for the nginx container, the image with nginx pre-installed.
"""
from bci_tester.data import NGINX_CONTAINER

from tenacity import retry, wait_exponential, stop_after_attempt
import requests

CONTAINER_IMAGES = (NGINX_CONTAINER,)

Expand All @@ -10,6 +11,13 @@ def test_nginx_welcome_page(auto_container, host):
"""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 quadratic backoff delay
@retry(
wait=wait_exponential(multiplier=1, min=4, max=10),
stop=stop_after_attempt(5),
)
def check_reply():
resp = requests.get(f"http://localhost:{host_port}/", timeout=30)
resp.raise_for_status()
if "Welcome to nginx" not in resp.text:
raise ValueError("Invalid response")
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 23f4c96

Please sign in to comment.