From f4cceaa7b10fa9cb7e90b648e096805786f518f7 Mon Sep 17 00:00:00 2001 From: Paul Marillonnet Date: Wed, 26 Jan 2022 10:19:36 +0100 Subject: [PATCH] tests: add a tox.ini and other tox/pytest-related files (#61045) --- check-migrations.sh | 27 ++++++++++++++ getlasso3.sh | 22 ++++++++++++ pylint.sh | 13 +++++++ tox.ini | 85 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100755 check-migrations.sh create mode 100755 getlasso3.sh create mode 100755 pylint.sh create mode 100644 tox.ini diff --git a/check-migrations.sh b/check-migrations.sh new file mode 100755 index 0000000..8d5dc7d --- /dev/null +++ b/check-migrations.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + + +# https://stackoverflow.com/questions/49778988/makemigrations-in-dev-machine-without-database-instance +CHECK_MIGRATIONS_SETTINGS=`mktemp` +trap "rm -f ${CHECK_MIGRATIONS_SETTINGS}" EXIT +cat <${CHECK_MIGRATIONS_SETTINGS} +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.dummy', + } +} +EOF +TEMPFILE=`mktemp` +trap "rm -f ${TEMPFILE} ${CHECK_MIGRATIONS_SETTINGS}" EXIT + +DJANGO_SETTINGS_MODULE=authentic2.settings AUTHENTIC2_SETTINGS_FILE=${CHECK_MIGRATIONS_SETTINGS} django-admin makemigrations --dry-run --noinput authentic2_auth_fedict >${TEMPFILE} 2>&1 || true + +if ! grep 'No changes detected' -q ${TEMPFILE}; then + echo '!!! Missing migration detected !!!' + cat ${TEMPFILE} + exit 1 +else + exit 0 +fi diff --git a/getlasso3.sh b/getlasso3.sh new file mode 100755 index 0000000..9266a72 --- /dev/null +++ b/getlasso3.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Get venv site-packages path +DSTDIR=`python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'` + +# Get not venv site-packages path +# Remove first path (assuming that is the venv path) +NONPATH=`echo $PATH | sed 's/^[^:]*://'` +SRCDIR=`PATH=$NONPATH python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'` + +# Clean up +rm -f $DSTDIR/lasso.* +rm -f $DSTDIR/_lasso.* + +# Link +ln -sv /usr/lib/python3/dist-packages/lasso.py $DSTDIR/ +for SOFILE in /usr/lib/python3/dist-packages/_lasso.cpython-*.so +do + ln -sv $SOFILE $DSTDIR/ +done + +exit 0 diff --git a/pylint.sh b/pylint.sh new file mode 100755 index 0000000..241d24c --- /dev/null +++ b/pylint.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +if [ -f /var/lib/jenkins/pylint.django.rc ]; then + PYLINT_RC=/var/lib/jenkins/pylint.django.rc +elif [ -f pylint.django.rc ]; then + PYLINT_RC=pylint.django.rc +else + echo No pylint RC found + exit 0 +fi +pylint -f parseable --rcfile ${PYLINT_RC} "$@" > pylint.out || /bin/true diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..dbee3d3 --- /dev/null +++ b/tox.ini @@ -0,0 +1,85 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/authentic2-auth-fedict/{env:BRANCH_NAME:} +envlist = + py3-dj22 + +[tox:jenkins] +envlist = + pylint + code-style + py3-dj22 + + +[testenv] +setenv = + AUTHENTIC2_SETTINGS_FILE=tests/settings.py + DJANGO_SETTINGS_MODULE=authentic2.settings + + JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml} + COVERAGE={tty::--junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=src/ --cov-config .coveragerc} +passenv= + BRANCH_NAME + # support for pg_virtualenv + PGPORT + PGHOST + PGUSER + PGPASSWORD +usedevelop = true +deps = + !local: https://git.entrouvert.org/authentic.git/snapshot/authentic-main.tar.gz + local: ../authentic2 + # dependency constraints for authentic + py3: file-magic + djangorestframework>=3.12,<3.13 + dj22: django<2.3 + django-tables<2.0 + psycopg2-binary<2.9 + oldldap: python-ldap<3 + ldaptools + + # pytest requirements + pytest + pytest-cov + pytest-django + pytest-freezegun + pytest-random + django-webtest + pyquery + astroid!=2.5.7 + +commands = + py3: ./getlasso3.sh + ./check-migrations.sh + py.test {env:COVERAGE:} {env:JUNIT:} {tty:--sw:} {posargs:tests/} + +[testenv:pylint] +usedevelop = true +basepython = python3 +deps = + https://git.entrouvert.org/authentic.git/snapshot/authentic-main.tar.gz + Django<2.3 + pylint<1.8 + pylint-django<0.8.1 +commands = + /bin/bash -c "./pylint.sh src/*/" + +[testenv:code-style] +skip_install = true +deps = + pre-commit +commands = + pre-commit run --all-files --show-diff-on-failure + +[pytest] +junit_family=xunit2 +filterwarnings = + once + ignore:::django\..* + ignore:::authentic2\..* + ignore:::rest_framework\..* + ignore:::gettext\..*