summaryrefslogtreecommitdiff
path: root/yaksh/test_views.py
diff options
context:
space:
mode:
authoradityacp2018-01-15 16:30:26 +0530
committeradityacp2018-01-16 15:20:55 +0530
commit8006ffb4a5bd54aa960b24f1508d95844fa579de (patch)
tree5e03c42d8ec18d708b5e17c289310822c5581d51 /yaksh/test_views.py
parent3abbc557c57eaf2f3d08222034f9a720a1e7a1ed (diff)
downloadonline_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.tar.gz
online_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.tar.bz2
online_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.zip
Change in template, test_views, urls and views
- Allow teacher to edit questionpaper for a quiz - Add test to check if teacher is allowed to edit questionpaper for a quiz
Diffstat (limited to 'yaksh/test_views.py')
-rw-r--r--yaksh/test_views.py92
1 files changed, 77 insertions, 15 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 71d6f80..6444465 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -3960,13 +3960,35 @@ 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",
enrollment="Open Enrollment", creator=self.user)
+ # Add teacher to the course
+ self.course.teachers.add(self.teacher)
+
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),
@@ -3976,6 +3998,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 +4028,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 +4041,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 +4053,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 +4079,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 +4100,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 +4381,39 @@ 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)
+
+ # Should allow course teacher to edit question paper
+ self.client.login(
+ username=self.teacher.username,
+ password=self.teacher_plaintext_pass
+ )
+
+ 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):