Skip to content

Commit

Permalink
Merge 75c2302 into 7f1e4a8
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip committed Feb 18, 2016
2 parents 7f1e4a8 + 75c2302 commit e75ac60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tz_detect/templatetags/tz_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
@register.inclusion_tag('tz_detect/detector.html', takes_context=True)
def tz_detect(context):
return {
'show': not hasattr(context['request'], 'timezone_active'),
'show': not hasattr(context.get('request'), 'timezone_active'),
'debug': getattr(settings, 'DEBUG', False),
}
17 changes: 13 additions & 4 deletions tz_detect/tests.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from pytz.tzinfo import BaseTzInfo

from django.contrib.sessions.middleware import SessionMiddleware
from django.test import TestCase
from django.test.client import RequestFactory
from django.contrib.sessions.middleware import SessionMiddleware
from pytz.tzinfo import BaseTzInfo

from tz_detect.views import SetOffsetView
from tz_detect.templatetags.tz_detect import tz_detect
from tz_detect.utils import offset_to_timezone
from tz_detect.views import SetOffsetView


class ViewTestCase(TestCase):
Expand Down Expand Up @@ -83,5 +84,13 @@ def test_fuzzy(self):
self.assertEqual(str(tz), 'Europe/London')


class TemplatetagTestCase(TestCase):


def test_no_request_context(self):
try:
tz_detect({})
except KeyError as e:
if e.message == 'request':
self.fail("Templatetag shouldn't expect request in context.")
else:
raise

0 comments on commit e75ac60

Please sign in to comment.