def test_blog_search_view_paginator(rf): url = reverse('blog:search') request = rf.get(url) view = BlogSearchView() view.request = request paginator, page = view.build_page() assert isinstance(paginator, Paginator)
def test_blog_search_view_invalid_page_number(rf): url = reverse("blog:search") request = rf.get(url, data={"page": "a"}) view = BlogSearchView() view.request = request with pytest.raises(Http404): assert view.build_page() request = rf.get(url, data={"page": -1}) view = BlogSearchView() view.request = request with pytest.raises(Http404): assert view.build_page() # Always redirect to page 1 request = rf.get(url, data={"page": 99999}) view = BlogSearchView() view.request = request paginator, page = view.build_page() assert page.number == 1