feat: Added test for Course Doctype

This commit is contained in:
scmmishra 2019-03-06 15:18:27 +05:30
parent 75defde940
commit 64347a5642
2 changed files with 32 additions and 28 deletions

View File

@ -19,30 +19,10 @@ class Course(Document):
if total_weightage != 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):
try:
topic_list = self.get_all_children()
topic_data = [frappe.get_doc("Topic", topic.topic) for topic in topic_list]
except frappe.DoesNotExistError:
return None
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]
return topic_data

View File

@ -2,6 +2,7 @@
# Copyright (c) 2015, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals
from erpnext.education.doctype.topic.test_topic import make_topic
import frappe
import unittest
@ -9,12 +10,35 @@ import unittest
# test_records = frappe.get_test_records('Course')
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):
course = frappe.get_doc({
"doctype": "Program",
"course_name": name,
"course_code": name
}).insert()
return course.name
try:
course = frappe.get_doc("Course", name)
except frappe.DoesNotExistError:
course = frappe.get_doc({
"doctype": "Course",
"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