diff --git a/.gitignore b/.gitignore index 73a8c5be..de8bdcac 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ tests/test_module_build_service.db-journal requirements.txt.orig mbstest.db htmlcov/ +test.env.yaml diff --git a/tests/integration/README.rst b/tests/integration/README.rst new file mode 100644 index 00000000..921cf4be --- /dev/null +++ b/tests/integration/README.rst @@ -0,0 +1,33 @@ +============================================== +Integration tests for the Module Build Service +============================================== + +This directory stores the integration tests for MBS. + +Configuration +============= + +The tests should be configured by a ``test.env.yaml`` file placed in the +top-level directory of this repository. This can be changed to a different +path by setting ``MBS_TEST_CONFIG``. + +See `tests/integration/example.test.env.yaml`_ for the list of configuration +options and examples. + +Running the tests +================= + +Tests can be triggered from the top-level directory of this repository with:: + + tox -e integration + +Note, that the ``integration`` environment is not part of the default ``tox`` +envlist. + +``REQUESTS_CA_BUNDLE`` is passed in ``tox.ini`` for the ``integration`` +environment in order to enable running the tests against MBS instances which +have self-signed certificates. Example usage:: + + REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt tox -e integration + +.. _tests/integration/example.test.env.yaml: example.test.env.yaml diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py new file mode 100644 index 00000000..6d5e566b --- /dev/null +++ b/tests/integration/conftest.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# SPDX-License-Identifier: MIT + +import os + +import yaml +import pytest + +from utils import MBS, Git, Koji + + +def load_test_env(): + """Load test environment configuration + + :return: Test environment configuration. + :rtype: dict + """ + config_file = os.getenv("MBS_TEST_CONFIG", "test.env.yaml") + with open(config_file) as f: + env = yaml.safe_load(f) + return env + + +test_env = load_test_env() + + +@pytest.fixture(scope="session") +def mbs(): + return MBS(test_env["mbs_api"]) + + +@pytest.fixture(scope="session") +def git(): + return Git(test_env["git_url"]) + + +@pytest.fixture(scope="session") +def koji(): + return Koji(**test_env["koji"]) diff --git a/tests/integration/example.test.env.yaml b/tests/integration/example.test.env.yaml new file mode 100644 index 00000000..549f6f4f --- /dev/null +++ b/tests/integration/example.test.env.yaml @@ -0,0 +1,9 @@ +--- +# API endpoint of the MBS instance under test. +mbs_api: https://mbs.fedoraproject.org/module-build-service/2/module-builds/ +# Git instance used by the build system. +git_url: https://src.fedoraproject.org/ +# Koji instance the MBS instance under test communicates with. +koji: + server: https://koji.fedoraproject.org/kojihub + topurl: https://kojipkgs.fedoraproject.org/ diff --git a/tests/integration/test_normal_build.py b/tests/integration/test_normal_build.py new file mode 100644 index 00000000..93c2fe00 --- /dev/null +++ b/tests/integration/test_normal_build.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# SPDX-License-Identifier: MIT + + +def test_normal_build(): + """ TODO(csomh): implement this test + """ + assert True diff --git a/tests/integration/utils.py b/tests/integration/utils.py new file mode 100644 index 00000000..4b657e71 --- /dev/null +++ b/tests/integration/utils.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# SPDX-License-Identifier: MIT + + +class MBS: + + def __init__(self, api): + self._api = api + + +class Git: + + def __init__(self, url): + self._url = url + + +class Koji: + + def __init__(self, server, topurl): + self._server = server + self._topurl = topurl diff --git a/tox.ini b/tox.ini index fa867b6e..965f46bb 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,10 @@ whitelist_externals = deps = -r{toxinidir}/test-requirements.txt commands = py.test -v \ + --ignore tests/integration \ + --cov module_build_service \ + --cov-report html \ + --cov-report term \ -W "ignore:Use .persist_selectable:DeprecationWarning" \ -W "ignore:The ConnectionEvents.dbapi_error() event is deprecated and will be removed in a future release. Please refer to the ConnectionEvents.handle_error() event.:DeprecationWarning" \ {posargs} @@ -55,5 +59,18 @@ commands = /bin/bash -c "bandit -r -ll $(find . -mindepth 1 -maxdepth 1 ! -name tests ! -name \.\* -type d -o -name \*.py)" ignore_outcome = True -[pytest] -addopts = --cov module_build_service --cov-report html --cov-report term +[testenv:integration] +basepython = python3 +skipsdist = true +skip_install = true +sitepackages = false +# let's handle integration test deps separately +deps = + pytest + requests + PyYAML +# Set this to /etc/pki/tls/certs/ca-bundle.crt, for example, +# if the instance tested has a self-signed certificate. +passenv = REQUESTS_CA_BUNDLE MBS_TEST_CONFIG +commands = + pytest -vv --confcutdir=tests/integration {posargs:tests/integration}