summaryrefslogtreecommitdiff
path: root/yaksh/test_models.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2018-01-15 12:23:52 +0530
committerGitHub2018-01-15 12:23:52 +0530
commit1445358b4ee548edd16a8d42026b080b7d92a0c4 (patch)
tree99b437d71f841cb1ac9f26266d7e7de04031f340 /yaksh/test_models.py
parent3abbc557c57eaf2f3d08222034f9a720a1e7a1ed (diff)
parentef22478a11d518982f38a6a0d4d84f6f8ba5e492 (diff)
downloadonline_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.tar.gz
online_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.tar.bz2
online_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.zip
Merge pull request #422 from adityacp/show_course_status
Show course status
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r--yaksh/test_models.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 59dea5b..7086a1e 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -2,7 +2,7 @@ import unittest
from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\
QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\
StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload,\
- LearningModule, LearningUnit, Lesson, LessonFile
+ LearningModule, LearningUnit, Lesson, LessonFile, CourseStatus
from yaksh.code_server import(ServerPool,
get_result as get_result_from_code_server
)
@@ -204,6 +204,26 @@ class LearningModuleTestCases(unittest.TestCase):
# Then
self.assertEqual(status, module_status)
+ def test_module_completion_percent(self):
+ # for module without learning units
+ percent = self.learning_module_two.get_module_complete_percent(
+ self.course, self.student
+ )
+ self.assertEqual(percent, 0)
+
+ # for module with learning units
+ lesson = Lesson.objects.get(name='L1')
+ self.completed_unit = LearningUnit.objects.get(lesson=lesson)
+
+ course_status = CourseStatus.objects.create(
+ course=self.course, user=self.student)
+ course_status.completed_units.add(self.completed_unit)
+
+ percent = self.learning_module.get_module_complete_percent(
+ self.course, self.student
+ )
+ self.assertEqual(percent, 50)
+
class LearningUnitTestCases(unittest.TestCase):
def setUp(self):
@@ -1523,6 +1543,26 @@ class CourseTestCases(unittest.TestCase):
"""Test to check enrollment is closed for open course"""
self.assertFalse(self.enroll_request_course.is_active_enrollment())
+ def test_course_complete_percent(self):
+ # for course with no modules
+ self.no_module_course = Course.objects.create(
+ name="test_course", creator=self.creator, enrollment="open")
+ percent = self.course.percent_completed(self.student1)
+ self.assertEqual(percent, 0)
+
+ # for course with module but zero percent completed
+ percent = self.course.percent_completed(self.student1)
+ self.assertEqual(percent, 0)
+
+ # Add completed unit to course status and check percent
+ lesson = Lesson.objects.get(name='L1')
+ self.completed_unit = LearningUnit.objects.get(lesson=lesson)
+
+ course_status = CourseStatus.objects.create(
+ course=self.course, user=self.student1)
+ course_status.completed_units.add(self.completed_unit)
+ updated_percent = self.course.percent_completed(self.student1)
+ self.assertEqual(updated_percent, 25)
###############################################################################