From 28dd4c139e8ceba03257d5f8cee616fba2d000c2 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Mon, 4 Mar 2019 14:21:22 +0530 Subject: [PATCH] feat: Added test for Topic Doctype - Added test for get_contents function - Removed unused class functions --- erpnext/education/doctype/topic/test_topic.py | 39 ++++++++++++++++++- erpnext/education/doctype/topic/topic.py | 8 +--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/erpnext/education/doctype/topic/test_topic.py b/erpnext/education/doctype/topic/test_topic.py index 33e7e246fb..b014836228 100644 --- a/erpnext/education/doctype/topic/test_topic.py +++ b/erpnext/education/doctype/topic/test_topic.py @@ -7,4 +7,41 @@ import frappe import unittest 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 diff --git a/erpnext/education/doctype/topic/topic.py b/erpnext/education/doctype/topic/topic.py index b48593e36d..71bfc18c4d 100644 --- a/erpnext/education/doctype/topic/topic.py +++ b/erpnext/education/doctype/topic/topic.py @@ -13,10 +13,4 @@ class Topic(Document): content_data = [frappe.get_doc(course_content.content_type, course_content.content) for course_content in course_content_list] except Exception as e: return None - return content_data - - def get_first_content(self): - return self.get_contents()[0] - - def get_last_content(self): - return self.get_contents()[-1] + return content_data \ No newline at end of file