pytest-docker-registry-fixtures


Namepytest-docker-registry-fixtures JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/crashvb/pytest-docker-registry-fixtures
SummaryPytest fixtures for testing with docker registries.
upload_time2024-08-12 23:25:46
maintainerNone
docs_urlNone
authorRichard Davis
requires_pythonNone
licenseApache License 2.0
keywords docker fixtures pytest registries
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-docker-registry-fixtures

[![pypi version](https://img.shields.io/pypi/v/pytest-docker-registry-fixtures.svg)](https://pypi.org/project/pytest-docker-registry-fixtures)
[![build status](https://github.com/crashvb/pytest-docker-registry-fixtures/actions/workflows/main.yml/badge.svg)](https://github.com/crashvb/pytest-docker-registry-fixtures/actions)
[![coverage status](https://coveralls.io/repos/github/crashvb/pytest-docker-registry-fixtures/badge.svg)](https://coveralls.io/github/crashvb/pytest-docker-registry-fixtures)
[![python versions](https://img.shields.io/pypi/pyversions/pytest-docker-registry-fixtures.svg?logo=python&logoColor=FBE072)](https://pypi.org/project/pytest-docker-registry-fixtures)
[![linting](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/PyCQA/pylint)
[![code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![license](https://img.shields.io/github/license/crashvb/pytest-docker-registry-fixtures.svg)](https://github.com/crashvb/pytest-docker-registry-fixtures/blob/master/LICENSE.md)

## Overview

Pytest fixtures to instantiate and populated local docker registries, using [lovely-pytest-docker](https://pypi.org/project/lovely-pytest-docker) and [docker-py](https://pypi.org/project/docker-py), for testing.

## Getting Started

Update <tt>setup.py</tt> to include:

```python
from distutils.core import setup

setup(
	tests_require=["pytest-docker-registry-fixtures"]
)
```

All fixtures should be automatically included via the <tt>pytest11</tt> entry point.
```python
import requests
import pytest
from pytest_docker_registry_fixtures import DockerRegistryInsecure, DockerRegistrySecure  # Optional, for typing

@pytest.mark.push_image("busybox:1.30.1", "alpine")
def test_docker_registry_secure(docker_registry_secure: DockerRegistrySecure):
    response = requests.head(f"https://{docker_registry_secure.endpoint}/v2/",
        headers=docker_registry_secure.auth_header,
        verify=str(docker_registry_secure.cacerts),
    )
    assert response.status_code == 200

def test_docker_registry_insecure(docker_registry_insecure: DockerRegistryInsecure):
    response = requests.head(f"http://{docker_registry_insecure.endpoint}/v2/")
    assert response.status_code == 200
```

The `push_image` mark can optionally be added to stage images in the registry prior to testing. See [Markers](#markers) for details.

## Installation
### From [pypi.org](https://pypi.org/project/pytest-docker-registry-fixtures/)

```
$ pip install pytest_docker_registry_fixtures
```

### From source code

```bash
$ git clone https://github.com/crashvb/pytest-docker-registry-fixtures
$ cd pytest-docker-registry-fixtures
$ virtualenv env
$ source env/bin/activate
$ python -m pip install --editable .[dev]
```

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

### docker_client

Creates a Docker client using configuration values from environment variables. This fixture is used to replicate images into a registry.

```python
from docker import DockerClient

def test_docker_pull(docker_client: DockerClient):
    image = docker_client.image.pull("busybox:1.30.1")
```

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

Retrieves an HTTP basic authentication header that is populated with credentials that can access the secure docker registry service. The credentials are retrieved from the [docker_registry_password](#docker_registry_password) and [docker_registry_username](#docker_registry_username) fixtures. This fixture is used to replicate docker images into the secure docker registry service.

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

Locates a user-defined CA trust store (<tt>tests/cacerts</tt>) to use to verify connections to the secure docker registry service. If one cannot be located, a temporary trust store is created containing certificates from <tt>certifi</tt> and the [docker_registry_certs](#docker_registry_certs) fixture. This fixture is used to instantiate the secure docker registry service.

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

Returns the paths of the self-signed certificate authority certificate, certificate, and private key that are used by the secure docker registry service. This fixture is used to instantiate the secure docker registry service.

#### NamedTuple Fields

The following fields are defined in the tuple provided by this fixture:

* **ca_certificate** - Path to the self-signed certificate authority certificate.
* **ca_private_key** - Path to the self-signed certificate authority private key.
* **certificate** - Path to the certificate.
* **private_key** - Path to the private key.

Typing is provided by `pytest_docker_registry_fixtures.DockerRegistryCerts`.

### <a name="docker_registry_hwpasswd"></a> docker_registry_htpasswd

Provides the path to a htpasswd file that is used by the secure docker registry service. If a user-defined htpasswd file (<tt>tests/htpasswd</tt>) can be located, it is used. Otherwise, a temporary htpasswd file is created using credentials from the [docker_registry_password](#docker_registry_password) and [docker_registry_username](#docker_registry_username) fixtures. This fixture is used to instantiate the secure docker registry service.

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

Configures and instantiates a docker registry without TLS or authentication.

```python
import requests
from pytest_docker_registry_fixtures import DockerRegistryInsecure  # Optional, for typing

def test_docker_registry_insecure(docker_registry_insecure: DockerRegistryInsecure):
    for image_name in docker_registry_insecure.images:
        response = requests.head(
            f"http://{docker_registry_insecure.endpoint}/v2/{image_name.image}/manifests/{image_name.tag}",
        )
        assert response.status_code == 200
        assert "Docker-Content-Digest" in response.headers
```

#### NamedTuple Fields

The following fields are defined in the tuple provided by this fixture:

* **docker_client** - from [docker_client](#docker_client)
* **docker_compose** - Path to the fully instantiated docker-compose configuration.
* **endpoint** - Endpoint of the insecure docker registry service.
* **endpoint_name** - Endpoint of the insecure docker registry service, by service name.
* **images** - List of images that were replicated into the insecure docker registry service.
* **service_name** - Name of the service within the docker-compose configuration.

Typing is provided by `pytest_docker_registry_fixtures.DockerRegistryInsecure`.

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

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

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

Configures and instantiates a TLS enabled docker registry with HTTP basic authorization.

```python
import requests
from pytest_docker_registry_fixtures import DockerRegistrySecure  # Optional, for typing

def test_docker_registry_secure(docker_registry_secure: DockerRegistrySecure):
    for image_name in docker_registry_secure.images:
        response = requests.head(
            f"https://{docker_registry_secure.endpoint}/v2/{image_name.image}/manifests/{image_name.tag}",
            headers=docker_registry_secure.auth_header,
            verify=str(docker_registry_secure.cacerts),
        )
        assert response.status_code == 200
        assert "Docker-Content-Digest" in response.headers
```

#### NamedTuple Fields

The following fields are defined in the tuple provided by this fixture:

* **auth_header** - from [docker_registry_auth_header](#docker_registry_auth_header).
* **cacerts** - from [docker_registry_cacerts](#docker_registry_cacerts).
* **certs** - from [docker_registry_certs](#docker_registry_certs).
* **docker_client** - Docker client, from [docker_client](#docker_client), with injected authentication credentials for the secure docker registry service.
* **docker_compose** - Path to the fully instantiated docker-compose configuration.
* **endpoint** - Endpoint of the secure docker registry service.
* **endpoint_name** - Endpoint of the secure docker registry service, by service name.
* **htpasswd** - from [docker_registry_htpasswd](#docker_registry_htpasswd)
* **images** - List of images that were replicated into the secure docker registry service.
* **password** - from [docker_registry_password](#docker_registry_password).
* **service_name** - Name of the service within the docker-compose configuration.
* **ssl_context** - from [docker_registry_ssl_context](#docker_registry_ssl_context).
* **username** - from [docker_registry_username](#docker_registry_username).

Typing is provided by `pytest_docker_registry_fixtures.DockerRegistrySecure`.

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

Provides an SSL context containing the CA trust store from the  [docker_registry_cacerts](#docker_registry_cacerts) fixture. This fixture is used to instantiate the secure docker registry service.

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

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

### <a name="pdrf_docker_compose_insecure"></a> pdrf_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-registry-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 registry service.

### <a name="pdrf_docker_compose_secure"></a> pdrf_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-registry-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 registry service; however, unlike the configuration returned by the [pdrf_docker_compose_insecure](#pdrf_docker_compose_insecure) fixture, this configuration will be treated as a template; the <tt>$PATH_CERTIFICATE</tt>, <tt>$PATH_HTPASSWD</tt>, and <tt>$PATH_KEY</tt> tokens will be populated with the absolute paths provided by the [docker_registry_certs](#docker_registry_certs) and [docker_registry_htpasswd](#docker_registry_htpasswd) fixtures, as appropriate.

## <a name="markers"></a>Markers

### pytest.mark.push_image

This marker specifies the docker image name(s) that should be replicated to the docker registry service(s) prior to testing. It can ...

... decorate individual tests:

```python
import pytest
from pytest_docker_registry_fixtures import DockerRegistrySecure  # Optional, for typing

@pytest.mark.push_image("busybox:1.30.1", "alpine", "python,mysql:latest")
def test_docker_registry_secure(docker_registry_secure: DockerRegistrySecure):
	...
```

... be specified in the `pytestmark` list at the module level:

```python
#!/usr/bin/env python

import pytest

pytestmark = [pytest.mark.push_image("busybox:1.30.1", "alpine", "python,mysql:latest")]

...
```

... or be provided via the corresponding `--push-image` command-line argument:

```bash
python -m pytest --push-image busybox:1.30.1 --push-image alpine --push-image python,mysql:latest ...
```

This marker supports being specified multiple times, and removes duplicate image names (see [Limitations](#limitations) below).

A helper function, `get_pushed_images`, is included for test scenarios that  wish to inspect the maker directly:

```python
import pytest
from pytest_docker_registry_fixtures import DockerRegistrySecure, get_pushed_images, ImageName

@pytest.mark.push_image("busybox:1.30.1")
def test_docker_registry_secure(docker_registry_secure: DockerRegistrySecure, request):
    image_name = ImageName.parse(get_pushed_images(request)[0])
```

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

It is possible to instantiate multiple registry instances using the corresponding enumerated fixtures. All [fixtures](#fixtures) listed above have _*_list_ (e.g. `docker_registry_secure` -> `docker_registry_secure_list`) versions that will return enumerated lists of corresponding data type.

For example:

```python
import requests
from typing import List  # Optional, for typing
from pytest_docker_registry_fixtures import DockerRegistrySecure  # Optional, for typing

def test_docker_registry_secure_list(docker_registry_secure_list: List[DockerRegistrySecure]):
    for docker_registry_secure in docker_registry_secure_list:
        for image_name in docker_registry_secure.images:
            response = requests.head(
                f"https://{docker_registry_secure.endpoint}/v2/{image_name.image}/manifests/{image_name.tag}",
                headers=docker_registry_secure.auth_header,
                verify=str(docker_registry_secure.cacerts),
            )
            assert response.status_code == 200
            assert "Docker-Content-Digest" in response.headers
```

It is possible to use both singular and enumerated fixtures within the same test context; however, the same values will be returned for the singular fixture as the first enumerated list value (i.e. docker_registry_secure == docker_registry_secure_list[0]). To avoid complications with lower layers, mainly docker-compose, and to allow for this interchangeability, caching is used internally.

By default, the scale factor of the enumerated instances is set to one (n=1). This value can be changed by overriding the `pdrf_scale_factor` fixture, as follows:

```python
import pytest

@pytest.fixture(scope="session")
def pdrf_scale_factor() -> int:
    return 4
```

This fixture will be used to scale both the insecure and secure docker registries.

## <a name="limitations"></a>Limitations

1. All the fixtures provided by this package are <tt>session</tt> scoped; and will only be executed once per test execution.
2. The `push_image` marker is processed as part of the `docker_registry_insecure` and `docker_registry_secure` fixtures. As such:
  * _all_ markers will be aggregated during initialization of the session, and processed prior test execution.
  * Pushed images will be replicated to both the insecure and secure docker registries, if both are instantiated.
3. A working docker client is required to push images.
4. At most 10 insecure and 10 secure docker registries are supported using the embedded docker compose.
5. It is not currently possible to specify into which enumerated registry instances images should be replicated. As such, and for backwards compatibility, they will only be replicated into the first instance of each of the insecure and secure docker registries.

## Development

[Source Control](https://github.com/crashvb/pytest-docker-registry-fixtures)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/crashvb/pytest-docker-registry-fixtures",
    "name": "pytest-docker-registry-fixtures",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "docker fixtures pytest registries",
    "author": "Richard Davis",
    "author_email": "crashvb@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/54/e3/d55dea1f7bd40246b57c631558d245875fef27076c9cc97149a1fd81c28c/pytest_docker_registry_fixtures-1.0.0.tar.gz",
    "platform": null,
    "description": "# pytest-docker-registry-fixtures\n\n[![pypi version](https://img.shields.io/pypi/v/pytest-docker-registry-fixtures.svg)](https://pypi.org/project/pytest-docker-registry-fixtures)\n[![build status](https://github.com/crashvb/pytest-docker-registry-fixtures/actions/workflows/main.yml/badge.svg)](https://github.com/crashvb/pytest-docker-registry-fixtures/actions)\n[![coverage status](https://coveralls.io/repos/github/crashvb/pytest-docker-registry-fixtures/badge.svg)](https://coveralls.io/github/crashvb/pytest-docker-registry-fixtures)\n[![python versions](https://img.shields.io/pypi/pyversions/pytest-docker-registry-fixtures.svg?logo=python&logoColor=FBE072)](https://pypi.org/project/pytest-docker-registry-fixtures)\n[![linting](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/PyCQA/pylint)\n[![code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![license](https://img.shields.io/github/license/crashvb/pytest-docker-registry-fixtures.svg)](https://github.com/crashvb/pytest-docker-registry-fixtures/blob/master/LICENSE.md)\n\n## Overview\n\nPytest fixtures to instantiate and populated local docker registries, using [lovely-pytest-docker](https://pypi.org/project/lovely-pytest-docker) and [docker-py](https://pypi.org/project/docker-py), for testing.\n\n## Getting Started\n\nUpdate <tt>setup.py</tt> to include:\n\n```python\nfrom distutils.core import setup\n\nsetup(\n\ttests_require=[\"pytest-docker-registry-fixtures\"]\n)\n```\n\nAll fixtures should be automatically included via the <tt>pytest11</tt> entry point.\n```python\nimport requests\nimport pytest\nfrom pytest_docker_registry_fixtures import DockerRegistryInsecure, DockerRegistrySecure  # Optional, for typing\n\n@pytest.mark.push_image(\"busybox:1.30.1\", \"alpine\")\ndef test_docker_registry_secure(docker_registry_secure: DockerRegistrySecure):\n    response = requests.head(f\"https://{docker_registry_secure.endpoint}/v2/\",\n        headers=docker_registry_secure.auth_header,\n        verify=str(docker_registry_secure.cacerts),\n    )\n    assert response.status_code == 200\n\ndef test_docker_registry_insecure(docker_registry_insecure: DockerRegistryInsecure):\n    response = requests.head(f\"http://{docker_registry_insecure.endpoint}/v2/\")\n    assert response.status_code == 200\n```\n\nThe `push_image` mark can optionally be added to stage images in the registry prior to testing. See [Markers](#markers) for details.\n\n## Installation\n### From [pypi.org](https://pypi.org/project/pytest-docker-registry-fixtures/)\n\n```\n$ pip install pytest_docker_registry_fixtures\n```\n\n### From source code\n\n```bash\n$ git clone https://github.com/crashvb/pytest-docker-registry-fixtures\n$ cd pytest-docker-registry-fixtures\n$ virtualenv env\n$ source env/bin/activate\n$ python -m pip install --editable .[dev]\n```\n\n## <a name=\"fixtures\"></a>Fixtures\n\n### docker_client\n\nCreates a Docker client using configuration values from environment variables. This fixture is used to replicate images into a registry.\n\n```python\nfrom docker import DockerClient\n\ndef test_docker_pull(docker_client: DockerClient):\n    image = docker_client.image.pull(\"busybox:1.30.1\")\n```\n\n### <a name=\"docker_registry_auth_header\"></a> docker_registry_auth_header\n\nRetrieves an HTTP basic authentication header that is populated with credentials that can access the secure docker registry service. The credentials are retrieved from the [docker_registry_password](#docker_registry_password) and [docker_registry_username](#docker_registry_username) fixtures. This fixture is used to replicate docker images into the secure docker registry service.\n\n### <a name=\"docker_registry_cacerts\"></a> docker_registry_cacerts\n\nLocates a user-defined CA trust store (<tt>tests/cacerts</tt>) to use to verify connections to the secure docker registry service. If one cannot be located, a temporary trust store is created containing certificates from <tt>certifi</tt> and the [docker_registry_certs](#docker_registry_certs) fixture. This fixture is used to instantiate the secure docker registry service.\n\n### <a name=\"docker_registry_certs\"></a> docker_registry_certs\n\nReturns the paths of the self-signed certificate authority certificate, certificate, and private key that are used by the secure docker registry service. This fixture is used to instantiate the secure docker registry service.\n\n#### NamedTuple Fields\n\nThe following fields are defined in the tuple provided by this fixture:\n\n* **ca_certificate** - Path to the self-signed certificate authority certificate.\n* **ca_private_key** - Path to the self-signed certificate authority private key.\n* **certificate** - Path to the certificate.\n* **private_key** - Path to the private key.\n\nTyping is provided by `pytest_docker_registry_fixtures.DockerRegistryCerts`.\n\n### <a name=\"docker_registry_hwpasswd\"></a> docker_registry_htpasswd\n\nProvides the path to a htpasswd file that is used by the secure docker registry service. If a user-defined htpasswd file (<tt>tests/htpasswd</tt>) can be located, it is used. Otherwise, a temporary htpasswd file is created using credentials from the [docker_registry_password](#docker_registry_password) and [docker_registry_username](#docker_registry_username) fixtures. This fixture is used to instantiate the secure docker registry service.\n\n### <a name=\"docker_registry_insecure\"></a> docker_registry_insecure\n\nConfigures and instantiates a docker registry without TLS or authentication.\n\n```python\nimport requests\nfrom pytest_docker_registry_fixtures import DockerRegistryInsecure  # Optional, for typing\n\ndef test_docker_registry_insecure(docker_registry_insecure: DockerRegistryInsecure):\n    for image_name in docker_registry_insecure.images:\n        response = requests.head(\n            f\"http://{docker_registry_insecure.endpoint}/v2/{image_name.image}/manifests/{image_name.tag}\",\n        )\n        assert response.status_code == 200\n        assert \"Docker-Content-Digest\" in response.headers\n```\n\n#### NamedTuple Fields\n\nThe following fields are defined in the tuple provided by this fixture:\n\n* **docker_client** - from [docker_client](#docker_client)\n* **docker_compose** - Path to the fully instantiated docker-compose configuration.\n* **endpoint** - Endpoint of the insecure docker registry service.\n* **endpoint_name** - Endpoint of the insecure docker registry service, by service name.\n* **images** - List of images that were replicated into the insecure docker registry service.\n* **service_name** - Name of the service within the docker-compose configuration.\n\nTyping is provided by `pytest_docker_registry_fixtures.DockerRegistryInsecure`.\n\n### <a name=\"docker_registry_password\"></a> docker_registry_password\n\nProvides a generated password to use for authentication to the secure docker registry service. This fixture is used to replicate docker images into the secure docker registry service.\n\n### <a name=\"docker_registry_secure\"></a> docker_registry_secure\n\nConfigures and instantiates a TLS enabled docker registry with HTTP basic authorization.\n\n```python\nimport requests\nfrom pytest_docker_registry_fixtures import DockerRegistrySecure  # Optional, for typing\n\ndef test_docker_registry_secure(docker_registry_secure: DockerRegistrySecure):\n    for image_name in docker_registry_secure.images:\n        response = requests.head(\n            f\"https://{docker_registry_secure.endpoint}/v2/{image_name.image}/manifests/{image_name.tag}\",\n            headers=docker_registry_secure.auth_header,\n            verify=str(docker_registry_secure.cacerts),\n        )\n        assert response.status_code == 200\n        assert \"Docker-Content-Digest\" in response.headers\n```\n\n#### NamedTuple Fields\n\nThe following fields are defined in the tuple provided by this fixture:\n\n* **auth_header** - from [docker_registry_auth_header](#docker_registry_auth_header).\n* **cacerts** - from [docker_registry_cacerts](#docker_registry_cacerts).\n* **certs** - from [docker_registry_certs](#docker_registry_certs).\n* **docker_client** - Docker client, from [docker_client](#docker_client), with injected authentication credentials for the secure docker registry service.\n* **docker_compose** - Path to the fully instantiated docker-compose configuration.\n* **endpoint** - Endpoint of the secure docker registry service.\n* **endpoint_name** - Endpoint of the secure docker registry service, by service name.\n* **htpasswd** - from [docker_registry_htpasswd](#docker_registry_htpasswd)\n* **images** - List of images that were replicated into the secure docker registry service.\n* **password** - from [docker_registry_password](#docker_registry_password).\n* **service_name** - Name of the service within the docker-compose configuration.\n* **ssl_context** - from [docker_registry_ssl_context](#docker_registry_ssl_context).\n* **username** - from [docker_registry_username](#docker_registry_username).\n\nTyping is provided by `pytest_docker_registry_fixtures.DockerRegistrySecure`.\n\n### <a name=\"docker_registry_ssl_context\"></a> docker_registry_ssl_context\n\nProvides an SSL context containing the CA trust store from the  [docker_registry_cacerts](#docker_registry_cacerts) fixture. This fixture is used to instantiate the secure docker registry service.\n\n### <a name=\"docker_registry_username\"></a> docker_registry_username\n\nProvides a generated username to use for authentication to the secure docker registry service. This fixture is used to replicate docker images into the secure docker registry service.\n\n### <a name=\"pdrf_docker_compose_insecure\"></a> pdrf_docker_compose_insecure\n\nThis 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-registry-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 registry service.\n\n### <a name=\"pdrf_docker_compose_secure\"></a> pdrf_docker_compose_secure\n\nThis 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-registry-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 registry service; however, unlike the configuration returned by the [pdrf_docker_compose_insecure](#pdrf_docker_compose_insecure) fixture, this configuration will be treated as a template; the <tt>$PATH_CERTIFICATE</tt>, <tt>$PATH_HTPASSWD</tt>, and <tt>$PATH_KEY</tt> tokens will be populated with the absolute paths provided by the [docker_registry_certs](#docker_registry_certs) and [docker_registry_htpasswd](#docker_registry_htpasswd) fixtures, as appropriate.\n\n## <a name=\"markers\"></a>Markers\n\n### pytest.mark.push_image\n\nThis marker specifies the docker image name(s) that should be replicated to the docker registry service(s) prior to testing. It can ...\n\n... decorate individual tests:\n\n```python\nimport pytest\nfrom pytest_docker_registry_fixtures import DockerRegistrySecure  # Optional, for typing\n\n@pytest.mark.push_image(\"busybox:1.30.1\", \"alpine\", \"python,mysql:latest\")\ndef test_docker_registry_secure(docker_registry_secure: DockerRegistrySecure):\n\t...\n```\n\n... be specified in the `pytestmark` list at the module level:\n\n```python\n#!/usr/bin/env python\n\nimport pytest\n\npytestmark = [pytest.mark.push_image(\"busybox:1.30.1\", \"alpine\", \"python,mysql:latest\")]\n\n...\n```\n\n... or be provided via the corresponding `--push-image` command-line argument:\n\n```bash\npython -m pytest --push-image busybox:1.30.1 --push-image alpine --push-image python,mysql:latest ...\n```\n\nThis marker supports being specified multiple times, and removes duplicate image names (see [Limitations](#limitations) below).\n\nA helper function, `get_pushed_images`, is included for test scenarios that  wish to inspect the maker directly:\n\n```python\nimport pytest\nfrom pytest_docker_registry_fixtures import DockerRegistrySecure, get_pushed_images, ImageName\n\n@pytest.mark.push_image(\"busybox:1.30.1\")\ndef test_docker_registry_secure(docker_registry_secure: DockerRegistrySecure, request):\n    image_name = ImageName.parse(get_pushed_images(request)[0])\n```\n\n## <a name=\"enumerated_fixtures\"></a>Enumerated Fixtures\n\nIt is possible to instantiate multiple registry instances using the corresponding enumerated fixtures. All [fixtures](#fixtures) listed above have _*_list_ (e.g. `docker_registry_secure` -> `docker_registry_secure_list`) versions that will return enumerated lists of corresponding data type.\n\nFor example:\n\n```python\nimport requests\nfrom typing import List  # Optional, for typing\nfrom pytest_docker_registry_fixtures import DockerRegistrySecure  # Optional, for typing\n\ndef test_docker_registry_secure_list(docker_registry_secure_list: List[DockerRegistrySecure]):\n    for docker_registry_secure in docker_registry_secure_list:\n        for image_name in docker_registry_secure.images:\n            response = requests.head(\n                f\"https://{docker_registry_secure.endpoint}/v2/{image_name.image}/manifests/{image_name.tag}\",\n                headers=docker_registry_secure.auth_header,\n                verify=str(docker_registry_secure.cacerts),\n            )\n            assert response.status_code == 200\n            assert \"Docker-Content-Digest\" in response.headers\n```\n\nIt is possible to use both singular and enumerated fixtures within the same test context; however, the same values will be returned for the singular fixture as the first enumerated list value (i.e. docker_registry_secure == docker_registry_secure_list[0]). To avoid complications with lower layers, mainly docker-compose, and to allow for this interchangeability, caching is used internally.\n\nBy default, the scale factor of the enumerated instances is set to one (n=1). This value can be changed by overriding the `pdrf_scale_factor` fixture, as follows:\n\n```python\nimport pytest\n\n@pytest.fixture(scope=\"session\")\ndef pdrf_scale_factor() -> int:\n    return 4\n```\n\nThis fixture will be used to scale both the insecure and secure docker registries.\n\n## <a name=\"limitations\"></a>Limitations\n\n1. All the fixtures provided by this package are <tt>session</tt> scoped; and will only be executed once per test execution.\n2. The `push_image` marker is processed as part of the `docker_registry_insecure` and `docker_registry_secure` fixtures. As such:\n  * _all_ markers will be aggregated during initialization of the session, and processed prior test execution.\n  * Pushed images will be replicated to both the insecure and secure docker registries, if both are instantiated.\n3. A working docker client is required to push images.\n4. At most 10 insecure and 10 secure docker registries are supported using the embedded docker compose.\n5. It is not currently possible to specify into which enumerated registry instances images should be replicated. As such, and for backwards compatibility, they will only be replicated into the first instance of each of the insecure and secure docker registries.\n\n## Development\n\n[Source Control](https://github.com/crashvb/pytest-docker-registry-fixtures)\n\n\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Pytest fixtures for testing with docker registries.",
    "version": "1.0.0",
    "project_urls": {
        "Bug Reports": "https://github.com/crashvb/pytest-docker-registry-fixtures/issues",
        "Homepage": "https://github.com/crashvb/pytest-docker-registry-fixtures",
        "Source": "https://github.com/crashvb/pytest-docker-registry-fixtures"
    },
    "split_keywords": [
        "docker",
        "fixtures",
        "pytest",
        "registries"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "abe2567a252ae681e59b14121e78d7739891093242873c0efc539c9bc4b7f160",
                "md5": "e959c2eb12535618fb7cbc2e1cc16604",
                "sha256": "0dde4d49c97be4da5b6da37691d633de89793eb1b184d8c94d828c0abb193e39"
            },
            "downloads": -1,
            "filename": "pytest_docker_registry_fixtures-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e959c2eb12535618fb7cbc2e1cc16604",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 30540,
            "upload_time": "2024-08-12T23:25:45",
            "upload_time_iso_8601": "2024-08-12T23:25:45.148816Z",
            "url": "https://files.pythonhosted.org/packages/ab/e2/567a252ae681e59b14121e78d7739891093242873c0efc539c9bc4b7f160/pytest_docker_registry_fixtures-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54e3d55dea1f7bd40246b57c631558d245875fef27076c9cc97149a1fd81c28c",
                "md5": "d0481fa0a74052684d7fd3a1d8f770a9",
                "sha256": "dfb4796bf1669c06e05afe9dfa96d9ed7fe7d9917b53e5c7be648eaca9bb950a"
            },
            "downloads": -1,
            "filename": "pytest_docker_registry_fixtures-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d0481fa0a74052684d7fd3a1d8f770a9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29684,
            "upload_time": "2024-08-12T23:25:46",
            "upload_time_iso_8601": "2024-08-12T23:25:46.797037Z",
            "url": "https://files.pythonhosted.org/packages/54/e3/d55dea1f7bd40246b57c631558d245875fef27076c9cc97149a1fd81c28c/pytest_docker_registry_fixtures-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-12 23:25:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "crashvb",
    "github_project": "pytest-docker-registry-fixtures",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-docker-registry-fixtures"
}
        
Elapsed time: 0.34620s