feat: Added test for Topic Doctype
- Added test for get_contents function
- Removed unused class functions
diff --git a/erpnext/education/doctype/topic/test_topic.py b/erpnext/education/doctype/topic/test_topic.py
index 33e7e24..b014836 100644
--- a/erpnext/education/doctype/topic/test_topic.py
+++ b/erpnext/education/doctype/topic/test_topic.py
@@ -7,4 +7,41 @@
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 b48593e..71bfc18 100644
--- a/erpnext/education/doctype/topic/topic.py
+++ b/erpnext/education/doctype/topic/topic.py
@@ -13,10 +13,4 @@
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