Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

Commit

Permalink
Adds global context processors w/ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kumar303 committed Sep 22, 2011
1 parent 8e32847 commit 59a27fe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions funfactory/context_processors.py
Expand Up @@ -8,3 +8,8 @@ def i18n(request):
or translation.get_language(),
'DIR': 'rtl' if translation.get_language_bidi() else 'ltr',
}


def globals(request):
return {'request': request,
'settings': settings}
1 change: 1 addition & 0 deletions funfactory/settings_base.py
Expand Up @@ -138,6 +138,7 @@ def lazy_langs():
'session_csrf.context_processor',
'django.contrib.messages.context_processors.messages',
'funfactory.context_processors.i18n',
'funfactory.context_processors.globals',
#'jingo_minify.helpers.build_ids',
)

Expand Down
31 changes: 31 additions & 0 deletions tests/test_context_processors.py
@@ -0,0 +1,31 @@
import jingo
import jinja2
from nose.tools import eq_
from test_utils import TestCase, RequestFactory


class TestContext(TestCase):

def setUp(self):
self.factory = RequestFactory()

def render(self, content, request=None):
if not request:
request = self.factory.get('/')
tpl = jinja2.Template(content)
return jingo.render_to_string(request, tpl)

def test_request(self):
eq_(self.render('{{ request.path }}'), '/')

def test_settings(self):
eq_(self.render('{{ settings.SITE_ID }}'), '1')

def test_languages(self):
eq_(self.render("{{ LANGUAGES['en-us'] }}"), 'English (US)')

def test_languages(self):
eq_(self.render("{{ LANG }}"), 'en-US')

def test_lang_dir(self):
eq_(self.render("{{ DIR }}"), 'ltr')

0 comments on commit 59a27fe

Please sign in to comment.