Package: pytest-docker-apache-fixtures
pytest-docker-apache-fixturesOverviewPytest fixtures to instantiate and utilize local apache (httpd) docker containers, usinglovely-pytest-dockeranddocker-py, for testing.Getting StartedUpdatesetup.pyto include:fromdistutils.coreimportsetupsetup(tests_require=["pytest-docker-apache-fixtures"])All fixtures should be automatically included via thepytest11entry point.importrequestsimportpytestfrompytest_docker_apache_fixturesimportApacheInsecure,ApacheSecure# Optional, for typingdeftest_apache_secure(apache_secure:ApacheSecure):response=requests.head(f"https://{apache_secure.endpoint}/",headers=apache_secure.auth_header,verify=str(apache_secure.cacerts),)assertresponse.status_code==200deftest_apache_insecure(apache_insecure:ApacheInsecure):response=requests.head(f"http://{apache_insecure.endpoint}/")assertresponse.status_code==200Thepush_imagemark can optionally be added to stage images in the apache prior to testing. SeeMarkersfor details.CompatibilityTested with python 3.8InstallationFrompypi.org$ pip install pytest_docker_apache_fixturesFrom source code$gitclonehttps://github.com/crashvb/pytest-docker-apache-fixtures
$cdpytest-docker-apache-fixtures
$virtualenvenv
$sourceenv/bin/activate
$python-mpipinstall--editable.[dev]Fixturesapache_auth_headerRetrieves an HTTP basic authentication header that is populated with credentials that can access the secure apache service. The credentials are retrieved from theapache_passwordandapache_usernamefixtures. This fixture is used to replicate docker images into the secure apache service.apache_cacertsLocates a user-defined CA trust store (tests/cacerts) to use to verify connections to the secure apache service. If one cannot be located, a temporary trust store is created containing certificates fromcertifiand theapache_certsfixture. This fixture is used to instantiate the secure apache service.apache_certsReturns the paths of the self-signed certificate authority certificate, certificate, and private key that are used by the secure apache service. This fixture is used to instantiate the secure apache service.NamedTuple FieldsThe 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 bypytest_docker_apache_fixtures.ApacheCerts.apache_htpasswdProvides the path to a htpasswd file that is used by the secure apache service. If a user-defined htpasswd file (tests/htpasswd) can be located, it is used. Otherwise, a temporary htpasswd file is created using credentials from theapache_passwordandapache_usernamefixtures. This fixture is used to instantiate the secure apache ervice.apache_apachecfg_insecureProvides the path to an insecure apache.cfg file that is used by the insecure apache service. If a user-defined apache.cfg file (tests/apache.insecure.cfg) can be located, it is used. Otherwise, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure apache service.apache_apachecfg_secureProvides the path to a secure apache.cfg file that is used by the secure apache service. If a user-defined apache.cfg file (tests/apache.secure.cfg) can be located, it is used. Otherwise, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure apache service.apache_insecureConfigures and instantiates a apache service without TLS or authentication.importrequestsfrompytest_docker_apache_fixturesimportApacheInsecure# Optional, for typingdeftest_apache_insecure(apache_insecure:ApacheInsecure):response=requests.head(f"http://{apache_insecure.endpoint}/")assertresponse.status_code==200NamedTuple FieldsThe following fields are defined in the tuple provided by this fixture:docker_compose- Path to the fully instantiated docker-compose configuration.endpoint- Endpoint of the insecure apache service.endpoint_name- Endpoint of the insecure apache service, by service name.service_name- Name of the service within the docker-compose configuration.Typing is provided bypytest_docker_apache_fixtures.ApacheInsecure.apache_passwordProvides a generated password to use for authentication to the secure apache service. This fixture is used to replicate docker images into the secure apache service.apache_secureConfigures and instantiates a TLS enabled apache service with HTTP basic authorization.importrequestsfrompytest_docker_apache_fixturesimportApacheSecure# Optional, for typingdeftest_apache_secure(apache_secure:ApacheSecure):response=requests.head(f"https://{apache_secure.endpoint}/",headers=apache_secure.auth_header,verify=str(apache_secure.cacerts),)assertresponse.status_code==200NamedTuple FieldsThe following fields are defined in the tuple provided by this fixture:auth_header- fromapache_auth_header.cacerts- fromapache_cacerts.certs- fromapache_certs.docker_compose- Path to the fully instantiated docker-compose configuration.endpoint- Endpoint of the secure apache service.endpoint_name- Endpoint of the secure apache service, by service name.htpasswd- fromapache_htpasswdpassword- fromapache_password.service_name- Name of the service within the docker-compose configuration.ssl_context- fromapache_ssl_context.username- fromapache_username.Typing is provided bypytest_docker_apache_fixtures.ApacheSecure.apache_ssl_contextProvides an SSL context containing the CA trust store from theapache_cacertsfixture. This fixture is used to instantiate the secure apache service.apache_usernameProvides a generated username to use for authentication to the secure apache service. This fixture is used to replicate docker images into the secure apache service.pdhf_docker_compose_insecureThis fixture uses thedocker_compose_filesfixture to locate a user-defined docker-compose configuration file (typicallytests/docker-compose.yml) that contains thepytest-docker-apache-insecureservice. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure apache service. The configuration will be treated as a template; the$PATH_APACHECFGtoken will be populated with the absolute path provided by theapache_apachecfgfixture.pdhf_docker_compose_secureThis fixture uses thedocker_compose_filesfixture to locate a user-defined docker-compose configuration file (typicallytests/docker-compose.yml) that contains thepytest-docker-apache-secureservice. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure apache service. The configuration will be treated as a template; the$PATH_CERTIFICATE,$PATH_HTPASSWD,$PATH_KEY, and$PATH_APACHECFGtokens will be populated with the absolute paths provided by theapache_certs,apache_htpasswd, andapache_apachecfgfixtures, as appropriate.Enumerated FixturesIt is possible to instantiate multiple apache instances using the corresponding enumerated fixtures. Allfixtureslisted above have _*list(e.g.apache_secure->apache_secure_list) versions that will return enumerated lists of corresponding data type.For example:importrequestsfromtypingimportList# Optional, for typingfrompytest_docker_apache_fixturesimportApacheSecure# Optional, for typingdeftest_apache_secure_list(apache_secure_list:List[ApacheSecure]):forapache_secureinapache_secure_list:response=requests.head(f"https://{apache_secure.endpoint}/",headers=apache_secure.auth_header,verify=str(apache_secure.cacerts),)assertresponse.status_code==200It 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. apache_secure == apache_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 thepdhf_scale_factorfixture, as follows:importpytest@pytest.fixture(scope="session")defpdhf_scale_factor()->int:return4This fixture will be used to scale both the insecure and secure docker registries.LimitationsAll the fixtures provided by this package aresessionscoped; and will only be executed once per test execution.At most 10 insecure and 10 secure apache instances are supported using the embedded docker compose.DevelopmentSource Control