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)
示例#2
0
from django.urls import path
from blog.views import (
    BlogListView,
    BlogDetailView,
    BlogCreateView,
    BlogUpdateView,
    BlogDeleteView,
    LikeBlog,
    CategoryView,
    BlogSearchView,
    BlogAuthorProfileView,
)

app_name = 'blog'

urlpatterns = [
    path('', BlogListView.as_view(), name='list'),
    path('search/', BlogSearchView.as_view(), name='search'),
    path('create/', BlogCreateView.as_view(), name='create'),
    path('<slug>/', BlogDetailView.as_view(), name='detail'),
    path('<slug>/update/', BlogUpdateView.as_view(), name='update'),
    path('<slug>/delete/', BlogDeleteView.as_view(), name='delete'),
    path('like/<slug>/', LikeBlog, name='like'),
    path('category/<str:category>/', CategoryView, name='category'),
    path('author/<int:pk>/', BlogAuthorProfileView.as_view(), name='author'),
]
示例#3
0
from django.conf.urls import patterns, url
from django.views.generic.base import RedirectView
from blog.sitemaps import BlogSitemap

from blog.views import BlogIndexView, BlogDetailView, \
     BlogPostsAtomFeed, BlogPostsRssFeed, TagDetailView, BlogSearchView, LegacyPostRedirectView

urlpatterns = patterns(
    '',

    # blog urls
    url(r'^$', BlogIndexView.as_view(), name="blog"),
    url(r'^search$', BlogSearchView.as_view(), name="blog_search"),
    url(r'^post/(?P<slug>[-\w]+)/$',
        BlogDetailView.as_view(),
        name="blog_detail"),
    url(r'^tag/(?P<slug>[-\w]+)/$',
        TagDetailView.as_view(),
        name="blog_tag_detail"),

    # rss & atom feed
    url(r'^feed/rss$', BlogPostsRssFeed(), name="blog_rss_feed"),
    url(r'^feed/atom', BlogPostsAtomFeed(), name="blog_atom_feed"),

    # sitemap
    url(r'^sitemap\.xml$',
        'django.contrib.sitemaps.views.sitemap',
        {'sitemaps': dict(blog=BlogSitemap())},
        name="blog_sitemap"),

    # legacy urls for oldest tumblr blog.
示例#4
0
from django.conf.urls import patterns, url
from django.views.generic.base import RedirectView
from blog.sitemaps import BlogSitemap

from blog.views import BlogIndexView, BlogDetailView, \
     BlogPostsAtomFeed, BlogPostsRssFeed, TagDetailView, BlogSearchView, LegacyPostRedirectView


urlpatterns = patterns('',

    # blog urls
    url(r'^$', BlogIndexView.as_view(), name="blog"),
    url(r'^search$', BlogSearchView.as_view(), name="blog_search"),
    url(r'^post/(?P<slug>[-\w]+)/$',
        BlogDetailView.as_view(), name="blog_detail"),
    url(r'^tag/(?P<slug>[-\w]+)/$',
        TagDetailView.as_view(), name="blog_tag_detail"),

    # rss & atom feed
    url(r'^feed/rss$', BlogPostsRssFeed(), name="blog_rss_feed"),
    url(r'^feed/atom', BlogPostsAtomFeed(), name="blog_atom_feed"),

    # sitemap
    url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': dict(
        blog=BlogSitemap()
    )}, name="blog_sitemap"),

    # legacy urls for oldest tumblr blog.
    url(r'^post/(?P<legacy_post_id>\d+)',
        LegacyPostRedirectView.as_view(), name="legacy_blog_detail"),
    url(r'^tagged/(?P<slug>[-\w]+)', RedirectView.as_view(
示例#5
0
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