mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 13:49:13 +00:00
feat: Added test for Course Doctype
This commit is contained in:
@@ -19,30 +19,10 @@ class Course(Document):
|
|||||||
if total_weightage != 100:
|
if total_weightage != 100:
|
||||||
frappe.throw(_("Total Weightage of all Assessment Criteria must be 100%"))
|
frappe.throw(_("Total Weightage of all Assessment Criteria must be 100%"))
|
||||||
|
|
||||||
def get_contents_based_on_type(self):
|
|
||||||
contents= self.get_contents()
|
|
||||||
quiz_list = [item for item in contents if item.doctype=="Quiz"]
|
|
||||||
content_list = [item for item in contents if item.doctype!="Quiz"]
|
|
||||||
return content_list, quiz_list
|
|
||||||
|
|
||||||
def get_topics(self):
|
def get_topics(self):
|
||||||
try:
|
try:
|
||||||
topic_list = self.get_all_children()
|
topic_list = self.get_all_children()
|
||||||
topic_data = [frappe.get_doc("Topic", topic.topic) for topic in topic_list]
|
topic_data = [frappe.get_doc("Topic", topic.topic) for topic in topic_list]
|
||||||
except frappe.DoesNotExistError:
|
except frappe.DoesNotExistError:
|
||||||
return None
|
return None
|
||||||
return topic_data
|
return topic_data
|
||||||
|
|
||||||
def get_contents(self):
|
|
||||||
try:
|
|
||||||
topics = self.get_topics()
|
|
||||||
content_data = [{'name':topic.name, 'topic_name': topic.topic_name ,'content':topic.get_contents()} for topic in topics]
|
|
||||||
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]
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies and Contributors
|
# Copyright (c) 2015, Frappe Technologies and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from erpnext.education.doctype.topic.test_topic import make_topic
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
import unittest
|
import unittest
|
||||||
@@ -9,12 +10,35 @@ import unittest
|
|||||||
# test_records = frappe.get_test_records('Course')
|
# test_records = frappe.get_test_records('Course')
|
||||||
|
|
||||||
class TestCourse(unittest.TestCase):
|
class TestCourse(unittest.TestCase):
|
||||||
pass
|
def setUp(self):
|
||||||
|
make_course_and_linked_topic("_Test Course 1", ["_Test Topic 1", "_Test Topic 2"])
|
||||||
|
|
||||||
|
def test_get_topics(self):
|
||||||
|
course = frappe.get_doc("Course", "_Test Course 1")
|
||||||
|
topics = course.get_topics()
|
||||||
|
self.assertEqual(topics[0].name, "_Test Topic 1")
|
||||||
|
self.assertEqual(topics[1].name, "_Test Topic 2")
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
def make_course(name):
|
def make_course(name):
|
||||||
course = frappe.get_doc({
|
try:
|
||||||
"doctype": "Program",
|
course = frappe.get_doc("Course", name)
|
||||||
"course_name": name,
|
except frappe.DoesNotExistError:
|
||||||
"course_code": name
|
course = frappe.get_doc({
|
||||||
}).insert()
|
"doctype": "Course",
|
||||||
return course.name
|
"course_name": name,
|
||||||
|
"course_code": name
|
||||||
|
}).insert()
|
||||||
|
return course.name
|
||||||
|
|
||||||
|
def make_course_and_linked_topic(course_name, topic_name_list):
|
||||||
|
try:
|
||||||
|
course = frappe.get_doc("Course", course_name)
|
||||||
|
except frappe.DoesNotExistError:
|
||||||
|
make_course(course_name)
|
||||||
|
course = frappe.get_doc("Course", course_name)
|
||||||
|
topic_list = [make_topic(topic_name) for topic_name in topic_name_list]
|
||||||
|
for topic in topic_list:
|
||||||
|
course.append("topics", {"topic": topic})
|
||||||
|
course.save()
|
||||||
|
return course
|
||||||
|
|||||||
Reference in New Issue
Block a user