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.py257
1 files changed, 228 insertions, 29 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 71d6f80..9be8d13 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -1230,6 +1230,7 @@ class TestAddQuiz(TestCase):
kwargs={'quiz_id': self.exercise.id}),
data={
'description': 'updated demo exercise',
+ 'active': True
}
)
@@ -1257,6 +1258,7 @@ class TestAddQuiz(TestCase):
response = self.client.post(reverse('yaksh:add_exercise'),
data={
'description': "Demo Exercise",
+ 'active': True
}
)
quiz_list = Quiz.objects.all().order_by('-id')
@@ -1916,6 +1918,25 @@ class TestAddCourse(TestCase):
timezone='UTC'
)
+ # Create a teacher
+ self.teacher_plaintext_pass = 'demo_teacher'
+ self.teacher = User.objects.create_user(
+ username='demo_teacher',
+ password=self.teacher_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='demo@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.teacher,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='Moderator',
+ timezone='UTC'
+ )
+
# Create Student
self.student_plaintext_pass = 'demo_student'
self.student = User.objects.create_user(
@@ -1928,10 +1949,13 @@ class TestAddCourse(TestCase):
# Add to moderator group
self.mod_group.user_set.add(self.user)
+ self.mod_group.user_set.add(self.teacher)
self.course = Course.objects.create(name="Python Course",
enrollment="Enroll Request", creator=self.user)
+ self.course.teachers.add(self.teacher)
+
self.pre_req_quiz = Quiz.objects.create(
start_date_time=datetime(2014, 2, 1, 5, 8, 15, 0, tzone),
end_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzone),
@@ -2021,6 +2045,33 @@ class TestAddCourse(TestCase):
self.assertRedirects(response, '/exam/manage/courses',
target_status_code=301)
+ def test_add_course_teacher_cannot_be_creator(self):
+ """
+ Teacher editing the course should not become creator
+ """
+ self.client.login(
+ username=self.teacher.username,
+ password=self.teacher_plaintext_pass
+ )
+
+ response = self.client.post(reverse('yaksh:edit_course',
+ kwargs={"course_id": self.course.id}),
+ data={'name': 'Teacher_course',
+ 'active': True,
+ 'enrollment': 'open',
+ 'start_enroll_time': '2016-01-10 09:00:15',
+ 'end_enroll_time': '2016-01-15 09:00:15',
+ }
+ )
+ updated_course = Course.objects.get(id=self.course.id)
+ self.assertEqual(updated_course.name, 'Teacher_course')
+ self.assertEqual(updated_course.enrollment, 'open')
+ self.assertEqual(updated_course.active, True)
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(updated_course.creator, self.user)
+ self.assertRedirects(response, '/exam/manage/courses',
+ target_status_code=301)
+
class TestCourseDetail(TestCase):
def setUp(self):
@@ -2089,6 +2140,11 @@ class TestCourseDetail(TestCase):
self.user1_course = Course.objects.create(name="Python Course",
enrollment="Enroll Request", creator=self.user1)
+ self.learning_module = LearningModule.objects.create(
+ name="test module", description="test description module",
+ html_data="test html description module", creator=self.user1,
+ order=1)
+ self.user1_course.learning_module.add(self.learning_module)
def tearDown(self):
self.client.logout()
@@ -2475,6 +2531,30 @@ class TestCourseDetail(TestCase):
self.assertEqual(response.get('Content-Disposition'),
'attachment; filename="sample_user_upload"')
+ def test_view_course_status(self):
+ """ Test to view course status """
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+
+ # Denies student to view course status
+ response = self.client.get(reverse('yaksh:course_status',
+ kwargs={'course_id': self.user1_course.id}))
+ self.assertEqual(response.status_code, 404)
+
+ # Moderator Login
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ response = self.client.get(reverse('yaksh:course_status',
+ kwargs={'course_id': self.user1_course.id}))
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['state'], "course_status")
+ self.assertEqual(response.context['course'], self.user1_course)
+ self.assertEqual(response.context['modules'][0], self.learning_module)
+
class TestEnrollRequest(TestCase):
def setUp(self):
@@ -3960,8 +4040,27 @@ class TestQuestionPaper(TestCase):
timezone='UTC'
)
+ self.teacher_plaintext_pass = 'demo_teacher'
+ self.teacher = User.objects.create_user(
+ username='demo_teacher',
+ password=self.teacher_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='demo@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.teacher,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='Moderator',
+ timezone='UTC'
+ )
+
# Add to moderator group
self.mod_group.user_set.add(self.user)
+ self.mod_group.user_set.add(self.teacher)
self.course = Course.objects.create(
name="Python Course",
@@ -3976,6 +4075,15 @@ class TestQuestionPaper(TestCase):
creator=self.user
)
+ self.demo_quiz = 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='demo quiz 2', 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(
@@ -3997,8 +4105,6 @@ class TestQuestionPaper(TestCase):
)
self.mcq_based_testcase.save()
- ordered_questions = str(self.question_mcq.id)
-
# Mcc Question
self.question_mcc = Question.objects.create(
summary="Test_mcc_question", description="Test MCC",
@@ -4012,8 +4118,6 @@ class TestQuestionPaper(TestCase):
)
self.mcc_based_testcase.save()
- ordered_questions = ordered_questions + str(self.question_mcc.id)
-
# Integer Question
self.question_int = Question.objects.create(
summary="Test_mcc_question", description="Test MCC",
@@ -4026,8 +4130,6 @@ class TestQuestionPaper(TestCase):
)
self.int_based_testcase.save()
- ordered_questions = ordered_questions + str(self.question_int.id)
-
# String Question
self.question_str = Question.objects.create(
summary="Test_mcc_question", description="Test MCC",
@@ -4054,17 +4156,19 @@ class TestQuestionPaper(TestCase):
)
self.float_based_testcase.save()
- ordered_questions = ordered_questions + str(self.question_float.id)
-
- questions_list = [self.question_mcq, self.question_mcc,
- self.question_int, self.question_str,
- self.question_float]
-
+ self.questions_list = [self.question_mcq, self.question_mcc,
+ self.question_int, self.question_str,
+ self.question_float]
+ questions_order = ",".join([
+ str(self.question_mcq.id), str(self.question_mcc.id),
+ str(self.question_int.id), str(self.question_str.id),
+ str(self.question_float.id)
+ ])
self.question_paper = QuestionPaper.objects.create(
quiz=self.quiz,
- total_marks=5.0, fixed_question_order=ordered_questions
+ total_marks=5.0, fixed_question_order=questions_order
)
- self.question_paper.fixed_questions.add(*questions_list)
+ self.question_paper.fixed_questions.add(*self.questions_list)
self.answerpaper = AnswerPaper.objects.create(
user=self.user, question_paper=self.question_paper,
attempt_number=1,
@@ -4073,12 +4177,14 @@ class TestQuestionPaper(TestCase):
user_ip="127.0.0.1", status="inprogress", passed=False,
percent=0, marks_obtained=0, course=self.course
)
- self.answerpaper.questions.add(*questions_list)
+ self.answerpaper.questions.add(*self.questions_list)
def tearDown(self):
self.client.logout()
self.user.delete()
+ self.teacher.delete()
self.quiz.delete()
+ self.demo_quiz.delete()
self.course.delete()
self.answerpaper.delete()
self.question_mcq.delete()
@@ -4352,6 +4458,58 @@ class TestQuestionPaper(TestCase):
wrong_answer_paper = AnswerPaper.objects.get(id=self.answerpaper.id)
self.assertEqual(wrong_answer_paper.marks_obtained, 0)
+ def test_design_questionpaper(self):
+ """ Test design Question Paper """
+
+ # Should fail if Question paper is not the one which is associated
+ # with a quiz
+ self.client.login(
+ username=self.user.username,
+ password=self.user_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
+ )
+
+ # Should not allow teacher to view question paper
+ response = self.client.get(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.quiz.id,
+ "questionpaper_id": self.question_paper.id}))
+
+ self.assertEqual(response.status_code, 404)
+
+ # Should not allow teacher to view question paper
+ response = self.client.get(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.question_paper.id}))
+
+ self.assertEqual(response.status_code, 404)
+
+ # Should allow course teacher to view question paper
+ # Add teacher to the course
+ self.course.teachers.add(self.teacher)
+ response = self.client.get(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.question_paper.id}))
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed(response, 'yaksh/design_questionpaper.html')
+ self.assertEqual(response.context['fixed_questions'],
+ self.questions_list)
+ self.assertEqual(response.context['qpaper'], self.question_paper)
+
class TestLearningModule(TestCase):
def setUp(self):
@@ -4446,6 +4604,7 @@ class TestLearningModule(TestCase):
check_prerequisite=False, creator=self.user)
self.course.teachers.add(self.teacher)
self.course.learning_module.add(self.learning_module)
+ self.course.learning_module.add(self.learning_module1)
self.expected_url = "/exam/manage/courses/all_learning_module/"
@@ -4710,13 +4869,35 @@ class TestLearningModule(TestCase):
self.assertEqual(response.context["current_unit"].id,
self.learning_unit1.id)
+ # Go to next module with empty module
+ response = self.client.get(
+ reverse('yaksh:next_unit',
+ kwargs={"module_id": self.learning_module1.id,
+ "course_id": self.course.id}),
+ follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context["state"], "module")
+ self.assertEqual(response.context["learning_module"].id,
+ self.learning_module.id)
+
+ # Go to next module from last unit of previous unit
+ response = self.client.get(
+ reverse('yaksh:next_unit',
+ kwargs={"module_id": self.learning_module.id,
+ "course_id": self.course.id,
+ "current_unit_id": self.learning_unit1.id}),
+ follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context["state"], "module")
+ self.assertEqual(response.context["learning_module"].id,
+ self.learning_module1.id)
+
class TestLessons(TestCase):
def setUp(self):
self.client = Client()
self.mod_group = Group.objects.create(name='moderator')
- tzone = pytz.timezone('UTC')
# Create Moderator with profile
self.user_plaintext_pass = 'demo'
self.user = User.objects.create_user(
@@ -4764,25 +4945,30 @@ class TestLessons(TestCase):
name="Python Course",
enrollment="Open Enrollment", creator=self.user)
- self.quiz = 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='demo quiz', pass_criteria=40,
- creator=self.user
- )
-
self.lesson = Lesson.objects.create(
name="test lesson", description="test description",
creator=self.user)
+ self.lesson2 = Lesson.objects.create(
+ name="test lesson2", description="test description2",
+ creator=self.user)
self.learning_unit = LearningUnit.objects.create(
- order=0, type="lesson", lesson=self.lesson)
+ order=0, type="lesson", lesson=self.lesson
+ )
+ self.learning_unit2 = LearningUnit.objects.create(
+ order=0, type="lesson", lesson=self.lesson2
+ )
self.learning_module = LearningModule.objects.create(
order=0, name="test module", description="module",
- check_prerequisite=False, creator=self.user)
+ check_prerequisite=False, creator=self.user
+ )
+ self.learning_module2 = LearningModule.objects.create(
+ order=1, name="test module 2", description="module 2",
+ check_prerequisite=True, creator=self.user
+ )
self.learning_module.learning_unit.add(self.learning_unit.id)
- self.course.learning_module.add(self.learning_module.id)
+ self.learning_module2.learning_unit.add(self.learning_unit2.id)
+ self.course.learning_module.add(*[
+ self.learning_module.id, self.learning_module2.id])
self.course.teachers.add(self.teacher.id)
self.expected_url = "/exam/manage/courses/"
@@ -4791,11 +4977,13 @@ class TestLessons(TestCase):
self.user.delete()
self.student.delete()
self.teacher.delete()
- self.quiz.delete()
self.course.delete()
self.learning_unit.delete()
+ self.learning_unit2.delete()
self.learning_module.delete()
+ self.learning_module2.delete()
self.lesson.delete()
+ self.lesson2.delete()
def test_edit_lesson_denies_non_moderator(self):
""" Student should not be allowed to edit lesson """
@@ -4880,6 +5068,17 @@ class TestLessons(TestCase):
self.assertEqual(response.context["state"], "lesson")
self.assertEqual(response.context["current_unit"], self.learning_unit)
+ # Check unit module prerequisite completion status
+ response = self.client.get(
+ reverse('yaksh:show_lesson',
+ kwargs={"lesson_id": self.lesson2.id,
+ "module_id": self.learning_module2.id,
+ "course_id": self.course.id}))
+ err_msg = "You have not completed the module previous to {0}".format(
+ self.learning_module2.name)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context["msg"], err_msg)
+
def test_show_all_lessons(self):
""" Moderator should be able to see all created lessons"""
self.client.login(