feat: Added test for Topic Doctype
- Added test for get_contents function - Removed unused class functions
This commit is contained in:
parent
471140c6d4
commit
28dd4c139e
@ -7,4 +7,41 @@ import frappe
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestTopic(unittest.TestCase):
|
class TestTopic(unittest.TestCase):
|
||||||
pass
|
def setUp(self):
|
||||||
|
make_topic_and_linked_content("_Test Topic 1", [{"type":"Article", "name": "_Test Article 1"}])
|
||||||
|
|
||||||
|
def test_get_contents(self):
|
||||||
|
topic = frappe.get_doc("Topic", "_Test Topic 1")
|
||||||
|
self.assertEqual(topic.name, "_Test Topic 1")
|
||||||
|
contents = topic.get_contents()
|
||||||
|
self.assertEqual(contents[0].doctype, "Article")
|
||||||
|
self.assertEqual(contents[0].name, "_Test Article 1")
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
|
def make_topic(name):
|
||||||
|
topic = frappe.get_doc({
|
||||||
|
"doctype": "Topic",
|
||||||
|
"topic_name": name,
|
||||||
|
"topic_code": name,
|
||||||
|
}).insert()
|
||||||
|
return topic.name
|
||||||
|
|
||||||
|
def make_topic_and_linked_content(topic_name, content_dict_list):
|
||||||
|
try:
|
||||||
|
topic = frappe.get_doc("Topic", topic_name)
|
||||||
|
except frappe.DoesNotExistError:
|
||||||
|
make_topic(topic_name)
|
||||||
|
topic = frappe.get_doc("Topic", topic_name)
|
||||||
|
content_list = [make_content(content['type'], content['name']) for content in content_dict_list]
|
||||||
|
for content in content_list:
|
||||||
|
topic.append("topic_content", {"content": content.title, "content_type": content.doctype})
|
||||||
|
topic.save()
|
||||||
|
return topic
|
||||||
|
|
||||||
|
|
||||||
|
def make_content(type, name):
|
||||||
|
try:
|
||||||
|
content = frappe.get_doc(type, name)
|
||||||
|
except frappe.DoesNotExistError:
|
||||||
|
content = frappe.get_doc({"doctype": type, "title": name}).insert()
|
||||||
|
return content
|
||||||
|
@ -14,9 +14,3 @@ class Topic(Document):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return None
|
return None
|
||||||
return content_data
|
return content_data
|
||||||
|
|
||||||
def get_first_content(self):
|
|
||||||
return self.get_contents()[0]
|
|
||||||
|
|
||||||
def get_last_content(self):
|
|
||||||
return self.get_contents()[-1]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user