diff options
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r-- | yaksh/test_models.py | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 1f38d03..4d91b27 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1,5 +1,6 @@ import unittest from django.contrib.auth.models import Group +from django.core.files.uploadedfile import SimpleUploadedFile from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload,\ @@ -145,14 +146,52 @@ class LearningModuleTestCases(unittest.TestCase): self.learning_module_two = LearningModule.objects.get(name='LM2') self.creator = User.objects.get(username='creator') self.student = User.objects.get(username='course_user') - self.learning_unit_one = LearningUnit.objects.get(order=1) - self.learning_unit_two = LearningUnit.objects.get(order=2) + self.learning_unit_one = LearningUnit.objects.get(id=1) + self.learning_unit_two = LearningUnit.objects.get(id=2) self.quiz = Quiz.objects.get(description='demo quiz 1') self.lesson = Lesson.objects.get(name='L1') self.course = Course.objects.get(name='Python Course') self.course_status = CourseStatus.objects.get( course=self.course, user=self.student) + self.prereq_course = Course.objects.create( + name="Prerequisite Course", + enrollment="Enroll Request", creator=self.creator + ) + + self.prereq_learning_module = LearningModule.objects.create( + name='LM3', description='module one', creator=self.creator + ) + self.test_learning_module = LearningModule.objects.create( + name='LM4', description='module two', + creator=self.creator, order=1 + ) + course_status = CourseStatus.objects.create( + course=self.prereq_course, user=self.student + ) + lesson = Lesson.objects.create( + name='P1', description='Video Lesson', + creator=self.creator + ) + learning_unit_lesson = LearningUnit.objects.create( + order=2, + lesson=lesson, + type='lesson' + ) + learning_unit_quiz = LearningUnit.objects.create( + order=1, + quiz=self.quiz, + type='quiz' + ) + self.prereq_learning_module.learning_unit.add(learning_unit_quiz) + self.prereq_learning_module.learning_unit.add(learning_unit_lesson) + self.prereq_learning_module.save() + self.prereq_course.learning_module.add(self.prereq_learning_module) + self.prereq_course.learning_module.add(self.test_learning_module) + self.prereq_course.students.add(self.student) + self.prereq_course.save() + + def tearDown(self): # Remove unit from course status completed units self.course_status.completed_units.remove(self.learning_unit_one) @@ -164,6 +203,13 @@ class LearningModuleTestCases(unittest.TestCase): self.assertTrue(self.learning_module.check_prerequisite) self.assertEqual(self.learning_module.order, 0) + def test_prerequisite_passes(self): + self.assertFalse( + self.test_learning_module.is_prerequisite_passed( + self.student, self.prereq_course + ) + ) + def test_get_quiz_units(self): # Given quizzes = [self.quiz] @@ -2130,3 +2176,22 @@ class CourseStatusTestCases(unittest.TestCase): # Test get course grade after completion self.assertEqual(self.course.get_grade(self.answerpaper1.user), 'B') + + +class FileUploadTestCases(unittest.TestCase): + def setUp(self): + self.question = Question.objects.get(summary='Q1') + self.filename = "uploadtest.txt" + self.uploaded_file = SimpleUploadedFile(self.filename, b'Test File') + self.file_upload = FileUpload.objects.create( + file=self.uploaded_file, + question=self.question + ) + + def test_get_file_name(self): + self.assertEqual(self.file_upload.get_filename(), self.filename) + + def tearDown(self): + if os.path.isfile(self.file_upload.file.path): + os.remove(self.file_upload.file.path) + self.file_upload.delete() |