From 6059ca067b96f3eb2071f022a39ef2d7d1cc5cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Mon, 15 Jan 2018 05:26:33 +0100 Subject: [PATCH] Speed up tests ~20% less using MD5 and force_login in kfet testcase. ~77% less by disabling the debug tollbar. --- cof/settings/common.py | 3 +++ cof/settings/dev.py | 22 ++++++++++++++-------- kfet/tests/testcases.py | 8 +------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/cof/settings/common.py b/cof/settings/common.py index 48242fc3..708e90a0 100644 --- a/cof/settings/common.py +++ b/cof/settings/common.py @@ -7,6 +7,7 @@ the local development server should be here. """ import os +import sys try: from . import secret @@ -53,6 +54,8 @@ BASE_DIR = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ) +TESTING = sys.argv[1] == 'test' + # Application definition INSTALLED_APPS = [ diff --git a/cof/settings/dev.py b/cof/settings/dev.py index 6e1f6b11..114f37da 100644 --- a/cof/settings/dev.py +++ b/cof/settings/dev.py @@ -4,13 +4,18 @@ The settings that are not listed here are imported from .common """ from .common import * # NOQA -from .common import INSTALLED_APPS, MIDDLEWARE +from .common import INSTALLED_APPS, MIDDLEWARE, TESTING EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' DEBUG = True +if TESTING: + PASSWORD_HASHERS = [ + 'django.contrib.auth.hashers.MD5PasswordHasher', + ] + # --- # Apache static/media config @@ -36,12 +41,13 @@ def show_toolbar(request): """ return DEBUG -INSTALLED_APPS += ["debug_toolbar", "debug_panel"] +if not TESTING: + INSTALLED_APPS += ["debug_toolbar", "debug_panel"] -MIDDLEWARE = [ - "debug_panel.middleware.DebugPanelMiddleware" -] + MIDDLEWARE + MIDDLEWARE = [ + "debug_panel.middleware.DebugPanelMiddleware" + ] + MIDDLEWARE -DEBUG_TOOLBAR_CONFIG = { - 'SHOW_TOOLBAR_CALLBACK': show_toolbar, -} + DEBUG_TOOLBAR_CONFIG = { + 'SHOW_TOOLBAR_CALLBACK': show_toolbar, + } diff --git a/kfet/tests/testcases.py b/kfet/tests/testcases.py index 3ea428c3..aa2fb1b6 100644 --- a/kfet/tests/testcases.py +++ b/kfet/tests/testcases.py @@ -245,13 +245,7 @@ class ViewTestCaseMixin(TestCaseMixin): self.register_user(label, user) if self.auth_user: - # The wrapper is a sanity check. - self.assertTrue( - self.client.login( - username=self.auth_user, - password=self.auth_user, - ) - ) + self.client.force_login(self.users[self.auth_user]) def tearDown(self): del self.users_base