Skip to content

Commit

Permalink
Handle tox dependencies through extras
Browse files Browse the repository at this point in the history
Uses package extras to install dependencies for tests and documentation
build run by tox.

Run functional tests outside of containers created by docker-compose.
This avoids somewhat broken installation of tests dependencies in the
containers and simplifies creating coverage.
  • Loading branch information
hluk committed May 2, 2022
1 parent b3de018 commit fea93e2
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 157 deletions.
48 changes: 5 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# Use podman-compose by default if available.
ifeq (, $(shell which podman-compose))
COMPOSE := docker-compose
PODMAN := docker
else
COMPOSE := podman-compose
PODMAN := podman
endif

BROWSER := xdg-open
SERVICE := dev

PYTHON_VERSION_VENV := python3.9

POETRY_RUN := poetry run
PYTEST := pytest --color=yes
PIP_INSTALL := pip3 install --no-cache-dir --user
TOX := tox

all: help

Expand All @@ -29,29 +20,16 @@ help:
@echo
@echo ' make recreate - recreates containers for docker-compose environment'
@echo
@echo ' make exec [CMD=".."] - executes command in dev container'
@echo
@echo ' make sudo [CMD=".."] - executes command in dev container under root user'
@echo
@echo ' make pytest [ARGS=".."] - executes pytest with given arguments in dev container'
@echo
@echo ' make test - alias for "make pytest"'
@echo
@echo ' make coverage [ARGS=".."] - generates and shows test code coverage'
@echo ' make test - run unit and functional tests'
@echo
@echo 'Variables:'
@echo
@echo ' COMPOSE=docker-compose|podman-compose'
@echo ' - docker-compose or podman-compose command'
@echo ' (default is "podman-compose" if available)'
@echo
@echo ' PODMAN=docker|podman'
@echo ' - docker or podman command'
@echo ' (default is "podman" if "podman-compose" is available)'
@echo
@echo ' SERVICE={dev|waiverdb|resultsdb|waiverdb-db|resultsdb-db|memcached}'
@echo ' - service for which to run `make exec` and similar (default is "dev")'
@echo ' Example: make exec SERVICE=waiverdb CMD=flake8'
@echo ' ARGS=""'
@echo ' - additional arguments for pytest'

up:
$(COMPOSE) up -d
Expand All @@ -65,21 +43,5 @@ build:
recreate:
$(COMPOSE) up -d --force-recreate

exec:
$(PODMAN) exec greenwave_$(SERVICE)_1 bash -c '$(CMD)'

sudo:
$(PODMAN) exec -u root greenwave_$(SERVICE)_1 bash -c '$(CMD)'

test:
$(MAKE) exec CMD="$(PIP_INSTALL) poetry"
$(MAKE) exec CMD="poetry install --no-root"
$(MAKE) pytest

pytest:
$(MAKE) exec \
CMD="COVERAGE_FILE=/home/dev/.coverage-$(SERVICE) $(POETRY_RUN) $(PYTEST) $(ARGS)"

coverage:
$(MAKE) pytest ARGS="--cov-config .coveragerc --cov=greenwave --cov-report html:/home/dev/htmlcov-$(SERVICE) $(ARGS)"
$(BROWSER) docker/home/htmlcov-$(SERVICE)/index.html
$(TOX) -e functional -- $(ARGS)
2 changes: 1 addition & 1 deletion docs/docker-compose.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Run a specific test:

.. code-block:: console
make pytest ARGS="-vv -x greenwave/tests/test_rules.py -k test_remote_rule
make test ARGS="-vv -x greenwave/tests/test_rules.py -k test_remote_rule
Stop the containers:

Expand Down
25 changes: 19 additions & 6 deletions functional-tests/test_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
]


def drop_href(obj):
if isinstance(obj, dict):
return {
k: drop_href(v) for k, v in obj.items()
if k != "href"
}
return obj


def drop_hrefs(results):
return [drop_href(result) for result in results]


@pytest.mark.smoke
def test_any_policies_loaded(requests_session, greenwave_server):
r = requests_session.get(greenwave_server + 'api/v1.0/policies',
Expand Down Expand Up @@ -249,7 +262,7 @@ def test_make_a_decision_with_verbose_flag(requests_session, greenwave_server, t
res_data = r.json()

assert len(res_data['results']) == len(TASKTRON_RELEASE_CRITICAL_TASKS)
assert res_data['results'] == list(reversed(results))
assert drop_hrefs(res_data['results']) == drop_hrefs(list(reversed(results)))
expected_waivers = []
assert res_data['waivers'] == expected_waivers

Expand Down Expand Up @@ -294,7 +307,7 @@ def test_make_a_decision_with_verbose_flag_and_multiple_nvrs_with_results(
res_data = r.json()

assert len(res_data['results']) == len(TASKTRON_RELEASE_CRITICAL_TASKS) * len(build_nvrs)
assert res_data['results'] == list(reversed(results))
assert drop_hrefs(res_data['results']) == drop_hrefs(list(reversed(results)))


def test_make_a_decision_with_verbose_flag_and_multiple_nvrs_with_waivers(
Expand Down Expand Up @@ -1278,7 +1291,7 @@ def test_make_a_decision_for_bodhi_with_verbose_flag(
res_data = r.json()

assert len(res_data['results']) == len(TASKTRON_RELEASE_CRITICAL_TASKS) * len(nvrs)
assert res_data['results'] == list(reversed(results))
assert drop_hrefs(res_data['results']) == drop_hrefs(list(reversed(results)))
assert res_data['waivers'] == []
assert res_data['satisfied_requirements'] == []

Expand Down Expand Up @@ -1403,7 +1416,7 @@ def test_make_a_decision_with_verbose_flag_all_results_returned(
res_data = r.json()

assert len(res_data['results']) == len(results)
assert res_data['results'] == list(reversed(results))
assert drop_hrefs(res_data['results']) == drop_hrefs(list(reversed(results)))
assert len(res_data['waivers']) == len(expected_waivers)
assert res_data['waivers'] == expected_waivers

Expand Down Expand Up @@ -1481,7 +1494,7 @@ def test_api_with_when(requests_session, greenwave_server, testdatabuilder):
res_data = r.json()

assert len(res_data['results']) == 1
assert res_data['results'] == [results[0]]
assert drop_hrefs(res_data['results']) == drop_hrefs([results[0]])

del data['when']
r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data)
Expand Down Expand Up @@ -1606,7 +1619,7 @@ def test_make_a_decision_with_verbose_flag_on_demand_policy(
res_data = r.json()

assert len(res_data['results']) == len(results)
assert res_data['results'] == list(reversed(results))
assert drop_hrefs(res_data['results']) == drop_hrefs(list(reversed(results)))
assert len(res_data['waivers']) == len(expected_waivers)
assert res_data['waivers'] == expected_waivers
assert len(res_data['satisfied_requirements']) == len(results)
Expand Down

0 comments on commit fea93e2

Please sign in to comment.