示例#1
0
    def test_category_entries_view(self):
        pages = self.get_pages()
        posts = self.get_posts()

        with smart_override('en'):
            request = self.get_page_request(pages[1],
                                            self.user,
                                            lang='en',
                                            edit=True)
            view_obj = CategoryEntriesView()
            view_obj.request = request
            view_obj.namespace, view_obj.config = get_app_instance(request)
            view_obj.kwargs = {'category': 'category-1'}
            qs = view_obj.get_queryset()
            self.assertEqual(qs.count(), 3)
            self.assertEqual(set(qs), set([posts[0], posts[1], posts[2]]))

            view_obj.paginate_by = 1
            view_obj.object_list = qs
            context = view_obj.get_context_data(
                object_list=view_obj.object_list)
            self.assertTrue(context['category'])
            self.assertEqual(context['category'], self.category_1)
            self.assertTrue(context['is_paginated'])
            self.assertEqual(list(context['post_list']), [posts[0]])
            self.assertEqual(context['paginator'].count, 3)
            self.assertEqual(context['post_list'][0].title, 'First post')
            self.assertTrue(context['meta'])

            request = self.get_page_request(pages[1], self.user, edit=False)
            view_obj.request = request
            qs = view_obj.get_queryset()
            self.assertEqual(qs.count(), 1)
示例#2
0
    def test_category_entries_view(self):
        posts = self.get_posts()
        pages = self.get_pages()

        with smart_override('en'):
            request = self.get_page_request(pages[1], self.user, lang='en', edit=True)
            view_obj = CategoryEntriesView()
            view_obj.request = request
            view_obj.namespace, view_obj.config = get_app_instance(request)
            view_obj.kwargs = {'category': 'category-1'}
            qs = view_obj.get_queryset()
            self.assertEqual(qs.count(), 3)
            self.assertEqual(set(qs), set([posts[0], posts[1], posts[2]]))

            view_obj.paginate_by = 1
            view_obj.object_list = qs
            context = view_obj.get_context_data(object_list=view_obj.object_list)
            self.assertTrue(context['category'])
            self.assertEqual(context['category'], self.category_1)
            self.assertTrue(context['is_paginated'])
            self.assertEqual(list(context['post_list']), [posts[0]])
            self.assertEqual(context['paginator'].count, 3)
            self.assertEqual(context['post_list'][0].title, 'First post')

            request = self.get_page_request(pages[1], self.user, edit=False)
            view_obj.request = request
            qs = view_obj.get_queryset()
            self.assertEqual(qs.count(), 1)
示例#3
0
    def test_category_entries_view(self):
        page1, page2 = self.get_pages()
        post1, post2 = self.get_posts()

        request = self.get_page_request(page1,
                                        self.user,
                                        r'/en/blog/',
                                        edit=True)
        activate('en')
        view_obj = CategoryEntriesView()
        view_obj.request = request
        view_obj.kwargs = {'category': 'category-1'}
        qs = view_obj.get_queryset()
        self.assertEqual(qs.count(), 2)
        self.assertEqual(set(qs), set([post1, post2]))

        view_obj.paginate_by = 1
        view_obj.object_list = qs
        context = view_obj.get_context_data(object_list=view_obj.object_list)
        self.assertTrue(context['category'])
        self.assertEqual(context['category'], self.category_1)
        self.assertTrue(context['is_paginated'])
        self.assertEqual(list(context['post_list']), [post2])
        self.assertEqual(context['paginator'].count, 2)
        self.assertEqual(context['post_list'][0].title, 'Second post')
    def test_category_entries_view(self):
        pages = self.get_pages()
        posts = self.get_posts()

        with smart_override("en"):
            request = self.get_page_request(pages[1], self.user, lang="en", edit=True)
            view_obj = CategoryEntriesView()
            view_obj.request = request
            view_obj.namespace, view_obj.config = get_app_instance(request)
            view_obj.kwargs = {"category": "category-1"}
            qs = view_obj.get_queryset()
            self.assertEqual(qs.count(), 3)
            self.assertEqual(set(qs), {posts[0], posts[1], posts[2]})

            view_obj.paginate_by = 1
            view_obj.object_list = qs
            context = view_obj.get_context_data(object_list=view_obj.object_list)
            self.assertTrue(context["category"])
            self.assertEqual(context["category"], self.category_1)
            self.assertTrue(context["is_paginated"])
            self.assertEqual(list(context["post_list"]), [posts[0]])
            self.assertEqual(context["paginator"].count, 3)
            self.assertEqual(context["post_list"][0].title, "First post")
            self.assertTrue(context["meta"])

            request = self.get_page_request(pages[1], self.user, edit=False)
            view_obj.request = request
            qs = view_obj.get_queryset()
            self.assertEqual(qs.count(), 1)
示例#5
0
 def test_non_existing_blog_category_should_raise_404(self):
     pages = self.get_pages()
     with smart_override('en'):
         request = self.get_request(pages[1], 'en', AnonymousUser())
         view_obj = CategoryEntriesView()
         view_obj.request = request
         view_obj.namespace, view_obj.config = get_app_instance(request)
         with self.assertRaises(Http404):
             view_obj.kwargs = {'category': 'unknown-category'}
             view_obj.get_queryset()
 def test_non_existing_blog_category_should_raise_404(self):
     pages = self.get_pages()
     with smart_override('en'):
         request = self.get_request(pages[1], 'en', AnonymousUser())
         view_obj = CategoryEntriesView()
         view_obj.request = request
         view_obj.namespace, view_obj.config = get_app_instance(request)
         with self.assertRaises(Http404):
             view_obj.kwargs = {'category': 'unknown-category'}
             view_obj.get_queryset()
示例#7
0
    def test_category_entries_view(self):
        page1, page2 = self.get_pages()
        post1, post2 = self.get_posts()

        request = self.get_page_request(page1, self.user, r'/en/blog/', edit=False)
        activate('en')
        view_obj = CategoryEntriesView()
        view_obj.request = request
        view_obj.kwargs = {'category': 'category-1'}
        qs = view_obj.get_queryset()
        self.assertEqual(qs.count(), 2)
        self.assertEqual(set(qs), set([post1, post2]))

        view_obj.paginate_by = 1
        view_obj.object_list = qs
        context = view_obj.get_context_data(object_list=view_obj.object_list)
        self.assertTrue(context['category'])
        self.assertEqual(context['category'], self.category_1)
        self.assertTrue(context['is_paginated'])
        self.assertEqual(list(context['post_list']), [post2])
        self.assertEqual(context['paginator'].count, 2)
        self.assertEqual(context['post_list'][0].title, 'Second post')