Skip to content

Commit

Permalink
Prefix fixtures to prevent conflicts until pytest-dev/pytest#3966 is …
Browse files Browse the repository at this point in the history
…resolved.
  • Loading branch information
crashvb committed Feb 1, 2022
1 parent df1b786 commit 9ce2cb1
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 181 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ $ python -m pip install --editable .[dev]

## <a name="fixtures"></a>Fixtures

### <a name="docker_compose_insecure"></a> docker_compose_insecure

This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-haproxy-insecure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure docker haproxy service. The configuration will be treated as a template; the <tt>$PATH_HAPROXYCFG</tt> token will be populated with the absolute path provided by the [haproxy_haproxycfg](#haproxy_haproxycfg) fixture.

### <a name="docker_compose_secure"></a> docker_compose_secure

This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-haproxy-secure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure docker haproxy service. The configuration will be treated as a template; the <tt>$PATH_CERTIFICATE</tt>, <tt>$PATH_HAPROXYCFG</tt>, and <tt>$PATH_KEY</tt> tokens will be populated with the absolute paths provided by the [haproxy_certs](#haproxy_certs) and [haproxy_haproxycfg](#haproxy_haproxycfg) fixtures, as appropriate.

### <a name="haproxy_auth_header"></a> haproxy_auth_header

Retrieves an HTTP basic authentication header that is populated with credentials that can access the secure docker haproxy service. The credentials are retrieved from the [haproxy_password](#haproxy_password) and [haproxy_username](#haproxy_username) fixtures. This fixture is used to replicate docker images into the secure docker haproxy service.
Expand Down Expand Up @@ -165,6 +157,14 @@ Provides an SSL context containing the CA trust store from the [haproxy_cacerts

Provides a generated username to use for authentication to the secure docker haproxy service. This fixture is used to replicate docker images into the secure docker haproxy service.

### <a name="pdhf_docker_compose_insecure"></a> pdhf_docker_compose_insecure

This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-haproxy-insecure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure docker haproxy service. The configuration will be treated as a template; the <tt>$PATH_HAPROXYCFG</tt> token will be populated with the absolute path provided by the [haproxy_haproxycfg](#haproxy_haproxycfg) fixture.

### <a name="pdhf_docker_compose_secure"></a> pdhf_docker_compose_secure

This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-haproxy-secure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure docker haproxy service. The configuration will be treated as a template; the <tt>$PATH_CERTIFICATE</tt>, <tt>$PATH_HAPROXYCFG</tt>, and <tt>$PATH_KEY</tt> tokens will be populated with the absolute paths provided by the [haproxy_certs](#haproxy_certs) and [haproxy_haproxycfg](#haproxy_haproxycfg) fixtures, as appropriate.

## <a name="enumerated_fixtures"></a>Enumerated Fixtures

It is possible to instantiate multiple haproxy instances using the corresponding enumerated fixtures. All [fixtures](#fixtures) listed above have _*_list_ (e.g. `haproxy_secure` -> `haproxy_secure_list`) versions that will return enumerated lists of corresponding data type.
Expand Down
2 changes: 1 addition & 1 deletion pytest_docker_haproxy_fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

from .fixtures import *

__version__ = "0.1.3.dev0"
__version__ = "0.2.0.dev0"
280 changes: 140 additions & 140 deletions pytest_docker_haproxy_fixtures/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,136 +70,6 @@ class HAProxySecure(NamedTuple):
username: str


def _docker_compose_insecure(
*,
docker_compose_files: List[str],
scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure haproxy service.
"""
cache_key = _docker_compose_insecure.__name__
result = CACHE.get(cache_key, [])
for i in range(scale_factor):
if i < len(result):
continue

service_name = HAPROXY_SERVICE_PATTERN.format("insecure", i)
chain = itertools.chain(
get_docker_compose_user_defined(docker_compose_files, service_name),
# TODO: lovely-docker-compose uses the file for teardown ...
get_embedded_file(
tmp_path_factory, delete_after=False, name="docker-compose.yml"
),
)
for path in chain:
result.append(path)
break
else:
LOGGER.warning("Unable to find docker compose for: %s", service_name)
result.append("-unknown-")
CACHE[cache_key] = result
yield result


@pytest.fixture(scope="session")
def docker_compose_insecure(
docker_compose_files: List[str], tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure haproxy service.
"""
for lst in _docker_compose_insecure(
docker_compose_files=docker_compose_files,
scale_factor=1,
tmp_path_factory=tmp_path_factory,
):
yield lst[0]


@pytest.fixture(scope="session")
def docker_compose_insecure_list(
docker_compose_files: List[str],
pdhf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure haproxy service.
"""
yield from _docker_compose_insecure(
docker_compose_files=docker_compose_files,
scale_factor=pdhf_scale_factor,
tmp_path_factory=tmp_path_factory,
)


def _docker_compose_secure(
*,
docker_compose_files: List[str],
scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure haproxy
service.
"""
cache_key = _docker_compose_secure.__name__
result = CACHE.get(cache_key, [])
for i in range(scale_factor):
if i < len(result):
continue

service_name = HAPROXY_SERVICE_PATTERN.format("secure", i)
chain = itertools.chain(
get_docker_compose_user_defined(docker_compose_files, service_name),
get_embedded_file(
tmp_path_factory, delete_after=False, name="docker-compose.yml"
),
)
for path in chain:
result.append(path)
break
else:
LOGGER.warning("Unable to find docker compose for: %s", service_name)
result.append("-unknown-")
CACHE[cache_key] = result
yield result


@pytest.fixture(scope="session")
def docker_compose_secure(
docker_compose_files: List[str], tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure haproxy
service.
"""
for lst in _docker_compose_secure(
docker_compose_files=docker_compose_files,
scale_factor=1,
tmp_path_factory=tmp_path_factory,
):
yield lst[0]


@pytest.fixture(scope="session")
def docker_compose_secure_list(
docker_compose_files: List[str],
pdhf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure haproxy
service.
"""
yield from _docker_compose_secure(
docker_compose_files=docker_compose_files,
scale_factor=pdhf_scale_factor,
tmp_path_factory=tmp_path_factory,
)


def _haproxy_auth_header(
*,
haproxy_password_list: List[str],
Expand Down Expand Up @@ -556,14 +426,14 @@ def _haproxy_insecure(

@pytest.fixture(scope="session")
def haproxy_insecure(
docker_compose_insecure: Path,
docker_services: Services,
haproxy_haproxycfg_insecure: Path,
pdhf_docker_compose_insecure: Path,
tmp_path_factory: TempPathFactory,
) -> Generator[HAProxyInsecure, None, None]:
"""Provides the endpoint of a local, insecure, haproxy."""
for lst in _haproxy_insecure(
docker_compose_insecure_list=[docker_compose_insecure],
docker_compose_insecure_list=[pdhf_docker_compose_insecure],
docker_services=docker_services,
haproxy_haproxycfg_insecure_list=[haproxy_haproxycfg_insecure],
scale_factor=1,
Expand All @@ -574,15 +444,15 @@ def haproxy_insecure(

@pytest.fixture(scope="session")
def haproxy_insecure_list(
docker_compose_insecure_list: List[Path],
docker_services: Services,
haproxy_haproxycfg_insecure_list: List[Path],
pdhf_docker_compose_insecure_list: List[Path],
pdhf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[HAProxyInsecure], None, None]:
"""Provides the endpoint of a local, insecure, haproxy."""
yield from _haproxy_insecure(
docker_compose_insecure_list=docker_compose_insecure_list,
docker_compose_insecure_list=pdhf_docker_compose_insecure_list,
docker_services=docker_services,
haproxy_haproxycfg_insecure_list=haproxy_haproxycfg_insecure_list,
scale_factor=pdhf_scale_factor,
Expand Down Expand Up @@ -698,20 +568,20 @@ def _haproxy_secure(

@pytest.fixture(scope="session")
def haproxy_secure(
docker_compose_secure: Path,
docker_services: Services,
haproxy_auth_header,
haproxy_cacerts: Path,
haproxy_certs: HAProxyCerts,
haproxy_haproxycfg_secure: Path,
haproxy_password: str,
haproxy_ssl_context: SSLContext,
haproxy_username: str,
docker_services: Services,
pdhf_docker_compose_secure: Path,
tmp_path_factory: TempPathFactory,
) -> Generator[HAProxySecure, None, None]:
"""Provides the endpoint of a local, secure, haproxy."""
for lst in _haproxy_secure(
docker_compose_secure_list=[docker_compose_secure],
docker_compose_secure_list=[pdhf_docker_compose_secure],
haproxy_auth_header_list=[haproxy_auth_header],
haproxy_cacerts_list=[haproxy_cacerts],
haproxy_certs_list=[haproxy_certs],
Expand All @@ -728,21 +598,21 @@ def haproxy_secure(

@pytest.fixture(scope="session")
def haproxy_secure_list(
docker_compose_secure_list: List[Path],
docker_services: Services,
haproxy_auth_header_list,
haproxy_cacerts_list: List[Path],
haproxy_certs_list: List[HAProxyCerts],
haproxy_haproxycfg_secure_list: List[Path],
haproxy_password_list: List[str],
haproxy_ssl_context_list: List[SSLContext],
haproxy_username_list: List[str],
docker_services: Services,
pdhf_docker_compose_secure_list: List[Path],
pdhf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[HAProxySecure], None, None]:
"""Provides the endpoint of a local, secure, haproxy."""
yield from _haproxy_secure(
docker_compose_secure_list=docker_compose_secure_list,
docker_compose_secure_list=pdhf_docker_compose_secure_list,
haproxy_auth_header_list=haproxy_auth_header_list,
haproxy_cacerts_list=haproxy_cacerts_list,
haproxy_certs_list=haproxy_certs_list,
Expand Down Expand Up @@ -828,6 +698,136 @@ def haproxy_username_list(
return _haproxy_username(scale_factor=pdhf_scale_factor)


def _pdhf_docker_compose_insecure(
*,
docker_compose_files: List[str],
scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure haproxy service.
"""
cache_key = _pdhf_docker_compose_insecure.__name__
result = CACHE.get(cache_key, [])
for i in range(scale_factor):
if i < len(result):
continue

service_name = HAPROXY_SERVICE_PATTERN.format("insecure", i)
chain = itertools.chain(
get_docker_compose_user_defined(docker_compose_files, service_name),
# TODO: lovely-docker-compose uses the file for teardown ...
get_embedded_file(
tmp_path_factory, delete_after=False, name="docker-compose.yml"
),
)
for path in chain:
result.append(path)
break
else:
LOGGER.warning("Unable to find docker compose for: %s", service_name)
result.append("-unknown-")
CACHE[cache_key] = result
yield result


@pytest.fixture(scope="session")
def pdhf_docker_compose_insecure(
docker_compose_files: List[str], tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure haproxy service.
"""
for lst in _pdhf_docker_compose_insecure(
docker_compose_files=docker_compose_files,
scale_factor=1,
tmp_path_factory=tmp_path_factory,
):
yield lst[0]


@pytest.fixture(scope="session")
def pdhf_docker_compose_insecure_list(
docker_compose_files: List[str],
pdhf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the docker-compose configuration file containing the insecure haproxy service.
"""
yield from _pdhf_docker_compose_insecure(
docker_compose_files=docker_compose_files,
scale_factor=pdhf_scale_factor,
tmp_path_factory=tmp_path_factory,
)


def _pdhf_docker_compose_secure(
*,
docker_compose_files: List[str],
scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure haproxy
service.
"""
cache_key = _pdhf_docker_compose_secure.__name__
result = CACHE.get(cache_key, [])
for i in range(scale_factor):
if i < len(result):
continue

service_name = HAPROXY_SERVICE_PATTERN.format("secure", i)
chain = itertools.chain(
get_docker_compose_user_defined(docker_compose_files, service_name),
get_embedded_file(
tmp_path_factory, delete_after=False, name="docker-compose.yml"
),
)
for path in chain:
result.append(path)
break
else:
LOGGER.warning("Unable to find docker compose for: %s", service_name)
result.append("-unknown-")
CACHE[cache_key] = result
yield result


@pytest.fixture(scope="session")
def pdhf_docker_compose_secure(
docker_compose_files: List[str], tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure haproxy
service.
"""
for lst in _pdhf_docker_compose_secure(
docker_compose_files=docker_compose_files,
scale_factor=1,
tmp_path_factory=tmp_path_factory,
):
yield lst[0]


@pytest.fixture(scope="session")
def pdhf_docker_compose_secure_list(
docker_compose_files: List[str],
pdhf_scale_factor: int,
tmp_path_factory: TempPathFactory,
) -> Generator[List[Path], None, None]:
"""
Provides the location of the templated docker-compose configuration file containing the secure haproxy
service.
"""
yield from _pdhf_docker_compose_secure(
docker_compose_files=docker_compose_files,
scale_factor=pdhf_scale_factor,
tmp_path_factory=tmp_path_factory,
)


@pytest.fixture(scope="session")
def pdhf_scale_factor() -> int:
"""Provides the number enumerated instances to be instantiated."""
Expand Down
Loading

0 comments on commit 9ce2cb1

Please sign in to comment.