Exemplo n.º 1
0
    def test_articlecategoryarchiveview_get_queryset(self):
        view = ArticleCategoryArchiveView()
        view.request = self.factory.get('')
        view.request.pages = RequestPageManager(view.request)
        view.object = self.category

        self.assertListEqual(list(view.get_queryset()), [self.article])
Exemplo n.º 2
0
    def test_articlecategoryarchiveview_dispatch(self):
        view = ArticleCategoryArchiveView()
        view.request = self.factory.get('')
        view.request.pages = RequestPageManager(view.request)
        view.kwargs = {}

        dispatch = view.dispatch(view.request, slug='foo')
        self.assertListEqual(
            dispatch.template_name,
            ['news/article_category_archive.html', 'news/article_list.html'])
        self.assertEqual(dispatch.status_code, 200)
Exemplo n.º 3
0
    def test_articlefeedview_get(self):
        view = ArticleFeedView()
        view.request = self.factory.get('/news/feed/')
        view.request.pages = RequestPageManager(view.request)

        get = view.get(view.request)

        self.assertEqual(get.status_code, 200)

        # Handle single and double digit dates.
        self.assertIn(get['Content-Length'], ['376', '377'])

        self.assertEqual(get['Content-Type'], 'application/rss+xml; charset=utf-8')
Exemplo n.º 4
0
    def test_articlelistmixin_get_context_data(self):
        view = TestView()
        view.request = self.factory.get('/')
        view.request.pages = RequestPageManager(view.request)
        view.object_list = Article.objects.all()
        view.kwargs = {}

        data = view.get_context_data()

        self.assertEqual(list(data['article_list']), [self.article])
        self.assertEqual(list(data['object_list']), [self.article])
        self.assertEqual(list(data['category_list']), [self.category])
        self.assertEqual(repr(data['page_obj']), '<Page 1 of 1>')
        self.assertFalse(data['is_paginated'])
Exemplo n.º 5
0
    def test_articledetailview_get_context_data(self):
        view = ArticleDetailView()
        view.request = self.factory.get('/news/foo/')
        view.request.pages = RequestPageManager(view.request)
        view.object = self.article

        data = view.get_context_data()

        self.assertEqual(data['meta_description'], '')
        self.assertEqual(data['robots_follow'], True)
        self.assertEqual(list(data['category_list']), [self.category])
        self.assertEqual(data['robots_index'], True)
        self.assertEqual(data['title'], 'Foo')
        self.assertEqual(data['object'], self.article)
        self.assertEqual(data['robots_archive'], True)
        self.assertEqual(data['header'], 'Foo')
        self.assertEqual(data['article'], self.article)
        self.assertEqual(data['view'], view)
Exemplo n.º 6
0
    def test_articlecategoryarchiveview_get_context_data(self):
        view = ArticleCategoryArchiveView()
        view.request = self.factory.get('')
        view.request.pages = RequestPageManager(view.request)
        view.object = self.category
        view.object_list = Article.objects.all()
        view.kwargs = {}

        data = view.get_context_data()

        self.assertEqual(data['meta_description'], '')
        self.assertEqual(data['robots_follow'], True)
        self.assertEqual(list(data['category_list']), [self.category])
        self.assertEqual(data['robots_index'], True)
        self.assertEqual(data['title'], 'Foo')
        self.assertEqual(list(data['object_list']), [self.article])
        self.assertEqual(data['robots_archive'], True)
        self.assertEqual(data['header'], 'Foo')
        self.assertEqual(list(data['article_list']), [self.article])
        self.assertEqual(repr(data['page_obj']), '<Page 1 of 1>')
        self.assertEqual(data['category'], self.category)
        self.assertEqual(data['view'], view)
Exemplo n.º 7
0
    def test_faq_list_view_get_paginate_by(self):
        def setup_view(view, request, *args, **kwargs):
            """Mimic as_view() returned callable, but returns view instance.

            args and kwargs are the same you would pass to ``reverse()``

            """
            view.request = request
            view.args = args
            view.kwargs = kwargs
            return view

        self.factory = RequestFactory()
        request = self.factory.get('/')

        # Set the pages attribute manually as middleware isn't run in tests.
        request.pages = RequestPageManager(request.path, request.path_info)

        view = FaqListView()
        view = setup_view(view, request)
        view.dispatch(view.request, *view.args, **view.kwargs)

        self.assertEqual(view.get_paginate_by(view.get_queryset()), 5)
Exemplo n.º 8
0
    def test_articlelistmixin_get_queryset(self):
        view = TestView()
        view.request = self.factory.get('/')
        view.request.pages = RequestPageManager(view.request)

        self.assertListEqual(list(view.get_queryset()), [self.article])
Exemplo n.º 9
0
    def test_articlelistmixin_get_paginate_by(self):
        view = ArticleListMixin()
        view.request = self.factory.get('/')
        view.request.pages = RequestPageManager(view.request)

        self.assertEqual(view.get_paginate_by(None), 5)