Ticket #6888: month_tests.diff
File month_tests.diff, 4.1 KB (added by , 17 years ago) |
---|
-
tests/regressiontests/views/tests/generic/date_based.py
1 1 # coding: utf-8 2 2 from django.test import TestCase 3 from datetime import datetime 3 from datetime import datetime, date 4 4 from datetime import timedelta 5 from regressiontests.views.models import Article, Author 5 from regressiontests.views.models import Article, Author, Issue 6 6 7 7 class ObjectDetailTest(TestCase): 8 8 fixtures = ['testdata.json'] … … 67 67 article.save() 68 68 response = self.client.get('/views/date_based/archive_month/2004/02/') 69 69 self.assertEqual(response.status_code, 404) 70 71 72 No newline at end of file 70 71 def test_archive_month_midnight(self): 72 "Archive for month should not include item at start of next month" 73 february_issues = [ 74 Issue.objects.create(pub_date=date(2008, 2, 1)), 75 Issue.objects.create(pub_date=date(2008, 2, 10)), 76 Issue.objects.create(pub_date=date(2008, 2, 20)), 77 Issue.objects.create(pub_date=date(2008, 2, 29)), 78 ] 79 march_issues = [ 80 Issue.objects.create(pub_date=date(2008, 3, 1)), 81 Issue.objects.create(pub_date=datetime(2008, 3, 1, 0, 0, 0)), 82 Issue.objects.create(pub_date=date(2008, 3, 10)), 83 ] 84 85 self.assertEqual(Issue.objects.filter(pub_date__month=2).count(), len(february_issues)) 86 87 response = self.client.get('/views/date_based/issues/archive_month/2008/02/') 88 self.assertEqual(response.status_code, 200) 89 90 object_list = response.context['object_list'] 91 92 self.assertEqual(len(object_list), len(february_issues)) 93 for issue in object_list: 94 self.assertEqual(issue.pub_date.month, 2) -
tests/regressiontests/views/models.py
24 24 def __unicode__(self): 25 25 return self.title 26 26 27 28 class Issue(models.Model): 29 pub_date = models.DateTimeField() 30 31 def __unicode__(self): 32 return self.pub_date.strftime('%Y-%m-%d') -
tests/regressiontests/views/urls.py
14 14 'packages': ('regressiontests.views',), 15 15 } 16 16 17 date_based_info_dict = {17 article_date_based_info_dict = { 18 18 'queryset': Article.objects.all(), 19 19 'date_field': 'date_created', 20 20 'month_format': '%m', 21 21 } 22 22 23 issue_date_based_info_dict = { 24 'queryset': Issue.objects.all(), 25 'date_field': 'pub_date', 26 'month_format': '%m', 27 } 28 23 29 urlpatterns = patterns('', 24 30 (r'^$', views.index_page), 25 31 … … 38 44 # Date-based generic views 39 45 (r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$', 40 46 'django.views.generic.date_based.object_detail', 41 dict(slug_field='slug', ** date_based_info_dict)),47 dict(slug_field='slug', **article_date_based_info_dict)), 42 48 (r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/allow_future/$', 43 49 'django.views.generic.date_based.object_detail', 44 dict(allow_future=True, slug_field='slug', ** date_based_info_dict)),50 dict(allow_future=True, slug_field='slug', **article_date_based_info_dict)), 45 51 (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$', 46 52 'django.views.generic.date_based.archive_month', 47 date_based_info_dict), 53 article_date_based_info_dict), 54 55 (r'^date_based/issues/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$', 56 'django.views.generic.date_based.archive_month', 57 issue_date_based_info_dict), 48 58 )