From bc26626b6d2b7f72970efc7d3d1f158c735cbaef Mon Sep 17 00:00:00 2001 From: Adam Wentz Date: Fri, 7 Nov 2014 13:21:05 -0600 Subject: [PATCH] Added test for Content-subclass list view --- tests/content/test_content_views.py | 23 +++++++++++++++++++++-- tests/testcontent/views.py | 16 +++++++++++++++- tests/urls.py | 5 ++--- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/tests/content/test_content_views.py b/tests/content/test_content_views.py index d77a5a47..e83a1d44 100644 --- a/tests/content/test_content_views.py +++ b/tests/content/test_content_views.py @@ -1,13 +1,14 @@ from datetime import timedelta from django.contrib.auth import get_user_model +from django.contrib.contenttypes.models import ContentType from django.core.urlresolvers import reverse from django.test import Client from django.utils import timezone from elastimorphic.tests.base import BaseIndexableTestCase -from bulbs.content.models import ObfuscatedUrlInfo -from tests.testcontent.models import TestContentObj +from bulbs.content.models import FeatureType, ObfuscatedUrlInfo +from tests.testcontent.models import TestContentObj, TestContentObjTwo from tests.utils import make_content @@ -38,6 +39,24 @@ def published_article(self): response = self.client.get(reverse("published", kwargs={"pk": content.id})) self.assertEqual(response.status_code, 200) + def test_content_list_views(self): + ft = FeatureType.objects.create(name="Feature", slug="feature") + content = make_content(TestContentObj, feature_type=ft, published=timezone.now() - timedelta(hours=2)) + content_two = make_content(TestContentObjTwo, feature_type=ft, published=timezone.now() - timedelta(hours=2)) + # make sure we get all content with this list + TestContentObj.search_objects.refresh() + TestContentObjTwo.search_objects.refresh() + r = self.client.get(reverse("tests.testcontent.views.test_all_content_list")) + self.assertEqual(r.status_code, 200) + self.assertEqual(2, len(r.context_data["content_list"])) + # make sure we only get TestContentTwoObjs from this other list + r = self.client.get(reverse("tests.testcontent.views.test_content_two_list")) + self.assertEqual(r.status_code, 200) + self.assertEqual(1, len(r.context_data["content_list"])) + item = r.context_data["content_list"][0] + ctype = ContentType.objects.get_for_id(item.polymorphic_ctype) + self.assertIs(ctype.model_class(), TestContentObjTwo) + def test_base_content_detail_view_tokenized_url(self): """Test that we can get an article via a /unpublished/ style url.""" diff --git a/tests/testcontent/views.py b/tests/testcontent/views.py index 766a9142..8d6fc534 100644 --- a/tests/testcontent/views.py +++ b/tests/testcontent/views.py @@ -1,8 +1,22 @@ -from bulbs.content.views import BaseContentDetailView +from bulbs.content.views import BaseContentDetailView, ContentListView + +from .models import TestContentObjTwo + + +class AllContentListView(ContentListView): + template_name = "testapp/content_list.html" + + +class ContentTwoListView(ContentListView): + model = TestContentObjTwo + template_name = "testapp/content_list.html" class TestContentDetailView(BaseContentDetailView): """Test ContentDetailView that is based on the BaseContentDetailView as expected.""" template_name = "testapp/testcontentobj_detail.html" + test_content_detail = TestContentDetailView.as_view() +test_all_content_list = AllContentListView.as_view() +test_content_two_list = ContentTwoListView.as_view() diff --git a/tests/urls.py b/tests/urls.py index f0e31c96..8e4efb2b 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -4,9 +4,8 @@ urlpatterns = patterns("", url(r"^api/v1/", include("bulbs.api.urls")), # noqa - url(r"^content_list_one\.html", - ContentListView.as_view(template_name="testapp/content_list.html")), - + url(r"^content_list_one\.html", "tests.testcontent.views.test_all_content_list"), + url(r"^content_list_two\.html", "tests.testcontent.views.test_content_two_list"), # testing unpublished links url(r"^unpublished/(?P\w+)$", "bulbs.content.views.unpublished", name="unpublished"), url(r"^detail/(?P\d+)/$", "tests.testcontent.views.test_content_detail", name="published"),