summaryrefslogtreecommitdiff
path: root/yaksh/test_models.py
diff options
context:
space:
mode:
authoradityacp2018-01-12 17:46:23 +0530
committeradityacp2018-01-12 18:20:27 +0530
commitca9cd739cd528b1fe883f25be1d76b8bbdb7bc25 (patch)
treeebc2f0938ffae1903aa77b99703849927bebc157 /yaksh/test_models.py
parentae15c16a7a94e86d6debf3cc385e24fecac889e2 (diff)
downloadonline_test-ca9cd739cd528b1fe883f25be1d76b8bbdb7bc25.tar.gz
online_test-ca9cd739cd528b1fe883f25be1d76b8bbdb7bc25.tar.bz2
online_test-ca9cd739cd528b1fe883f25be1d76b8bbdb7bc25.zip
Add views and models tests for 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)
###############################################################################