|
|
@@ -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), |
|
|
|