mirror of
https://github.com/django/django.git
synced 2024-12-26 11:06:07 +00:00
0fcb094557
This patch is the result of the work of many people, over many years. To try and thank individuals would inevitably lead to many people being left out or forgotten -- so rather than try to give a list that will inevitably be incomplete, I'd like to thank *everybody* who contributed in any way, big or small, with coding, testing, feedback and/or documentation over the multi-year process of getting this into trunk. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14254 bcc190cf-cafb-0310-a4f2-bffc1f526a37
72 lines
3.4 KiB
Python
72 lines
3.4 KiB
Python
from django.core.exceptions import ImproperlyConfigured
|
|
from django.test import TestCase
|
|
|
|
from regressiontests.generic_views.models import Author, Page
|
|
|
|
|
|
class DetailViewTest(TestCase):
|
|
fixtures = ['generic-views-test-data.json']
|
|
urls = 'regressiontests.generic_views.urls'
|
|
|
|
def test_simple_object(self):
|
|
res = self.client.get('/detail/obj/')
|
|
self.assertEqual(res.status_code, 200)
|
|
self.assertEqual(res.context['object'], {'foo': 'bar'})
|
|
self.assertTemplateUsed(res, 'generic_views/detail.html')
|
|
|
|
def test_detail_by_pk(self):
|
|
res = self.client.get('/detail/author/1/')
|
|
self.assertEqual(res.status_code, 200)
|
|
self.assertEqual(res.context['object'], Author.objects.get(pk=1))
|
|
self.assertEqual(res.context['author'], Author.objects.get(pk=1))
|
|
self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
|
|
|
def test_detail_by_slug(self):
|
|
res = self.client.get('/detail/author/byslug/scott-rosenberg/')
|
|
self.assertEqual(res.status_code, 200)
|
|
self.assertEqual(res.context['object'], Author.objects.get(slug='scott-rosenberg'))
|
|
self.assertEqual(res.context['author'], Author.objects.get(slug='scott-rosenberg'))
|
|
self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
|
|
|
def test_template_name(self):
|
|
res = self.client.get('/detail/author/1/template_name/')
|
|
self.assertEqual(res.status_code, 200)
|
|
self.assertEqual(res.context['object'], Author.objects.get(pk=1))
|
|
self.assertEqual(res.context['author'], Author.objects.get(pk=1))
|
|
self.assertTemplateUsed(res, 'generic_views/about.html')
|
|
|
|
def test_template_name_suffix(self):
|
|
res = self.client.get('/detail/author/1/template_name_suffix/')
|
|
self.assertEqual(res.status_code, 200)
|
|
self.assertEqual(res.context['object'], Author.objects.get(pk=1))
|
|
self.assertEqual(res.context['author'], Author.objects.get(pk=1))
|
|
self.assertTemplateUsed(res, 'generic_views/author_view.html')
|
|
|
|
def test_template_name_field(self):
|
|
res = self.client.get('/detail/page/1/field/')
|
|
self.assertEqual(res.status_code, 200)
|
|
self.assertEqual(res.context['object'], Page.objects.get(pk=1))
|
|
self.assertEqual(res.context['page'], Page.objects.get(pk=1))
|
|
self.assertTemplateUsed(res, 'generic_views/page_template.html')
|
|
|
|
def test_context_object_name(self):
|
|
res = self.client.get('/detail/author/1/context_object_name/')
|
|
self.assertEqual(res.status_code, 200)
|
|
self.assertEqual(res.context['object'], Author.objects.get(pk=1))
|
|
self.assertEqual(res.context['thingy'], Author.objects.get(pk=1))
|
|
self.assertFalse('author' in res.context)
|
|
self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
|
|
|
def test_duplicated_context_object_name(self):
|
|
res = self.client.get('/detail/author/1/dupe_context_object_name/')
|
|
self.assertEqual(res.status_code, 200)
|
|
self.assertEqual(res.context['object'], Author.objects.get(pk=1))
|
|
self.assertFalse('author' in res.context)
|
|
self.assertTemplateUsed(res, 'generic_views/author_detail.html')
|
|
|
|
def test_invalid_url(self):
|
|
self.assertRaises(AttributeError, self.client.get, '/detail/author/invalid/url/')
|
|
|
|
def test_invalid_queryset(self):
|
|
self.assertRaises(ImproperlyConfigured, self.client.get, '/detail/author/invalid/qs/')
|