Skip to content
Browse files

Complete the tests of view with USE_TZ alternatively set to True and …

…False, closes #233
  • Loading branch information...
1 parent 6256c75 commit 2d012e54d16f57074283116c9fb603292b34b4e8 @Fantomas42 committed Apr 29, 2013
Showing with 37 additions and 10 deletions.
  1. +1 −1 docs/development/tests.rst
  2. +36 −9 zinnia/tests/views.py
View
2 docs/development/tests.rst
@@ -51,7 +51,7 @@ Coverage
Despite my best efforts, some functionnalities are not yet tested, that's why
I need your help !
-As I write these lines the **160** tests in Zinnia cover **96%** of the code
+As I write these lines the **164** tests in Zinnia cover **96%** of the code
bundled in Zinnia. A real effort has been made to obtain this percentage,
for ensuring the quality of the code.
View
45 zinnia/tests/views.py
@@ -25,6 +25,10 @@
@skipIfCustomUser
+@override_settings(
+ TEMPLATE_CONTEXT_PROCESSORS=(
+ 'django.core.context_processors.request',
+ ))
class ViewsBaseCase(TestCase):
"""
Setup and utility function base case.
@@ -101,11 +105,6 @@ def check_capabilities(self, url, mimetype, queries=0):
self.assertEquals(response['Content-Type'], mimetype)
self.assertTrue('protocol' in response.context)
-ViewsBaseCase = override_settings(
- TEMPLATE_CONTEXT_PROCESSORS=(
- 'django.core.context_processors.request',
- ))(ViewsBaseCase)
-
class ZinniaViewsTestCase(ViewsBaseCase):
"""
@@ -124,7 +123,8 @@ def tearDown(self):
except AttributeError:
pass
- def test_zinnia_entry_archive_index(self):
+ @override_settings(USE_TZ=False)
+ def test_zinnia_entry_archive_index_no_timezone(self):
template_name_today = 'zinnia/archives/%s/entry_archive.html' % \
date.today().strftime('%Y/%m/%d')
setup_test_template_loader(
@@ -134,6 +134,18 @@ def test_zinnia_entry_archive_index(self):
self.assertTemplateUsed(response, template_name_today)
restore_template_loaders()
+ @override_settings(USE_TZ=True, TIME_ZONE='Europe/Paris')
+ def test_zinnia_entry_archive_index_with_timezone(self):
+ template_name_today = 'zinnia/archives/%s/entry_archive.html' % \
+ timezone.localtime(timezone.now()
+ ).strftime('%Y/%m/%d')
+ setup_test_template_loader(
+ {template_name_today: ''})
+ response = self.check_publishing_context(
+ '/', 2, 3, 'entry_list', 2)
+ self.assertTemplateUsed(response, template_name_today)
+ restore_template_loaders()
+
def test_zinnia_entry_archive_year(self):
setup_test_template_loader(
{'zinnia/archives/2010/entry_archive_year.html': ''})
@@ -193,14 +205,29 @@ def test_zinnia_entry_archive_day(self):
self.assertEquals(response.context['next_day'], None)
restore_template_loaders()
- def test_zinnia_entry_archive_today(self):
+ @override_settings(USE_TZ=False)
+ def test_zinnia_entry_archive_today_no_timezone(self):
setup_test_template_loader(
{'zinnia/entry_archive_today.html': ''})
with self.assertNumQueries(5):
response = self.client.get('/today/')
- self.assertEquals(response.context['day'], timezone.localtime(
- timezone.now()).date())
self.assertTemplateUsed(response, 'zinnia/entry_archive_today.html')
+ self.assertEquals(response.context['day'].date(), date.today())
+ self.assertEquals(response.context['previous_month'], date(2010, 6, 1))
+ self.assertEquals(response.context['next_month'], None)
+ self.assertEquals(response.context['previous_day'], date(2010, 6, 1))
+ self.assertEquals(response.context['next_day'], None)
+ restore_template_loaders()
+
+ @override_settings(USE_TZ=True, TIME_ZONE='Europe/Paris')
+ def test_zinnia_entry_archive_today_with_timezone(self):
+ setup_test_template_loader(
+ {'zinnia/entry_archive_today.html': ''})
+ with self.assertNumQueries(5):
+ response = self.client.get('/today/')
+ self.assertTemplateUsed(response, 'zinnia/entry_archive_today.html')
+ self.assertEquals(response.context['day'].date(), timezone.localtime(
+ timezone.now()).date())
self.assertEquals(response.context['previous_month'], date(2010, 6, 1))
self.assertEquals(response.context['next_month'], None)
self.assertEquals(response.context['previous_day'], date(2010, 6, 1))

3 comments on commit 2d012e5

@bryanhelmig

:+1: Any chance for a 0.12.4 for this fix?

@Fantomas42
Owner

The branch 0.12 is dedicated for Django 1.4, and the bug is related to Django 1.5 only, so I don't see the utility to build a new release for that.

@bryanhelmig

Gotcha, no worries.

Please sign in to comment.
Something went wrong with that request. Please try again.