summaryrefslogtreecommitdiff
path: root/yaksh/test_views.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/test_views.py')
-rw-r--r--yaksh/test_views.py225
1 files changed, 225 insertions, 0 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 46d3929..06a4fa3 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -1743,6 +1743,10 @@ class TestCourses(TestCase):
self.lesson = Lesson.objects.create(
name="demo lesson", description="test description",
creator=self.user1)
+ lesson_file = SimpleUploadedFile("file1.mp4", b"Test")
+ django_file = File(lesson_file)
+ self.lesson.video_file.save(lesson_file.name, django_file,
+ save=True)
self.lesson_unit = LearningUnit.objects.create(
order=1, type="lesson", lesson=self.lesson)
@@ -2002,6 +2006,63 @@ class TestCourses(TestCase):
os.remove(file_path)
shutil.rmtree(os.path.dirname(file_path))
+ def test_download_course_offline(self):
+ """ Test to download course with lessons offline"""
+
+ # Student fails to download course if not enrolled in that course
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ response = self.client.get(
+ reverse('yaksh:download_course',
+ kwargs={"course_id": self.user1_course.id}),
+ follow=True
+ )
+ self.assertEqual(response.status_code, 404)
+
+ # Teacher/Moderator should be able to download course
+ self.client.login(
+ username=self.teacher.username,
+ password=self.teacher_plaintext_pass
+ )
+
+ # Should not allow to download if the course doesn't have lessons
+ self.user1_course.learning_module.add(self.learning_module)
+ response = self.client.get(
+ reverse('yaksh:download_course',
+ kwargs={"course_id": self.user1_course.id}),
+ follow=True
+ )
+ self.user1_course.learning_module.remove(self.learning_module)
+ self.assertEqual(response.status_code, 404)
+ lesson_file = SimpleUploadedFile("file1.txt", b"Test")
+ django_file = File(lesson_file)
+ lesson_file_obj = LessonFile()
+ lesson_file_obj.lesson = self.lesson
+ lesson_file_obj.file.save(lesson_file.name, django_file, save=True)
+ self.user1_course.learning_module.add(self.learning_module1)
+ response = self.client.get(
+ reverse('yaksh:download_course',
+ kwargs={"course_id": self.user1_course.id}),
+ follow=True
+ )
+ course_name = self.user1_course.name.replace(" ", "_")
+ self.assertEqual(response.status_code, 200)
+ zip_file = string_io(response.content)
+ zipped_file = zipfile.ZipFile(zip_file, 'r')
+ self.assertIsNone(zipped_file.testzip())
+ files_in_zip = zipped_file.namelist()
+ module_path = os.path.join(course_name, "demo_module",
+ "demo_module.html")
+ lesson_path = os.path.join(course_name, "demo_module", "demo_lesson",
+ "demo_lesson.html")
+ self.assertIn(module_path, files_in_zip)
+ self.assertIn(lesson_path, files_in_zip)
+ zip_file.close()
+ zipped_file.close()
+ self.user1_course.learning_module.remove(self.learning_module1)
+
class TestAddCourse(TestCase):
def setUp(self):
@@ -4456,6 +4517,24 @@ class TestQuestionPaper(TestCase):
timezone='UTC'
)
+ self.student_plaintext_pass = 'demo'
+ self.student = User.objects.create_user(
+ username='demo_student',
+ password=self.student_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='demo@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.student,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='Student',
+ timezone='UTC'
+ )
+
self.user2_plaintext_pass = 'demo2'
self.user2 = User.objects.create_user(
username='demo_user2',
@@ -4518,6 +4597,15 @@ class TestQuestionPaper(TestCase):
creator=self.user
)
+ self.quiz_without_qp = Quiz.objects.create(
+ start_date_time=datetime(2014, 10, 9, 10, 8, 15, 0, tzone),
+ end_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzone),
+ duration=30, active=True, instructions="Demo Instructions",
+ attempts_allowed=-1, time_between_attempts=0,
+ description='quiz without question paper', pass_criteria=40,
+ creator=self.user
+ )
+
self.learning_unit = LearningUnit.objects.create(
order=1, type="quiz", quiz=self.quiz)
self.learning_module = LearningModule.objects.create(
@@ -4600,6 +4688,13 @@ class TestQuestionPaper(TestCase):
)
self.float_based_testcase.save()
+ # Question with tag
+ self.tagged_que = Question.objects.create(
+ summary="Test_tag_question", description="Test Tag",
+ points=1.0, language="python", type="float", user=self.teacher
+ )
+ self.tagged_que.tags.add("test_tag")
+
self.questions_list = [self.question_mcq, self.question_mcc,
self.question_int, self.question_str,
self.question_float]
@@ -4612,6 +4707,13 @@ class TestQuestionPaper(TestCase):
quiz=self.quiz,
total_marks=5.0, fixed_question_order=questions_order
)
+ self.fixed_que = Question.objects.create(
+ summary="Test_fixed_question", description="Test Tag",
+ points=1.0, language="python", type="float", user=self.teacher
+ )
+ self.fixed_question_paper = QuestionPaper.objects.create(
+ quiz=self.demo_quiz, total_marks=5.0
+ )
self.question_paper.fixed_questions.add(*self.questions_list)
self.answerpaper = AnswerPaper.objects.create(
user=self.user, question_paper=self.question_paper,
@@ -4966,6 +5068,26 @@ class TestQuestionPaper(TestCase):
"questionpaper_id": self.question_paper.id}))
self.assertEqual(response.status_code, 404)
+ # Design question paper for a quiz
+ response = self.client.post(
+ reverse('yaksh:design_questionpaper',
+ kwargs={"quiz_id": self.quiz_without_qp.id}),
+ data={"marks": "1.0", "question_type": "code"})
+ self.assertEqual(response.status_code, 200)
+ self.assertIsNotNone(response.context['questions'])
+
+ # Student should not be able to design question paper
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+
+ response = self.client.get(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.demo_quiz.id,
+ "questionpaper_id": self.question_paper.id}))
+ self.assertEqual(response.status_code, 404)
+
self.client.login(
username=self.teacher.username,
password=self.teacher_plaintext_pass
@@ -5002,6 +5124,18 @@ class TestQuestionPaper(TestCase):
self.questions_list)
self.assertEqual(response.context['qpaper'], self.question_paper)
+ # Get questions using tags for question paper
+ search_tag = [tag for tag in self.tagged_que.tags.all()]
+ response = self.client.post(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.question_paper.id}),
+ data={"question_tags": search_tag})
+
+ self.assertEqual(response.context["questions"][0], self.tagged_que)
+
+ # Add random questions in question paper
response = self.client.post(
reverse('yaksh:designquestionpaper',
kwargs={"quiz_id": self.quiz.id,
@@ -5012,6 +5146,7 @@ class TestQuestionPaper(TestCase):
'marks': ['1.0'], 'question_type': ['code'],
'add-random': ['']}
)
+
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'yaksh/design_questionpaper.html')
random_set = response.context['random_sets'][0]
@@ -5019,6 +5154,91 @@ class TestQuestionPaper(TestCase):
self.assertIn(self.random_que1, added_random_ques)
self.assertIn(self.random_que2, added_random_ques)
+ # Check if questions already exists
+ self.client.login(
+ username=self.user.username,
+ password=self.user_plaintext_pass
+ )
+ response = self.client.post(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.question_paper.id}),
+ data={'marks': ['1.0'], 'question_type': ['code'],
+ 'add-fixed': ['']}
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context["questions"].count(), 0)
+
+ # Add fixed question in question paper
+ response = self.client.post(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.demo_quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.fixed_question_paper.id}),
+ data={'checked_ques': [self.fixed_que.id],
+ 'add-fixed': ''}
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['qpaper'], self.fixed_question_paper)
+ self.assertEqual(response.context['fixed_questions'][0],
+ self.fixed_que)
+
+ # Add one more fixed question in question paper
+ response = self.client.post(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.demo_quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.fixed_question_paper.id}),
+ data={'checked_ques': [self.question_float.id],
+ 'add-fixed': ''}
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['qpaper'], self.fixed_question_paper)
+ self.assertEqual(response.context['fixed_questions'],
+ [self.fixed_que, self.question_float])
+
+ # Remove fixed question from question paper
+ response = self.client.post(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.demo_quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.fixed_question_paper.id}),
+ data={'added-questions': [self.fixed_que.id],
+ 'remove-fixed': ''}
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['qpaper'], self.fixed_question_paper)
+ self.assertEqual(response.context['fixed_questions'],
+ [self.question_float])
+
+ # Remove one more fixed question from question paper
+ response = self.client.post(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.demo_quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.fixed_question_paper.id}),
+ data={'added-questions': [self.question_float.id],
+ 'remove-fixed': ''}
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['qpaper'], self.fixed_question_paper)
+ self.assertEqual(response.context['fixed_questions'], [])
+
+ # Remove random questions from question paper
+ random_que_set = self.question_paper.random_questions.all().first()
+ response = self.client.post(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.question_paper.id}),
+ data={'random_sets': random_que_set.id,
+ 'remove-random': ''}
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['qpaper'], self.question_paper)
+ self.assertEqual(len(response.context['random_sets']), 0)
+
class TestLearningModule(TestCase):
def setUp(self):
@@ -5515,6 +5735,7 @@ class TestLessons(TestCase):
password=self.teacher_plaintext_pass
)
dummy_file = SimpleUploadedFile("test.txt", b"test")
+ video_file = SimpleUploadedFile("test.mp4", b"test")
response = self.client.post(
reverse('yaksh:edit_lesson',
kwargs={"lesson_id": self.lesson.id,
@@ -5522,6 +5743,7 @@ class TestLessons(TestCase):
data={"name": "updated lesson",
"description": "updated description",
"Lesson_files": dummy_file,
+ "video_file": video_file,
"Save": "Save"}
)
@@ -5533,6 +5755,8 @@ class TestLessons(TestCase):
self.assertEqual(updated_lesson.creator, self.user)
self.assertEqual(updated_lesson.html_data,
Markdown().convert("updated description"))
+ self.assertEqual(os.path.basename(updated_lesson.video_file.name),
+ "test.mp4")
lesson_files = LessonFile.objects.filter(
lesson=self.lesson).first()
self.assertIn("test.txt", lesson_files.file.name)
@@ -5551,6 +5775,7 @@ class TestLessons(TestCase):
lesson=self.lesson).exists()
self.assertFalse(lesson_file_exists)
self.assertFalse(os.path.exists(lesson_file_path))
+ updated_lesson.remove_file()
def test_show_lesson(self):
""" Student should be able to view lessons """