From d519e49acbdfc33642bc0f51cc2434d831be8b62 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Fiorentino Date: Thu, 22 Mar 2018 11:45:56 -0300 Subject: [PATCH] Simplify test suit. --- .gitignore | 1 + .../{ => cases}/test_authorize_endpoint.py | 0 .../tests/{ => cases}/test_claims.py | 0 .../tests/{ => cases}/test_commands.py | 0 .../{ => cases}/test_end_session_endpoint.py | 0 .../tests/{ => cases}/test_middleware.py | 0 .../test_provider_info_endpoint.py | 0 .../tests/{ => cases}/test_settings.py | 0 .../tests/{ => cases}/test_token_endpoint.py | 0 .../{ => cases}/test_userinfo_endpoint.py | 0 oidc_provider/tests/{ => cases}/test_utils.py | 0 oidc_provider/tests/settings.py | 79 ++++++++++++ runtests.py | 120 ------------------ tox.ini | 36 +++--- 14 files changed, 99 insertions(+), 137 deletions(-) rename oidc_provider/tests/{ => cases}/test_authorize_endpoint.py (100%) rename oidc_provider/tests/{ => cases}/test_claims.py (100%) rename oidc_provider/tests/{ => cases}/test_commands.py (100%) rename oidc_provider/tests/{ => cases}/test_end_session_endpoint.py (100%) rename oidc_provider/tests/{ => cases}/test_middleware.py (100%) rename oidc_provider/tests/{ => cases}/test_provider_info_endpoint.py (100%) rename oidc_provider/tests/{ => cases}/test_settings.py (100%) rename oidc_provider/tests/{ => cases}/test_token_endpoint.py (100%) rename oidc_provider/tests/{ => cases}/test_userinfo_endpoint.py (100%) rename oidc_provider/tests/{ => cases}/test_utils.py (100%) create mode 100644 oidc_provider/tests/settings.py delete mode 100644 runtests.py diff --git a/.gitignore b/.gitignore index 2c6f875..c057419 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ src/ docs/_build/ .eggs/ .python-version +.pytest_cache/ diff --git a/oidc_provider/tests/test_authorize_endpoint.py b/oidc_provider/tests/cases/test_authorize_endpoint.py similarity index 100% rename from oidc_provider/tests/test_authorize_endpoint.py rename to oidc_provider/tests/cases/test_authorize_endpoint.py diff --git a/oidc_provider/tests/test_claims.py b/oidc_provider/tests/cases/test_claims.py similarity index 100% rename from oidc_provider/tests/test_claims.py rename to oidc_provider/tests/cases/test_claims.py diff --git a/oidc_provider/tests/test_commands.py b/oidc_provider/tests/cases/test_commands.py similarity index 100% rename from oidc_provider/tests/test_commands.py rename to oidc_provider/tests/cases/test_commands.py diff --git a/oidc_provider/tests/test_end_session_endpoint.py b/oidc_provider/tests/cases/test_end_session_endpoint.py similarity index 100% rename from oidc_provider/tests/test_end_session_endpoint.py rename to oidc_provider/tests/cases/test_end_session_endpoint.py diff --git a/oidc_provider/tests/test_middleware.py b/oidc_provider/tests/cases/test_middleware.py similarity index 100% rename from oidc_provider/tests/test_middleware.py rename to oidc_provider/tests/cases/test_middleware.py diff --git a/oidc_provider/tests/test_provider_info_endpoint.py b/oidc_provider/tests/cases/test_provider_info_endpoint.py similarity index 100% rename from oidc_provider/tests/test_provider_info_endpoint.py rename to oidc_provider/tests/cases/test_provider_info_endpoint.py diff --git a/oidc_provider/tests/test_settings.py b/oidc_provider/tests/cases/test_settings.py similarity index 100% rename from oidc_provider/tests/test_settings.py rename to oidc_provider/tests/cases/test_settings.py diff --git a/oidc_provider/tests/test_token_endpoint.py b/oidc_provider/tests/cases/test_token_endpoint.py similarity index 100% rename from oidc_provider/tests/test_token_endpoint.py rename to oidc_provider/tests/cases/test_token_endpoint.py diff --git a/oidc_provider/tests/test_userinfo_endpoint.py b/oidc_provider/tests/cases/test_userinfo_endpoint.py similarity index 100% rename from oidc_provider/tests/test_userinfo_endpoint.py rename to oidc_provider/tests/cases/test_userinfo_endpoint.py diff --git a/oidc_provider/tests/test_utils.py b/oidc_provider/tests/cases/test_utils.py similarity index 100% rename from oidc_provider/tests/test_utils.py rename to oidc_provider/tests/cases/test_utils.py diff --git a/oidc_provider/tests/settings.py b/oidc_provider/tests/settings.py new file mode 100644 index 0000000..ea61262 --- /dev/null +++ b/oidc_provider/tests/settings.py @@ -0,0 +1,79 @@ +DEBUG = False + +SECRET_KEY = 'this-should-be-top-secret' + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } +} + +SITE_ID = 1 + +MIDDLEWARE_CLASSES = [ + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', +] + +MIDDLEWARE = [ + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', +] + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +INSTALLED_APPS = [ + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.admin', + 'oidc_provider', +] + +ROOT_URLCONF = 'oidc_provider.tests.app.urls' + +TEMPLATE_DIRS = [ + 'oidc_provider/tests/templates', +] + +USE_TZ = True + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + }, + }, + 'loggers': { + 'oidc_provider': { + 'handlers': ['console'], + 'level': 'DEBUG', + }, + }, +} + +# OIDC Provider settings. + +SITE_URL = 'http://localhost:8000' +OIDC_USERINFO = 'oidc_provider.tests.app.utils.userinfo' diff --git a/runtests.py b/runtests.py deleted file mode 100644 index 636062d..0000000 --- a/runtests.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python -import os -import sys - -import django - -from django.conf import settings - - -DEFAULT_SETTINGS = dict( - - DEBUG=False, - - DATABASES={ - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:', - } - }, - - SITE_ID=1, - - MIDDLEWARE_CLASSES=[ - 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - ], - - MIDDLEWARE=[ - 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - ], - - TEMPLATES=[ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, - ], - - LOGGING={ - 'version': 1, - 'disable_existing_loggers': False, - 'handlers': { - 'console': { - 'class': 'logging.StreamHandler', - }, - }, - 'loggers': { - 'oidc_provider': { - 'handlers': ['console'], - 'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'), - }, - }, - }, - - INSTALLED_APPS=[ - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.messages', - 'django.contrib.admin', - 'oidc_provider', - ], - - SECRET_KEY='this-should-be-top-secret', - - ROOT_URLCONF='oidc_provider.tests.app.urls', - - TEMPLATE_DIRS=[ - 'oidc_provider/tests/templates', - ], - - USE_TZ=True, - - # OIDC Provider settings. - - SITE_URL='http://localhost:8000', - OIDC_USERINFO='oidc_provider.tests.app.utils.userinfo', - -) - - -def runtests(*test_args): - if not settings.configured: - settings.configure(**DEFAULT_SETTINGS) - - django.setup() - - parent = os.path.dirname(os.path.abspath(__file__)) - sys.path.insert(0, parent) - - try: - from django.test.runner import DiscoverRunner - runner_class = DiscoverRunner - if not test_args: - test_args = ["oidc_provider.tests"] - except ImportError: - from django.test.simple import DjangoTestSuiteRunner - runner_class = DjangoTestSuiteRunner - if not test_args: - test_args = ["tests"] - - failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) - sys.exit(failures) - - -if __name__ == "__main__": - runtests(*sys.argv[1:]) diff --git a/tox.ini b/tox.ini index bb1ed84..cf70af8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,33 +1,35 @@ [tox] - envlist= - clean, py27-django{17,18,19,110,111}, py34-django{17,18,19,110,111,20}, py35-django{18,19,110,111,20}, py36-django{18,19,110,111,20}, - [testenv] - +changedir= + oidc_provider/tests/cases deps = + mock + psycopg2 + pytest + pytest-django + pytest-flake8 + pytest-cov django17: django>=1.7,<1.8 django18: django>=1.8,<1.9 django19: django>=1.9,<1.10 django110: django>=1.10,<1.11 django111: django>=1.11,<1.12 django20: django>=2.0,<2.1 - coverage - mock - commands = - coverage run setup.py test + pytest --flake8 --cov=oidc_provider {posargs} -[testenv:clean] - -commands= - coverage erase - -[testenv:stats] - -commands= - coverage report -m +[pytest] +DJANGO_SETTINGS_MODULE = oidc_provider.tests.settings +python_files = test_*.py +flake8-max-line-length = 99 +flake8-ignore = + .git ALL + __pycache__ ALL + .ropeproject ALL + */migrations ALL + manage.py ALL