Skip to content

Commit

Permalink
move proxy fixture to conftest
Browse files Browse the repository at this point in the history
so it can be re-used
  • Loading branch information
minrk committed Mar 17, 2023
1 parent 83f2260 commit cd8bc0d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 44 deletions.
31 changes: 31 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 #
Expand Down
30 changes: 0 additions & 30 deletions tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 0 additions & 14 deletions tests/test_traefik_api_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down

0 comments on commit cd8bc0d

Please sign in to comment.