feat: Moved setup_program to test_program.py

This commit is contained in:
scmmishra 2019-03-14 15:32:22 +05:30
parent a98e936d26
commit 8aa6ac7b03
3 changed files with 44 additions and 59 deletions

View File

@ -6,43 +6,11 @@ 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
from erpnext.education.doctype.student.test_student import create_student
from erpnext.education.doctype.student.test_student import get_student
test_data = 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"
}
]
}
]
}]
})
from erpnext.education.doctype.program.test_program import setup_program
class TestCourseEnrollment(unittest.TestCase):
def setUp(self):
@ -60,6 +28,7 @@ class TestCourseEnrollment(unittest.TestCase):
progress = course_enrollment.get_progress(student)
finished = {'content': '_Test Article 1-1', 'content_type': 'Article', 'is_complete': True}
self.assertTrue(finished in progress)
frappe.db.rollback()
def make_course_activity(enrollment, content_type, content):
@ -75,16 +44,3 @@ def make_course_activity(enrollment, content_type, content):
"activity_date": frappe.utils.datetime.datetime.now()
}).insert()
return activity
def setup_program():
topic_list = [course['topic'] for course in test_data['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_data['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_data['course']]
program = make_program_and_linked_courses(test_data.program_name, course_list)
return program

View File

@ -3,11 +3,13 @@
# See license.txt
from __future__ import unicode_literals
from erpnext.education.doctype.course.test_course import make_course
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
import frappe
import unittest
# test_records = frappe.get_test_records('Program')
test_data = frappe.get_test_records('Program')
class TestProgram(unittest.TestCase):
def setUp(self):
@ -42,3 +44,15 @@ def make_program_and_linked_courses(program_name, course_name_list):
program.save()
return program
def setup_program():
topic_list = [course['topic'] for course in test_data['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_data['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_data['course']]
program = make_program_and_linked_courses(test_data['program_name'], course_list)
return program

View File

@ -1,12 +1,27 @@
[
{
"program_name": "_Test Program",
"program_code": "_TP1",
"program_abbreviation": "TP1"
},
{
"program_name": "_Test Program 2",
"program_code": "_TP2",
"program_abbreviation": "TP2"
}
]
{
"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"
}]
}
]
}]
}