diff --git a/erpnext/education/doctype/course_activity/course_activity.py b/erpnext/education/doctype/course_activity/course_activity.py index c890fade3e..28eafeae65 100644 --- a/erpnext/education/doctype/course_activity/course_activity.py +++ b/erpnext/education/doctype/course_activity/course_activity.py @@ -9,18 +9,10 @@ from frappe.model.document import Document class CourseActivity(Document): def validate(self): self.check_if_enrolled() - # self.check_if_course_present() + def check_if_enrolled(self): - pass - # programs_list = frappe.get_list("Program Enrollment", filters={'student': self.student_id}, fields=['program']) - # programs_enrolled_by_student = [item.program for item in programs_list] - # if self.program_name not in programs_enrolled_by_student: - # frappe.throw("Student {0} is not enrolled in program {1} ".format(self.student_id, self.program_name)) - - # def check_if_course_present(self): - # """ Get set of unique courses from lms_activity child table and make a list of it as assign it to course_list""" - # course_list = list(set([activity.course_name for activity in self.lms_activity])) - # current_program = frappe.get_doc('Program', self.program_name) - # courses_in_current_program = [course.course_name for course in current_program.courses] - # if len(set(courses_in_current_program) - set(course_list)) == 0: \ No newline at end of file + if frappe.db.exists("Course Enrollment", self.enrollment): + return True + else: + frappe.throw(_("Course Enrollment {0} does not exists".format(self.enrollment))) \ No newline at end of file diff --git a/erpnext/education/doctype/course_activity/test_course_activity.py b/erpnext/education/doctype/course_activity/test_course_activity.py index f014b16441..0c59c17a5d 100644 --- a/erpnext/education/doctype/course_activity/test_course_activity.py +++ b/erpnext/education/doctype/course_activity/test_course_activity.py @@ -6,5 +6,96 @@ from __future__ import unicode_literals import frappe import unittest +from erpnext.education.doctype.topic.test_topic import make_topic_and_linked_content +from erpnext.education.doctype.course.test_course import make_course_and_linked_topic +from erpnext.education.doctype.program.test_program import make_program_and_linked_courses + + +test_program = frappe._dict({ + "program_name": "_Test Program", + "course": [{ + "course_name": "_Test Course 1", + "topic": [ + { + "topic_name": "_Test Topic 1-1", + "content": [{ + "type": "Article", + "name": "_Test Article 1-1" + },{ + "type": "Article", + "name": "_Test Article 1-2" + } + ] + }, + { + "topic_name": "_Test Topic 1-2", + "content": [{ + "type": "Article", + "name": "_Test Article 1-3" + },{ + "type": "Article", + "name": "_Test Article 1-4" + } + ] + } + ] + }, + { + "course_name": "_Test Course 2", + "topic": [ + { + "topic_name": "_Test Topic 2-1", + "content": [{ + "type": "Article", + "name": "_Test Article 2-1" + },{ + "type": "Article", + "name": "_Test Article 2-2" + } + ] + }, + { + "topic_name": "_Test Topic 2-2", + "content": [{ + "type": "Article", + "name": "_Test Article 2-3" + },{ + "type": "Article", + "name": "_Test Article 2-4" + } + ] + } + ] + }] +}) + class TestCourseActivity(unittest.TestCase): - pass + def setUp(self): + pass + +def make_course_activity(enrollment, content_type, content): + activity = frappe.get_all("Course Activity", filters={'enrollment': enrollment, 'content_type': content_type, 'content': content}) + try: + activity = frappe.get_doc("Course Activity", activity[0]['name']) + except (IndexError, frappe.DoesNotExistError): + activity = frappe.get_doc({ + "doctype": "Course Activity", + "enrollment": enrollment, + "content_type": content_type, + "content": content, + "activity_date": frappe.utils.datetime.datetime.now() + }).insert() + return activity + +def setup_program(): + topic_list = [course['topic'] for course in test_program['course']] + for topic in topic_list[0]: + make_topic_and_linked_content(topic['topic_name'], topic['content']) + + all_courses_list = [{'course': course['course_name'], 'topic': [topic['topic_name'] for topic in course['topic']]} for course in test_program['course']] # returns [{'course': 'Applied Math', 'topic': ['Trignometry', 'Geometry']}] + for course in all_courses_list: + make_course_and_linked_topic(course['course'], course['topic']) + + course_list = [course['course_name'] for course in test_program['course']] + program = make_program_and_linked_courses(test_program.program_name, course_list) + return program