diff --git a/mfa/apps.py b/mfa/apps.py index cb5ecca..8a6e285 100644 --- a/mfa/apps.py +++ b/mfa/apps.py @@ -1,4 +1,4 @@ from django.apps import AppConfig class myAppNameConfig(AppConfig): name = 'mfa' - verbose_name = 'A Much Better Name' \ No newline at end of file + verbose_name = 'Django MFA2' \ No newline at end of file diff --git a/mfa/tests.py b/mfa/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/mfa/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..eea7252 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,104 @@ +[pytest] +# Searching +python_files = test_* +python_classes = Tests* +python_functions = test_* + +env_files = + .env + +# do not search for tests in these folders +norecursedirs = venv + +# Add folder to PYTHONPATH +# requires pytest >= 7.0.0 +pythonpath = mfa + + +# https://pytest-django.readthedocs.io/en/latest/usage.html +; DJANGO_SETTINGS_MODULE = + ; + +# do not override the debug mode (True/False) set in the django settings module +# https://pytest-django.readthedocs.io/en/latest/usage.html#additional-pytest-ini-settings +django_debug_mode = keep + + +# +# set env variables +# https://tech.serhatteker.com/post/2020-02/test-env-vars-in-python/ +# https://github.com/pytest-dev/pytest-env +; env = + ; KEY=value + + +addopts = + # verbose + -v + # more verbosity + # -vv + # Don't show warnings + # -p no:warnings + # generates coverage report + # note that enabling pytest coverage will cause debugging pytest to fail on pycharm + # add the --no-cov to the pytest configuration on pycharm to allow for debugging pytest + --cov=./src + # surpress generating converage if one or more tests failed + ; --no-cov-on-fail + # do not run migrations => faster test initialization + # --nomigrations + # Show hypthesis statistics whereever hypothesis was used + # ignore these tests/files when looking for tests + #--ignore= + # black + # --black + --hypothesis-show-statistics + + +# Define additional pytest markers so that using them in test will not trigger warnings +# To show the help line use: % pytest --marker +# To run pytest on a specifc marker use: pytest -m mark +# to run pytestt on several markers use quotation and logic operators as in: +# pytest -m "mark1 and mark2" +# pytest -m "mark1 or mark2" +# pytest -m "mark1 and not mark2" +markers = + API: tests of server api functions whether it is exposed as REST API or otherwise + BLACK_BOX: Black Box tests + WHITE_BOX: White Box tests + ENVIRONMENT: tests for the environment + CONFIGURATION: tests related configurations + LOGGING: tests related to logging + UNIT: Unit tests + INTEGRATION: Integration testing + UTILS: tests for utilities + FOCUS: tests under the microscope... under the spotlight... in focus + FUNC: functional teesting + REGRESSION: tests for fixed bugs + + DJANGO: tests related to DJANGO + + HTTP_REQUEST: tests of functions that handles HTTP REQUESTS + HTTP_GET: tests of functions that handles HTTP_GET_REQUESTS + HTTP_POST: tests of functions that handles HTTP_POST_REQUESTS + AUTH: tests related to user authentication + SQL_DB: tests related to the sql database + + CLI: tests related to flask-cli + SERVER: tests for the server + + API_V1: API related tests + + PRIVILEGED_USER: tests for privileged users + NON_PRIVILEGED_USER: tests for non-privileged users + PERMISSIONS: tests related to inspectre permissions + + ENDPOINTS: tests for endpoints (API nodes) + SERIALIZERS: tests for serializers + VIEWSETS: tests for DRF viewsets + FILTERS: tests for DRF filters + MODELS: tests for models + VALIDATORS: tests for validators + + ERROR_HANDLING: tests for error handling + SECURITY: tests for security diff --git a/requirements_testing.txt b/requirements_testing.txt new file mode 100644 index 0000000..a07e042 --- /dev/null +++ b/requirements_testing.txt @@ -0,0 +1,10 @@ +tox +pytest>=7.0.0 +pytest-xdist +pytest-cov # Test coverage +pytest-dotenv # plugin to load environment from .env file +pytest-env # plugin to allow passing environment variable to pytest environmentt +pytest-mock # plugin that provides a mocker fixture which is a thin-wrapper around the patching API provided by the mock package +hypothesis # plugin that helps in automatize generating random values instead of static values in pyttests +pytest-django # pytest support for Django +validators # a package containing several validator functions \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_views.py b/tests/test_views.py new file mode 100644 index 0000000..a1ace31 --- /dev/null +++ b/tests/test_views.py @@ -0,0 +1,2 @@ +import pytest + diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..23946b5 --- /dev/null +++ b/tox.ini @@ -0,0 +1,41 @@ +# Tox (https://tox.readthedocs.io/) 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. +# +# See also https://tox.readthedocs.io/en/latest/config.html for more +# configuration options. + +[tox] +# Choose your Python versions. They have to be available +# on the system the tests are run on. +# comma separated +envlist = py39, py310, py311 + +# Tell tox to not require a setup.py file +;skipsdist = True + +isolated_build = True + +[testenv] +# https://tox.wiki/en/latest/example/basic.html#using-a-different-default-pypi-url +;setenv = +; PIP_INDEX_URL = https://pypi.my-alternative-index.org + +# https://tech.serhatteker.com/post/2020-02/test-env-vars-in-python/ +;setenv = +; NAME=value + +# https://tox.wiki/en/latest/example/basic.html#passing-down-environment-variables +# passenv = ENV_VAR_NAME + +# https://tox.wiki/en/latest/example/pytest.html#extended-example-change-dir-before-test-and-use-per-virtualenv-tempdir +;changedir = tests + +deps = + -rrequirements.txt + +# https://tox.wiki/en/latest/example/basic.html#ignoring-a-command-exit-code +commands = +; pytest --junitxml=report.xml + pytest {posargs}