Przeglądaj źródła

fix: add tests

version-14
Rushabh Mehta 6 lat temu
rodzic
commit
a1eb5bf9b3
4 zmienionych plików z 62 dodań i 4 usunięć
  1. +33
    -2
      frappe/core/doctype/comment/test_comment.py
  2. +1
    -0
      frappe/patches.txt
  3. +3
    -2
      frappe/templates/includes/comments/comments.py
  4. +25
    -0
      frappe/website/doctype/blog_post/test_blog_post.py

+ 33
- 2
frappe/core/doctype/comment/test_comment.py Wyświetl plik

@@ -3,8 +3,39 @@
# See license.txt
from __future__ import unicode_literals

import frappe
import frappe, json
import unittest

class TestComment(unittest.TestCase):
pass
def test_comment_creation(self):
test_doc = frappe.get_doc(dict(doctype = 'ToDo', description = 'test'))
test_doc.insert()
comment = test_doc.add_comment('Comment', 'test comment')

test_doc.reload()

# check if updated in _comments cache
comments = json.loads(test_doc.get('_comments'))
self.assertEqual(comments[0].get('name'), comment.name)
self.assertEqual(comments[0].get('comment'), comment.content)

# check document creation
comment_1 = frappe.get_all('Comment', fields = ['*'], filters = dict(
reference_doctype = test_doc.doctype,
reference_name = test_doc.name
))[0]

self.assertEqual(comment_1.content, 'test comment')

# test via blog
def test_public_comment(self):
from frappe.website.doctype.blog_post.test_blog_post import make_test_blog
test_blog = make_test_blog()

from frappe.templates.includes.comments.comments import add_comment
add_comment('hello', 'test@test.com', 'Good Tester',
'Blog Post', test_blog.name, test_blog.route)





+ 1
- 0
frappe/patches.txt Wyświetl plik

@@ -9,6 +9,7 @@ execute:frappe.reload_doc('core', 'doctype', 'doctype', force=True) #2017-09-22
execute:frappe.reload_doc('core', 'doctype', 'docfield', force=True) #2018-02-20
execute:frappe.reload_doc('core', 'doctype', 'custom_docperm')
execute:frappe.reload_doc('core', 'doctype', 'docperm') #2018-05-29
execute:frappe.reload_doc('core', 'doctype', 'comment')
frappe.patches.v8_0.drop_is_custom_from_docperm
execute:frappe.reload_doc('core', 'doctype', 'module_def') #2017-09-22
execute:frappe.reload_doc('core', 'doctype', 'version') #2017-04-01


+ 3
- 2
frappe/templates/includes/comments/comments.py Wyświetl plik

@@ -24,7 +24,8 @@ def add_comment(comment, comment_email, comment_by, reference_doctype, reference
comment.db_set('published', 1)

# since comments are embedded in the page, clear the web cache
clear_cache(route)
if route:
clear_cache(route)

content = (doc.content
+ "<p><a href='{0}/desk/#Form/Comment/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
@@ -33,7 +34,7 @@ def add_comment(comment, comment_email, comment_by, reference_doctype, reference

# notify creator
frappe.sendmail(
recipients = frappe.get_doc('User', doc.owner, 'email') or doc.owner,
recipients = frappe.db.get_value('User', doc.owner, 'email') or doc.owner,
subject = _('New Comment on {0}: {1}').format(doc.doctype, doc.name),
message = content,
reference_doctype=doc.doctype,


+ 25
- 0
frappe/website/doctype/blog_post/test_blog_post.py Wyświetl plik

@@ -6,6 +6,7 @@ import unittest

from frappe.tests.test_website import set_request
from frappe.website.render import render
from frappe.utils import random_string

class TestBlogPost(unittest.TestCase):
def test_generator_view(self):
@@ -30,3 +31,27 @@ class TestBlogPost(unittest.TestCase):
response = render()

self.assertTrue(response.status_code, 404)

def make_test_blog():
if not frappe.db.exists('Blog Category', 'Test Blog Category'):
frappe.get_doc(dict(
doctype = 'Blog Category',
category_name = 'Test Blog Category',
title='Test Blog Category')).insert()
if not frappe.db.exists('Blogger', 'test-blogger'):
blogger = frappe.get_doc(dict(
doctype = 'Blogger',
short_name='test-blogger',
full_name='Test Blogger')).insert()
test_blog = frappe.get_doc(dict(
doctype = 'Blog Post',
blog_category = 'Test Blog Category',
blogger = 'test-blogger',
title = random_string(20),
route = random_string(20),
content = random_string(20),
published = 1
)).insert()

return test_blog


Ładowanie…
Anuluj
Zapisz