def test_get_model(self): view = FeaturedListView() user_content_type = ContentType.objects.get(app_label='auth', model='user').model_class() model_class = view.get_model('auth.user') self.assertEqual(user_content_type, model_class)
def test_get_category_template_names(self): view = FeaturedListView() view.get_context_data(self.category.slug, 'auth.user') expected = 'featured/%(slug)s_featured_list.html' % {'slug': self.category.slug} result = view.get_category_template_name() self.assertEqual(expected, result)
def test_get_model(self): view = FeaturedListView() user_content_type = ContentType.objects.get( app_label='auth', model='user').model_class() model_class = view.get_model('auth.user') self.assertEqual(user_content_type, model_class)
def test_get_category_template_names(self): view = FeaturedListView() view.get_context_data(self.category.slug, 'auth.user') expected = 'featured/%(slug)s_featured_list.html' % { 'slug': self.category.slug } result = view.get_category_template_name() self.assertEqual(expected, result)
def test_get_context_data(self): view = FeaturedListView() queryset = get_featured_queryset_for(User, category=self.category) context = view.get_context_data(self.category.slug, 'auth.user') self.assertEqual(2, len(context)) self.assertTrue('object_list' in context) self.assertEqual(list(queryset), list(context['object_list'])) self.assertTrue('user_list' in context) self.assertEqual(list(queryset), list(context['user_list']))
def test_get_context_data_when_inexistent_category_slug(self): view = FeaturedListView() self.assertRaises(Http404, view.get_context_data, slug='inexistent-cateogry-slug', model='auth.user')
def test_get_context_data_when_inexistent_model(self): view = FeaturedListView() self.assertRaises(Http404, view.get_context_data, slug=self.category.slug, model='auth.inexistentmodel')
def test_get_context_data_when_inactive_category(self): self.category.active = False self.category.save() view = FeaturedListView() self.assertRaises(Http404, view.get_context_data, slug=self.category.slug, model='auth.user')
from django.conf.urls.defaults import patterns, url from featured.views import FeaturedListView urlpatterns = patterns('', url(r'^(?P<slug>[-\w]+)/(?P<model>(\w+\.\w+))/$', FeaturedListView.as_view(), name='featured_category_list'), )
def test_get_object_name(self): view = FeaturedListView() object_name = view.get_object_name('auth.user') self.assertEqual('user_list', object_name)
def test_get_category(self): view = FeaturedListView() category_result = view.get_category(self.category.slug) self.assertEqual(self.category, category_result)
from django.conf.urls import url from featured.views import FeaturedListView urlpatterns = [ url(r'^(?P<slug>[-\w]+)/(?P<model>(\w+\.\w+))/$', FeaturedListView.as_view(), name='featured_category_list'), ]