From cd8bc0dfa50238a39feb65cc911c9e07ac7b8a8e Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 17 Mar 2023 11:20:28 +0100 Subject: [PATCH] move proxy fixture to conftest so it can be re-used --- tests/conftest.py | 31 +++++++++++++++++++++++++++++++ tests/test_proxy.py | 30 ------------------------------ tests/test_traefik_api_auth.py | 14 -------------- 3 files changed, 31 insertions(+), 44 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 14520c59..021f73e3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,7 @@ from tempfile import TemporaryDirectory import pytest +import utils from consul.aio import Consul from jupyterhub.utils import exponential_backoff from traitlets.log import get_logger @@ -288,6 +289,36 @@ async def auth_external_etcd_proxy( proxy.etcd.close() +@pytest.fixture( + params=[ + "no_auth_consul_proxy", + "auth_consul_proxy", + "no_auth_etcd_proxy", + "auth_etcd_proxy", + "file_proxy_toml", + "file_proxy_yaml", + "external_consul_proxy", + "auth_external_consul_proxy", + "external_etcd_proxy", + "auth_external_etcd_proxy", + "external_file_proxy_toml", + "external_file_proxy_yaml", + ] +) +def proxy(request): + """Parameterized fixture to run all the tests with every proxy implementation""" + proxy = request.getfixturevalue(request.param) + # wait for public endpoint to be reachable + asyncio.run( + exponential_backoff( + utils.check_host_up_http, + f"Proxy public url {proxy.public_url} cannot be reached", + url=proxy.public_url, + ) + ) + return proxy + + ######################################################################### # Fixtures for launching traefik, with each backend and with or without # # authentication # diff --git a/tests/test_proxy.py b/tests/test_proxy.py index 362c9789..17826b65 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -138,36 +138,6 @@ async def _launch_backends(n=1): proc.wait() -@pytest.fixture( - params=[ - "no_auth_consul_proxy", - "auth_consul_proxy", - "no_auth_etcd_proxy", - "auth_etcd_proxy", - "file_proxy_toml", - "file_proxy_yaml", - "external_consul_proxy", - "auth_external_consul_proxy", - "external_etcd_proxy", - "auth_external_etcd_proxy", - "external_file_proxy_toml", - "external_file_proxy_yaml", - ] -) -def proxy(request): - """Parameterized fixture to run all the tests with every proxy implementation""" - proxy = request.getfixturevalue(request.param) - # wait for public endpoint to be reachable - asyncio.run( - exponential_backoff( - utils.check_host_up_http, - f"Proxy public url {proxy.public_url} cannot be reached", - url=proxy.public_url, - ) - ) - return proxy - - async def wait_for_services(urls): # Wait until traefik and the backend are ready await exponential_backoff( diff --git a/tests/test_traefik_api_auth.py b/tests/test_traefik_api_auth.py index 8ef76038..1b1f0c97 100644 --- a/tests/test_traefik_api_auth.py +++ b/tests/test_traefik_api_auth.py @@ -7,20 +7,6 @@ pytestmark = pytest.mark.asyncio -@pytest.fixture( - params=[ - "file_proxy_toml", - "file_proxy_yaml", - "no_auth_etcd_proxy", - "auth_etcd_proxy", - "no_auth_consul_proxy", - "auth_consul_proxy", - ] -) -def proxy(request): - return request.getfixturevalue(request.param) - - @pytest.mark.parametrize( "username, password, expected_rc", [("api_admin", "admin", 200), ("api_admin", "1234", 401), ("", "", 401)],