Skip to content

Commit

Permalink
Merge "(no-ticket) Using cached template loader in default_settings."
Browse files Browse the repository at this point in the history
  • Loading branch information
mdebski authored and Gerrit Code Review committed Jun 30, 2014
2 parents b544aaa + 76b6141 commit 4e5094e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
22 changes: 19 additions & 3 deletions oioioi/base/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from django.utils.importlib import import_module
from django.core.handlers.wsgi import WSGIRequest
from django.core.cache import cache
from django.template.loaders.cached import Loader as CachedLoader

from oioioi.base import utils
from oioioi.base.permissions import is_superuser, Condition, make_condition, \
Expand Down Expand Up @@ -92,6 +93,14 @@ def check_ajax_not_accessible(testcase, url_or_viewname, *args, **kwargs):
testcase.assertIn(response.status_code, (403, 404))


def clear_template_cache():
from django.template.loader import template_source_loaders
if template_source_loaders:
for l in template_source_loaders:
if isinstance(l, CachedLoader):
l.reset()


class IgnorePasswordAuthBackend(object):
"""An authentication backend which accepts any password for an existing
user.
Expand Down Expand Up @@ -232,14 +241,21 @@ def test_no_contest(self):
self.assertIn('This is a new OIOIOI installation',
response.content)

def test_navbar_login(self):
response = self.client.get('/')
self.assertIn('navbar-login', response.content)


class TestIndexNoContestWithOverride(TestCase):
fixtures = ('test_users',)

@override_settings(TEMPLATE_DIRS=(os.path.join(basedir, 'templates'),))
def test_custom_index(self):
response = self.client.get('/')
self.assertIn('This is a test index template', response.content)

def test_navbar_login(self):
response = self.client.get('/')
self.assertIn('navbar-login', response.content)
def tearDown(self):
clear_template_cache()


class TestOrderedRegistry(TestCase):
Expand Down
7 changes: 6 additions & 1 deletion oioioi/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
# 'django.template.loaders.eggs.Loader',
)

if not DEBUG:
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', TEMPLATE_LOADERS),
)

TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
Expand Down

0 comments on commit 4e5094e

Please sign in to comment.