# 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}/authentic/
envlist =
  authentic-py3-dj22-drf39-djtables1211
  authentic-py3-dj22-drf312-djtables211
  code-style

[tox:jenkins]
envlist =
  update-locales
  authentic-py3-dj22-drf39-djtables1211
  check-migrations
  code-style
  pylint

[testenv]
setenv =

  authentic: AUTHENTIC2_SETTINGS_FILE=tests/settings.py
  authentic: DJANGO_SETTINGS_MODULE=authentic2.settings
  rbac: DJANGO_SETTINGS_MODULE=django_rbac.test_settings

  authentic: TESTS=tests/
  authentic-oldldap: TESTS=tests/test_ldap.py
  rbac: TESTS=tests_rbac/

  DB_ENGINE=django.db.backends.postgresql_psycopg2
  SETUPTOOLS_USE_DISTUTILS=stdlib

  JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml}
  COVERAGE={tty::--cov --cov-append --cov-report xml --cov-report html --cov-config=tox.ini}
  fast: FAST=--nomigrations
  reusedb: REUSEDB=--reuse-db
  !nosw: SW={tty:--sw:}
  slow: PYTESTOPTIONS={env:PYTESTOPTIONS:} --slow
passenv=
  BRANCH_NAME
  # support for pg_virtualenv
  PGPORT
  PGHOST
  PGUSER
  PGPASSWORD
  PYTESTOPTIONS
deps = 
  pip > 9
  dj22: django<2.3
  djtables1211: django-tables2==1.21.1
  djtables211: django-tables2==2.1.1
  psycopg2-binary<2.9
  coverage
  pytest-cov
  pytest-django
  pytest-random
  mock<4
  pytest!=5.3.3
  lxml
  cssselect
  django-webtest
  Markdown<3
  WebTest
  pyquery
  httmock
  pytz
  pytest-freezegun
  faker
  pylint
  pylint-django
  uwsgidecorators
  enum34<=1.1.6
  ldaptools>=0.15
  oldldap: python-ldap<3
  rbac: numpy
  py2: django-appconf<1.0.4
  py2: django-filter<2
  py3: django-filter
  drf39: djangorestframework>=3.9.2,<3.10
  drf312: djangorestframework>=3.12,<3.13
usedevelop = True
commands =
  ./getlasso3.sh
  rbac,authentic: py.test {env:PYTESTOPTIONS:} {env:FAST:} {env:REUSEDB:} {env:COVERAGE:} {env:JUNIT:} {env:SW:} {posargs:{env:TESTS} --random-group}

[testenv:check-migrations]
basepython = python3
usedevelop = True
setenv =
  DJANGO_SETTINGS_MODULE=authentic2.settings
  SETUPTOOLS_USE_DISTUTILS=stdlib
deps =
    psycopg2-binary<2.9
commands =
  ./getlasso3.sh
  ./check-migrations.sh

[testenv:pylint]
basepython = python3
setenv =
  DJANGO_SETTINGS_MODULE=authentic2.settings
  SETUPTOOLS_USE_DISTUTILS=stdlib
deps =
    pylint
    pylint-django
    psycopg2-binary<2.9
    django_webtest
    faker
    httmock
    lxml
    ldaptools
    pytest
    uwsgidecorators
    pyquery
commands =
    ./getlasso3.sh
    ./pylint.sh tests/ src/

[testenv:manage]
usedevelop = True
setenv =
  DJANGO_SETTINGS_MODULE=authentic2.settings
  AUTHENTIC2_SETTINGS_FILE=local_settings.py
deps =
  psycopg2-binary<2.9
  django-debug-toolbar
  ipython
  ipdb
commands =
    ./getlasso3.sh
    ./authentic2-ctl {posargs:--help}


[testenv:update-locales]
usedevelop = True
setenv =
  DJANGO_SETTINGS_MODULE=authentic2.settings
deps =
  psycopg2-binary<2.9
commands =
    ./getlasso3.sh
    ./authentic2-ctl makemessages
    ./authentic2-ctl compilemessages


[testenv:code-style]
skip_install = true
deps =
  pre-commit
commands =
  pre-commit run --all-files --show-diff-on-failure

[pytest]
filterwarnings =
  ignore
  once:::authentic2.*
junit_family=xunit2

[coverage:run]
source =
    authentic2
    authentic2_auth_fc
    authentic2_auth_oidc
    authentic2_auth_saml
    authentic2_idp_cas
    authentic2_idp_oidc
    django_rbac
branch = True
dynamic_context = test_function

[coverage:html]
show_contexts = True
