Speed up tests

~20% less using MD5 and force_login in kfet testcase.
~77% less by disabling the debug tollbar.
This commit is contained in:
Aurélien Delobelle 2018-01-15 05:26:33 +01:00
parent 44eee9be38
commit 6059ca067b
3 changed files with 18 additions and 15 deletions

View file

@ -7,6 +7,7 @@ the local development server should be here.
""" """
import os import os
import sys
try: try:
from . import secret from . import secret
@ -53,6 +54,8 @@ BASE_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
) )
TESTING = sys.argv[1] == 'test'
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [

View file

@ -4,13 +4,18 @@ The settings that are not listed here are imported from .common
""" """
from .common import * # NOQA 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' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEBUG = True DEBUG = True
if TESTING:
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.MD5PasswordHasher',
]
# --- # ---
# Apache static/media config # Apache static/media config
@ -36,12 +41,13 @@ def show_toolbar(request):
""" """
return DEBUG return DEBUG
INSTALLED_APPS += ["debug_toolbar", "debug_panel"] if not TESTING:
INSTALLED_APPS += ["debug_toolbar", "debug_panel"]
MIDDLEWARE = [ MIDDLEWARE = [
"debug_panel.middleware.DebugPanelMiddleware" "debug_panel.middleware.DebugPanelMiddleware"
] + MIDDLEWARE ] + MIDDLEWARE
DEBUG_TOOLBAR_CONFIG = { DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': show_toolbar, 'SHOW_TOOLBAR_CALLBACK': show_toolbar,
} }

View file

@ -245,13 +245,7 @@ class ViewTestCaseMixin(TestCaseMixin):
self.register_user(label, user) self.register_user(label, user)
if self.auth_user: if self.auth_user:
# The wrapper is a sanity check. self.client.force_login(self.users[self.auth_user])
self.assertTrue(
self.client.login(
username=self.auth_user,
password=self.auth_user,
)
)
def tearDown(self): def tearDown(self):
del self.users_base del self.users_base