| 1 | # coding: utf-8 |
| 2 | from django.test import TestCase |
| 3 | from datetime import datetime |
| 4 | from models import Article |
| 5 | |
| 6 | _today = datetime.now() |
| 7 | _long_ago = datetime(2001, 1, 1) |
| 8 | _far_future = datetime(3000, 01, 01) |
| 9 | |
| 10 | class DateBasedGenericViewTest(TestCase): |
| 11 | def setUp(self): |
| 12 | current_article = Article(slug="current_article", date_created=_today) |
| 13 | current_article.save() |
| 14 | past_article = Article(slug="old_article", date_created=_long_ago) |
| 15 | past_article.save() |
| 16 | future_article = Article(slug="future_article", date_created=_far_future) |
| 17 | future_article.save() |
| 18 | |
| 19 | def test_object_detail_finds_past(self): |
| 20 | response = self.client.get('/generic_views/date_based/object_detail/2001/01/01/old_article/') |
| 21 | self.assertEqual(response.context['object'].slug, "old_article") |
| 22 | |
| 23 | def test_object_detail_finds_today(self): |
| 24 | today_url = _today.strftime('%Y/%m/%d') |
| 25 | response = self.client.get('/generic_views/date_based/object_detail/%s/current_article/' % today_url) |
| 26 | self.assertEqual(response.context['object'].slug, "current_article") |
| 27 | |
| 28 | def test_object_detail_ignores_future(self): |
| 29 | # careful, this is a year 3000 bug waiting to happen ;-) |
| 30 | response = self.client.get('/generic_views/date_based/object_detail/3000/jan/01/future_article/') |
| 31 | self.assertFalse(response.context.has_key('object')) |
| 32 | |
| 33 | # vim: expandtab tabstop=8 shiftwidth=4 autoindent |