From a5045f62fe500a349b6b440bbecfa8f189e727b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksi=20H=C3=A4kli?= Date: Wed, 6 Jan 2021 23:42:25 +0200 Subject: [PATCH] Move tests outside project source folder --- docs/conf.py | 2 +- manage.py | 2 +- pytest.ini | 5 ++--- setup.py | 2 +- {axes/tests => tests}/__init__.py | 0 {axes/tests => tests}/base.py | 0 {axes/tests => tests}/settings.py | 2 +- {axes/tests => tests}/test_admin.py | 3 ++- {axes/tests => tests}/test_attempts.py | 3 ++- {axes/tests => tests}/test_backends.py | 3 ++- {axes/tests => tests}/test_checks.py | 7 ++++--- {axes/tests => tests}/test_decorators.py | 3 ++- {axes/tests => tests}/test_handlers.py | 7 ++++--- {axes/tests => tests}/test_helpers.py | 13 +++++-------- {axes/tests => tests}/test_logging.py | 3 ++- {axes/tests => tests}/test_login.py | 3 ++- {axes/tests => tests}/test_management.py | 3 ++- {axes/tests => tests}/test_middleware.py | 6 ++---- {axes/tests => tests}/test_models.py | 3 ++- {axes/tests => tests}/test_signals.py | 3 ++- {axes/tests => tests}/test_utils.py | 5 +++-- {axes/tests => tests}/urls.py | 0 {axes/tests => tests}/urls_empty.py | 0 23 files changed, 42 insertions(+), 36 deletions(-) rename {axes/tests => tests}/__init__.py (100%) rename {axes/tests => tests}/base.py (100%) rename {axes/tests => tests}/settings.py (98%) rename {axes/tests => tests}/test_admin.py (95%) rename {axes/tests => tests}/test_attempts.py (99%) rename {axes/tests => tests}/test_backends.py (94%) rename {axes/tests => tests}/test_checks.py (94%) rename {axes/tests => tests}/test_decorators.py (97%) rename {axes/tests => tests}/test_handlers.py (98%) rename {axes/tests => tests}/test_helpers.py (89%) rename {axes/tests => tests}/test_logging.py (99%) rename {axes/tests => tests}/test_login.py (99%) rename {axes/tests => tests}/test_management.py (98%) rename {axes/tests => tests}/test_middleware.py (92%) rename {axes/tests => tests}/test_models.py (96%) rename {axes/tests => tests}/test_signals.py (91%) rename {axes/tests => tests}/test_utils.py (99%) rename {axes/tests => tests}/urls.py (100%) rename {axes/tests => tests}/urls_empty.py (100%) diff --git a/docs/conf.py b/docs/conf.py index 206e5b8..65425a0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,7 @@ from pkg_resources import get_distribution import django import sphinx_rtd_theme -environ.setdefault("DJANGO_SETTINGS_MODULE", "axes.tests.settings") +environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") django.setup() # -- Extra custom configuration ------------------------------------------ diff --git a/manage.py b/manage.py index b2cf6bd..e456dcf 100644 --- a/manage.py +++ b/manage.py @@ -4,7 +4,7 @@ import os import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "axes.tests.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") from django.core.management import execute_from_command_line diff --git a/pytest.ini b/pytest.ini index e919914..f5eae20 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,4 @@ [pytest] -testpaths = axes/tests -python_files = tests.py test_*.py tests_*.py *_tests.py *_test.py +testpaths = tests addopts = --cov axes --cov-config .coveragerc --cov-append --cov-report term-missing --cov-report=xml -DJANGO_SETTINGS_MODULE = axes.tests.settings +DJANGO_SETTINGS_MODULE = tests.settings diff --git a/setup.py b/setup.py index 42a923e..9b39c15 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ setup( python_requires="~=3.6", install_requires=["django>=2.2", "django-ipware>=3,<4"], include_package_data=True, - packages=find_packages(), + packages=find_packages(exclude=["tests"]), classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", diff --git a/axes/tests/__init__.py b/tests/__init__.py similarity index 100% rename from axes/tests/__init__.py rename to tests/__init__.py diff --git a/axes/tests/base.py b/tests/base.py similarity index 100% rename from axes/tests/base.py rename to tests/base.py diff --git a/axes/tests/settings.py b/tests/settings.py similarity index 98% rename from axes/tests/settings.py rename to tests/settings.py index 03667dd..1f64a8d 100644 --- a/axes/tests/settings.py +++ b/tests/settings.py @@ -26,7 +26,7 @@ AUTHENTICATION_BACKENDS = [ PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"] -ROOT_URLCONF = "axes.tests.urls" +ROOT_URLCONF = "tests.urls" INSTALLED_APPS = [ "django.contrib.auth", diff --git a/axes/tests/test_admin.py b/tests/test_admin.py similarity index 95% rename from axes/tests/test_admin.py rename to tests/test_admin.py index 7857420..9fa44d6 100644 --- a/axes/tests/test_admin.py +++ b/tests/test_admin.py @@ -6,7 +6,8 @@ from django.test import override_settings import axes.admin from axes.models import AccessAttempt, AccessLog -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase class AxesEnableAdminFlag(AxesTestCase): diff --git a/axes/tests/test_attempts.py b/tests/test_attempts.py similarity index 99% rename from axes/tests/test_attempts.py rename to tests/test_attempts.py index da4d666..8fe0967 100644 --- a/axes/tests/test_attempts.py +++ b/tests/test_attempts.py @@ -6,9 +6,10 @@ from django.utils.timezone import now from axes.attempts import get_cool_off_threshold from axes.models import AccessAttempt -from axes.tests.base import AxesTestCase from axes.utils import reset, reset_request +from tests.base import AxesTestCase + class GetCoolOffThresholdTestCase(AxesTestCase): @override_settings(AXES_COOLOFF_TIME=42) diff --git a/axes/tests/test_backends.py b/tests/test_backends.py similarity index 94% rename from axes/tests/test_backends.py rename to tests/test_backends.py index e279427..e681385 100644 --- a/axes/tests/test_backends.py +++ b/tests/test_backends.py @@ -5,7 +5,8 @@ from axes.exceptions import ( AxesBackendRequestParameterRequired, AxesBackendPermissionDenied, ) -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase class BackendTestCase(AxesTestCase): diff --git a/axes/tests/test_checks.py b/tests/test_checks.py similarity index 94% rename from axes/tests/test_checks.py rename to tests/test_checks.py index bfc56a7..baece20 100644 --- a/axes/tests/test_checks.py +++ b/tests/test_checks.py @@ -3,7 +3,8 @@ from django.test import override_settings, modify_settings from axes.backends import AxesBackend from axes.checks import Messages, Hints, Codes -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase class CacheCheckTestCase(AxesTestCase): @@ -75,14 +76,14 @@ class BackendCheckTestCase(AxesTestCase): self.assertEqual(warnings, [warning]) @override_settings( - AUTHENTICATION_BACKENDS=["axes.tests.test_checks.AxesSpecializedBackend"] + AUTHENTICATION_BACKENDS=["tests.test_checks.AxesSpecializedBackend"] ) def test_specialized_backend(self): warnings = run_checks() self.assertEqual(warnings, []) @override_settings( - AUTHENTICATION_BACKENDS=["axes.tests.test_checks.AxesNotDefinedBackend"] + AUTHENTICATION_BACKENDS=["tests.test_checks.AxesNotDefinedBackend"] ) def test_import_error(self): with self.assertRaises(ImportError): diff --git a/axes/tests/test_decorators.py b/tests/test_decorators.py similarity index 97% rename from axes/tests/test_decorators.py rename to tests/test_decorators.py index 1447aa9..3c3e331 100644 --- a/axes/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -3,7 +3,8 @@ from unittest.mock import MagicMock, patch from django.http import HttpResponse from axes.decorators import axes_dispatch, axes_form_invalid -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase class DecoratorTestCase(AxesTestCase): diff --git a/axes/tests/test_handlers.py b/tests/test_handlers.py similarity index 98% rename from axes/tests/test_handlers.py rename to tests/test_handlers.py index fe0c144..d06578c 100644 --- a/axes/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -10,7 +10,8 @@ from axes.conf import settings from axes.handlers.proxy import AxesProxyHandler from axes.helpers import get_client_str from axes.models import AccessAttempt, AccessLog -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase @override_settings(AXES_HANDLER="axes.handlers.base.AxesHandler") @@ -54,7 +55,7 @@ class AxesHandlerTestCase(AxesTestCase): request.path = url self.assertEqual(AxesProxyHandler().is_admin_site(request), expected) - @override_settings(ROOT_URLCONF="axes.tests.urls_empty") + @override_settings(ROOT_URLCONF="tests.urls_empty") @override_settings(AXES_ONLY_ADMIN_SITE=True) def test_is_admin_site_no_admin_site(self): request = MagicMock() @@ -240,7 +241,7 @@ class AxesDatabaseHandlerTestCase(AxesHandlerBaseTestCase): def test_handler_callable_failure_limit(self): self.check_handler() - @override_settings(AXES_FAILURE_LIMIT="axes.tests.base.custom_failure_limit") + @override_settings(AXES_FAILURE_LIMIT="tests.base.custom_failure_limit") def test_handler_str_failure_limit(self): self.check_handler() diff --git a/axes/tests/test_helpers.py b/tests/test_helpers.py similarity index 89% rename from axes/tests/test_helpers.py rename to tests/test_helpers.py index 4cbbc0b..0219c75 100644 --- a/axes/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -5,7 +5,8 @@ from django.http import HttpRequest, HttpResponse from django.test import override_settings from axes.helpers import get_cool_off, get_lockout_response, is_user_attempt_whitelisted -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase def mock_get_cool_off_str(): @@ -25,9 +26,7 @@ class AxesCoolOffTestCase(AxesTestCase): def test_get_cool_off_callable(self): self.assertEqual(get_cool_off(), timedelta(seconds=30)) - @override_settings( - AXES_COOLOFF_TIME="axes.tests.test_helpers.mock_get_cool_off_str" - ) + @override_settings(AXES_COOLOFF_TIME="tests.test_helpers.mock_get_cool_off_str") def test_get_cool_off_path(self): self.assertEqual(get_cool_off(), timedelta(seconds=30)) @@ -50,9 +49,7 @@ class AxesWhitelistTestCase(AxesTestCase): def test_is_whitelisted_override_callable(self): self.assertTrue(is_user_attempt_whitelisted(self.request, self.credentials)) - @override_settings( - AXES_WHITELIST_CALLABLE="axes.tests.test_helpers.mock_is_whitelisted" - ) + @override_settings(AXES_WHITELIST_CALLABLE="tests.test_helpers.mock_is_whitelisted") def test_is_whitelisted_override_path(self): self.assertTrue(is_user_attempt_whitelisted(self.request, self.credentials)) @@ -81,7 +78,7 @@ class AxesLockoutTestCase(AxesTestCase): self.assertEqual(400, response.status_code) @override_settings( - AXES_LOCKOUT_CALLABLE="axes.tests.test_helpers.mock_get_lockout_response" + AXES_LOCKOUT_CALLABLE="tests.test_helpers.mock_get_lockout_response" ) def test_get_lockout_response_override_path(self): response = get_lockout_response(self.request, self.credentials) diff --git a/axes/tests/test_logging.py b/tests/test_logging.py similarity index 99% rename from axes/tests/test_logging.py rename to tests/test_logging.py index e7c0101..e3e7564 100644 --- a/axes/tests/test_logging.py +++ b/tests/test_logging.py @@ -5,7 +5,8 @@ from django.urls import reverse from axes.apps import AppConfig from axes.models import AccessAttempt, AccessLog -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase @patch("axes.apps.AppConfig.initialized", False) diff --git a/axes/tests/test_login.py b/tests/test_login.py similarity index 99% rename from axes/tests/test_login.py rename to tests/test_login.py index b8f33ec..45a4dac 100644 --- a/axes/tests/test_login.py +++ b/tests/test_login.py @@ -14,7 +14,8 @@ from django.contrib.auth import get_user_model, login, logout from axes.conf import settings from axes.models import AccessAttempt from axes.helpers import get_cache, make_cache_key_list -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase class DjangoLoginTestCase(TestCase): diff --git a/axes/tests/test_management.py b/tests/test_management.py similarity index 98% rename from axes/tests/test_management.py rename to tests/test_management.py index e95b03b..4d42f64 100644 --- a/axes/tests/test_management.py +++ b/tests/test_management.py @@ -5,7 +5,8 @@ from django.core.management import call_command from django.utils import timezone from axes.models import AccessAttempt, AccessLog -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase class ResetAccessLogsManagementCommandTestCase(AxesTestCase): diff --git a/axes/tests/test_middleware.py b/tests/test_middleware.py similarity index 92% rename from axes/tests/test_middleware.py rename to tests/test_middleware.py index 4a73aeb..fed40ce 100644 --- a/axes/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -1,11 +1,9 @@ -from unittest import mock - from django.http import HttpResponse, HttpRequest -from django.conf import settings from django.test import override_settings from axes.middleware import AxesMiddleware -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase class MiddlewareTestCase(AxesTestCase): diff --git a/axes/tests/test_models.py b/tests/test_models.py similarity index 96% rename from axes/tests/test_models.py rename to tests/test_models.py index 754cfc8..f72b7f0 100644 --- a/axes/tests/test_models.py +++ b/tests/test_models.py @@ -5,7 +5,8 @@ from django.db.migrations.executor import MigrationExecutor from django.db.migrations.state import ProjectState from axes.models import AccessAttempt, AccessLog -from axes.tests.base import AxesTestCase + +from tests.base import AxesTestCase class ModelsTestCase(AxesTestCase): diff --git a/axes/tests/test_signals.py b/tests/test_signals.py similarity index 91% rename from axes/tests/test_signals.py rename to tests/test_signals.py index 9324f17..23030cc 100644 --- a/axes/tests/test_signals.py +++ b/tests/test_signals.py @@ -1,8 +1,9 @@ from unittest.mock import MagicMock -from axes.tests.base import AxesTestCase from axes.signals import user_locked_out +from tests.base import AxesTestCase + class SignalTestCase(AxesTestCase): def test_send_lockout_signal(self): diff --git a/axes/tests/test_utils.py b/tests/test_utils.py similarity index 99% rename from axes/tests/test_utils.py rename to tests/test_utils.py index 846448f..96eb4d2 100644 --- a/axes/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,7 +7,6 @@ from django.test import override_settings, RequestFactory from axes.apps import AppConfig from axes.models import AccessAttempt -from axes.tests.base import AxesTestCase from axes.helpers import ( get_cache_timeout, get_client_str, @@ -24,6 +23,8 @@ from axes.helpers import ( toggleable, ) +from tests.base import AxesTestCase + @override_settings(AXES_ENABLED=False) class AxesDisabledTestCase(AxesTestCase): @@ -488,7 +489,7 @@ class UsernameTestCase(AxesTestCase): with self.assertRaises(TypeError): get_client_username(HttpRequest(), {}) - @override_settings(AXES_USERNAME_CALLABLE="axes.tests.test_utils.get_username") + @override_settings(AXES_USERNAME_CALLABLE="tests.test_utils.get_username") def test_get_client_username_str(self): self.assertEqual(get_client_username(HttpRequest(), {}), "username") diff --git a/axes/tests/urls.py b/tests/urls.py similarity index 100% rename from axes/tests/urls.py rename to tests/urls.py diff --git a/axes/tests/urls_empty.py b/tests/urls_empty.py similarity index 100% rename from axes/tests/urls_empty.py rename to tests/urls_empty.py