Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Added test for Content-subclass list view
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wentz committed Nov 7, 2014
1 parent 8ec951f commit bc26626
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
23 changes: 21 additions & 2 deletions 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


Expand Down Expand Up @@ -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/<token> style url."""

Expand Down
16 changes: 15 additions & 1 deletion 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()
5 changes: 2 additions & 3 deletions tests/urls.py
Expand Up @@ -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<token>\w+)$", "bulbs.content.views.unpublished", name="unpublished"),
url(r"^detail/(?P<pk>\d+)/$", "tests.testcontent.views.test_content_detail", name="published"),
Expand Down

0 comments on commit bc26626

Please sign in to comment.