def test_view_expired_news(self):
        """
        Make sure that an expired news isn't accessible
        """

        pk = NewsFactory.create(expired=True).id

        request = self.factory.get('/api/news/{}'.format(pk))
        response = NewsView.as_view()(request, pk=pk)

        self.assertEqual(response.status_code, 404)
    def test_view_one_news(self):
        """
        Make sure single news view returns a 200 status code
        """

        pk = NewsFactory.create().id

        request = self.factory.get('/api/news/{}'.format(pk))
        response = NewsView.as_view()(request, pk=pk)

        self.assertEqual(response.status_code, 200)
Пример #3
0
from django.conf.urls import url

from networkapi.news.views import (
    NewsListView,
    NewsView,
)

urlpatterns = [
    url('^$', NewsListView.as_view(), name='news-list'),
    url(r'^(?P<pk>[0-9]+)/', NewsView.as_view(), name='news'),
]