Merge pull request #11476 from adityahase/fix-blog-post-pagination

This commit is contained in:
Aditya Hase 2020-09-10 13:44:27 +05:30 committed by GitHub
commit d618d5d120
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View file

@ -247,7 +247,7 @@ def get_blog_list(doctype, txt=None, filters=None, limit_start=0, limit_page_len
and t1.blogger = t2.name
%(condition)s
order by featured desc, published_on desc, name asc
limit %(start)s, %(page_len)s""" % {
limit %(page_len)s OFFSET %(start)s""" % {
"start": limit_start, "page_len": limit_page_length,
"condition": (" and " + " and ".join(conditions)) if conditions else ""
}

View file

@ -9,6 +9,8 @@ import re
from frappe.utils import set_request
from frappe.website.render import render
from frappe.utils import random_string
from frappe.website.doctype.blog_post.blog_post import get_blog_list
from frappe.website.website_generator import WebsiteGenerator
class TestBlogPost(unittest.TestCase):
def test_generator_view(self):
@ -60,12 +62,36 @@ class TestBlogPost(unittest.TestCase):
frappe.delete_doc("Blog Post", blog.name)
frappe.delete_doc("Blog Category", blog.blog_category)
def make_test_blog():
if not frappe.db.exists('Blog Category', 'test-blog-category'):
# Set different title and name for the category
def test_blog_pagination(self):
# Create some Blog Posts for a Blog Category
category_title, blogs, BLOG_COUNT = "List Category", [], 4
for index in range(BLOG_COUNT):
blog = make_test_blog(category_title)
blogs.append(blog)
filters = frappe._dict({"blog_category": scrub(category_title)})
# Assert that get_blog_list returns results as expected
self.assertEqual(len(get_blog_list(None, None, filters, 0, 3)), 3)
self.assertEqual(len(get_blog_list(None, None, filters, 0, BLOG_COUNT)), BLOG_COUNT)
self.assertEqual(len(get_blog_list(None, None, filters, 0, 2)), 2)
self.assertEqual(len(get_blog_list(None, None, filters, 2, BLOG_COUNT)), 2)
# Cleanup Blog Post and linked Blog Category
for blog in blogs:
frappe.delete_doc(blog.doctype, blog.name)
frappe.delete_doc("Blog Category", blogs[0].blog_category)
def scrub(text):
return WebsiteGenerator.scrub(None, text)
def make_test_blog(category_title="Test Blog Category"):
category_name = scrub(category_title)
if not frappe.db.exists('Blog Category', category_name):
frappe.get_doc(dict(
doctype = 'Blog Category',
title='Test Blog Category')).insert()
title=category_title)).insert()
if not frappe.db.exists('Blogger', 'test-blogger'):
frappe.get_doc(dict(
doctype = 'Blogger',
@ -73,7 +99,7 @@ def make_test_blog():
full_name='Test Blogger')).insert()
test_blog = frappe.get_doc(dict(
doctype = 'Blog Post',
blog_category = 'test-blog-category',
blog_category = category_name,
blogger = 'test-blogger',
title = random_string(20),
route = random_string(20),