Student group creation (#10308)

* auto-fills groups with students

* improvised and rectified tests

* increased timer to avoid rare failures

* removed duplicate code

* requested changes implemented

* changes implemented
diff --git a/erpnext/schools/doctype/student_group/student_group.py b/erpnext/schools/doctype/student_group/student_group.py
index 55f1b66..0a7fdf1 100644
--- a/erpnext/schools/doctype/student_group/student_group.py
+++ b/erpnext/schools/doctype/student_group/student_group.py
@@ -68,7 +68,8 @@
 			student_list.append(s)
 		return student_list
 	else:
-		frappe.throw(_("No students found"))
+		frappe.msgprint(_("No students found"))
+		return []
 
 def get_program_enrollment(academic_year, academic_term=None, program=None, batch=None, course=None):
 	
diff --git a/erpnext/schools/doctype/student_group/test_student_group.js b/erpnext/schools/doctype/student_group/test_student_group.js
index 842d0ba..df72ae9 100644
--- a/erpnext/schools/doctype/student_group/test_student_group.js
+++ b/erpnext/schools/doctype/student_group/test_student_group.js
@@ -5,50 +5,59 @@
 	assert.expect(2);
 	let done = assert.async();
 	let instructor_code;
-	let loop = ["test-batch-wise-group", "test-course-wise-group"];
+	let group_based_on = ["test-batch-wise-group", "test-course-wise-group"];
 	let tasks = [];
 
 	frappe.run_serially([
 		// Saving Instructor code beforehand
-		() => frappe.set_route('List', 'Instructor'),
-		() => frappe.timeout(0.5),
-		() => frappe.tests.click_link('Instructor 1'),
-		() => frappe.timeout(0.5),
-		() => {instructor_code = frappe.get_route()[2];},
+		() => frappe.db.get_value('Instructor', {'instructor_name': 'Instructor 1'}, 'name'),
+		(instructor) => {instructor_code = instructor.message.name;},
 
 		// Creating a Batch and Course based group
 		() => {
-			loop.forEach(index => {
-				tasks.push(() => {
-					return frappe.tests.make('Student Group', [
-						{academic_year: '2016-17'},
-						{academic_term: '2016-17 (Semester 1)'},
-						{program: "Standard Test"},
-						{group_based_on: 'Batch'},
-						{student_group_name: index},
-						{max_strength: 10},
-						{batch: 'A'},
-						{instructors: [
-							[
-								{instructor: instructor_code}
-							]
-						]}
-					]);
-				});
-			});
-			return frappe.run_serially(tasks);
+			return frappe.tests.make('Student Group', [
+				{academic_year: '2016-17'},
+				{academic_term: '2016-17 (Semester 1)'},
+				{program: "Standard Test"},
+				{group_based_on: 'Batch'},
+				{student_group_name: group_based_on[0]},
+				{max_strength: 10},
+				{batch: 'A'},
+				{instructors: [
+					[
+						{instructor: instructor_code}
+					]
+				]}
+			]);
+		},
+		() => {
+			return frappe.tests.make('Student Group', [
+				{academic_year: '2016-17'},
+				{academic_term: '2016-17 (Semester 1)'},
+				{program: "Standard Test"},
+				{group_based_on: 'Course'},
+				{student_group_name: group_based_on[1]},
+				{max_strength: 10},
+				{batch: 'A'},
+				{course: 'Test_Sub'},
+				{instructors: [
+					[
+						{instructor: instructor_code}
+					]
+				]}
+			]);
 		},
 
 		// Populating the created group with Students
 		() => {
 			tasks = [];
-			loop.forEach(index => {
+			group_based_on.forEach(index => {
 				tasks.push(
-					() => frappe.timeout(0.3),
+					() => frappe.timeout(0.5),
 					() => frappe.set_route("Form", ('Student Group/' + index)),
-					() => frappe.timeout(0.3),
+					() => frappe.timeout(0.5),
 					() => frappe.tests.click_button('Get Students'),
-					() => frappe.timeout(0.2),
+					() => frappe.timeout(0.5),
 					() => {
 						assert.equal(cur_frm.doc.students.length, 5, 'Successfully fetched list of students');
 					},
diff --git a/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.py b/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.py
index 4a4cec7..649e5da 100644
--- a/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.py
+++ b/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.py
@@ -6,6 +6,7 @@
 import frappe
 from frappe import _
 from frappe.model.document import Document
+from erpnext.schools.doctype.student_group.student_group import get_students
 
 class StudentGroupCreationTool(Document):
 	def get_courses(self):
@@ -67,6 +68,10 @@
 			student_group.max_strength = d.max_strength
 			student_group.academic_term = self.academic_term
 			student_group.academic_year = self.academic_year
+			student_list = get_students(self.academic_year, d.group_based_on, self.academic_term, self.program, d.batch, d.course)
+
+			for student in student_list:
+				student_group.append('students', student)
 			student_group.save()
 
-		frappe.msgprint(_("{0} Student Groups created.".format(l)))
+		frappe.msgprint(_("{0} Student Groups created.".format(l)))
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js b/erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js
index c0b4dc8..366822e 100644
--- a/erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js
+++ b/erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js
@@ -7,11 +7,8 @@
 
 	frappe.run_serially([
 		// Saving Instructor code beforehand
-		() => frappe.set_route('List', 'Instructor'),
-		() => frappe.timeout(0.5),
-		() => frappe.tests.click_link('Instructor 1'),
-		() => frappe.timeout(0.5),
-		() => {instructor_code = frappe.get_route()[2];},
+		() => frappe.db.get_value('Instructor', {'instructor_name': 'Instructor 1'}, 'name'),
+		(instructor) => {instructor_code = instructor.message.name;},
 
 		// Setting up the creation tool to generate and save Student Group
 		() => frappe.set_route('Form', 'Student Group Creation Tool'),
@@ -57,15 +54,13 @@
 
 		// Goin to the generated group to set up student and instructor list
 		() => {
-			let loop = ['Student Group/test-batch-wise-group-2', 'Student Group/test-course-wise-group-2'];
+			let group_name = ['Student Group/test-batch-wise-group-2', 'Student Group/test-course-wise-group-2'];
 			let tasks = [];
-			loop.forEach(index => {
+			group_name.forEach(index => {
 				tasks.push(
 					() => frappe.timeout(1),
 					() => frappe.set_route("Form", index),
 					() => frappe.timeout(0.5),
-					() => frappe.tests.click_button("Get Students"),
-					() => frappe.timeout(0.5),
 					() => {
 						assert.equal(cur_frm.doc.students.length, 5, 'Successfully fetched list of students');
 					},
diff --git a/erpnext/schools/doctype/student_log/test_student_log.js b/erpnext/schools/doctype/student_log/test_student_log.js
index 6e03976..8f8d152 100644
--- a/erpnext/schools/doctype/student_log/test_student_log.js
+++ b/erpnext/schools/doctype/student_log/test_student_log.js
@@ -6,11 +6,8 @@
 	let done = assert.async();
 	let student_code;
 	frappe.run_serially([
-		() => frappe.set_route("List", "Student"),
-		() => frappe.timeout(0.5),
-		() => frappe.tests.click_link('Fname Mname Lname'),
-		() => frappe.timeout(0.5),
-		() => {student_code = frappe.get_route()[2];},
+		() => frappe.db.get_value('Student', {'student_email_id': 'test2@testmail.com'}, 'name'),
+		(student) => {student_code = student.message.name;},
 		() => {
 			return frappe.tests.make("Student Log", [
 				{student: student_code},