Ticket #5506: 5506.diff
File 5506.diff, 6.9 KB (added by , 17 years ago) |
---|
-
tests/regressiontests/generic_views/tests.py
=== tests/regressiontests/generic_views/__init__.py ================================================================== === tests/regressiontests/generic_views/tests.py ==================================================================
1 # coding: utf-8 2 from django.test import TestCase 3 from datetime import datetime 4 from datetime import timedelta 5 from models import Article 6 7 _today = datetime.now() 8 _long_ago = datetime(2001, 1, 1) 9 _far_future = datetime(3000, 01, 01) 10 11 class DateBasedGenericViewTest(TestCase): 12 def setUp(self): 13 current_article = Article(slug="current_article", date_created=_today) 14 current_article.save() 15 past_article = Article(slug="old_article", date_created=_long_ago) 16 past_article.save() 17 future_article = Article(slug="future_article", date_created=_far_future) 18 future_article.save() 19 20 def test_object_detail_finds_past(self): 21 response = self.client.get('/generic_views/date_based/object_detail/2001/01/01/old_article/') 22 self.assertEqual(response.context['object'].slug, "old_article") 23 24 def test_object_detail_finds_today(self): 25 today_url = _today.strftime('%Y/%m/%d') 26 response = self.client.get('/generic_views/date_based/object_detail/%s/current_article/' % today_url) 27 self.assertEqual(response.context['object'].slug, "current_article") 28 29 def test_object_detail_ignores_future_unless_allowed(self): 30 # careful, this is a year 3000 bug waiting to happen ;-) 31 disallowed_response = self.client.get('/generic_views/date_based/object_detail/3000/01/01/future_article/') 32 self.assertEqual(disallowed_response.status_code, 404) 33 # the same view, with allow_future=True 34 allowed_response = self.client.get('/generic_views/date_based/object_detail/3000/01/01/future_article/allow_future/') 35 self.assertEqual(allowed_response.context['object'].slug, "future_article") 36 37 class MonthArchive(TestCase): 38 def test_archive_month_includes_only_month(self): 39 # 2004 was a leap year, so it should be weird enough to not cheat 40 first_second_of_feb = datetime(2004, 2, 1, 0, 0, 0) 41 first_second_of_mar = datetime(2004, 3, 1, 0, 0, 0) 42 one_microsecond = timedelta(0, 0, 1) 43 article = Article(slug="example") 44 45 article.date_created = first_second_of_feb 46 article.save() 47 response = self.client.get('/generic_views/date_based/archive_month/2004/02/') 48 self.assertEqual(response.status_code, 200) 49 50 article.date_created = first_second_of_feb-one_microsecond 51 article.save() 52 response = self.client.get('/generic_views/date_based/archive_month/2004/02/') 53 self.assertEqual(response.status_code, 404) 54 55 article.date_created = first_second_of_mar-one_microsecond 56 article.save() 57 response = self.client.get('/generic_views/date_based/archive_month/2004/02/') 58 self.assertEqual(response.status_code, 200) 59 60 article.date_created = first_second_of_mar 61 article.save() 62 response = self.client.get('/generic_views/date_based/archive_month/2004/02/') 63 self.assertEqual(response.status_code, 404) 64 65 66 # vim: expandtab tabstop=8 shiftwidth=4 autoindent -
tests/regressiontests/generic_views/models.py
=== tests/regressiontests/generic_views/models.py ==================================================================
1 # coding: utf-8 2 from django.db import models 3 4 class Article(models.Model): 5 slug = models.CharField(max_length=20) 6 date_created = models.DateTimeField() 7 def __repr__(self): 8 return "<Article: %s>" % self.slug 9 10 # vim: expandtab tabstop=8 shiftwidth=4 autoindent -
tests/regressiontests/generic_views/urls.py
=== tests/regressiontests/generic_views/urls.py ==================================================================
1 from django.conf.urls.defaults import * 2 from django.views.generic import date_based 3 from models import Article 4 5 info_dict = { 6 'queryset': Article.objects.all(), 7 'date_field': 'date_created', 8 'month_format': '%m', 9 } 10 11 urlpatterns = patterns('django.views.generic.date_based', 12 url(r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(slug_field='slug', **info_dict), name="object_detail"), 13 url(r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/allow_future/$', 'object_detail', dict(allow_future=True, slug_field='slug', **info_dict), name="object_detail_allow_future"), 14 url(r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$', 'archive_month', info_dict, name="archive_month"), 15 ) 16 17 18 # vim: autoindent tabstop=4 shiftwidth=4 expandtab 19 -
tests/urls.py
Property changes on: tests/regressiontests/generic_views ___________________________________________________________________ Name: svn:ignore +*.pyc === tests/urls.py ==================================================================
4 4 # test_client modeltest urls 5 5 (r'^test_client/', include('modeltests.test_client.urls')), 6 6 (r'^test_client_regress/', include('regressiontests.test_client_regress.urls')), 7 (r'^generic_views/', include('regressiontests.generic_views.urls')), 7 8 8 9 # Always provide the auth system login and logout views 9 10 (r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}), -
tests/templates/generic_views/article_detail.html
=== tests/templates/generic_views/article_detail.html ==================================================================
1 This template intentionally left blank. 2 -
tests/templates/generic_views/article_archive_month.html
=== tests/templates/generic_views/article_archive_month.html ==================================================================
1 This template intentionally left blank. 2