summaryrefslogtreecommitdiff
path: root/yaksh/test_views.py
diff options
context:
space:
mode:
authorprathamesh2017-12-27 17:32:21 +0530
committerprathamesh2017-12-27 17:53:50 +0530
commit51a93b42b1d7b3a94e227796aa8d4f6e97de9929 (patch)
treedb35061da2b9891dd597337be78946eb67c5df3c /yaksh/test_views.py
parentb44db042059e69df4c4a948d6dff73604c7abf83 (diff)
downloadonline_test-51a93b42b1d7b3a94e227796aa8d4f6e97de9929.tar.gz
online_test-51a93b42b1d7b3a94e227796aa8d4f6e97de9929.tar.bz2
online_test-51a93b42b1d7b3a94e227796aa8d4f6e97de9929.zip
Exercise feature in video lessons
Exercise is same as quiz except for following differences: - no time limit - no marks weightage - no instruction page - skip denied for a particular time An attribute 'is_exercise' in Quiz determines whether the quiz is exercise or not. Questions contains 'min_time' attribute. For an exercise a question cannot be skipped for an allotted minimum time, after which either django or JavaScript makes Next button available. Implementation is as such due to complexity of our existing views and templates. Also, after min_time, same question with Next button is available to move on, assuming that solution is present in the video.
Diffstat (limited to 'yaksh/test_views.py')
-rw-r--r--yaksh/test_views.py100
1 files changed, 100 insertions, 0 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index d65fe8e..38564a1 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -1042,11 +1042,19 @@ class TestAddQuiz(TestCase):
creator=self.user
)
+ self.exercise = 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),
+ attempts_allowed=-1, time_between_attempts=0,
+ is_exercise=True, description='demo exercise', creator=self.user
+ )
+
def tearDown(self):
self.client.logout()
self.user.delete()
self.student.delete()
self.quiz.delete()
+ self.exercise.delete()
self.course.delete()
def test_add_quiz_denies_anonymous(self):
@@ -1171,6 +1179,98 @@ class TestAddQuiz(TestCase):
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, '/exam/manage/courses/all_quizzes/')
+ def test_add_exercise_denies_anonymous(self):
+ """
+ If not logged in redirect to login page
+ """
+ response = self.client.get(reverse('yaksh:add_exercise'),
+ follow=True
+ )
+ redirect_destination = '/exam/login/?next=/exam/manage/add_exercise/'
+ self.assertRedirects(response, redirect_destination)
+
+ def test_add_exercise_denies_non_moderator(self):
+ """
+ If not moderator in redirect to login page
+ """
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ course_id = self.course.id
+ response = self.client.get(reverse('yaksh:add_exercise'),
+ follow=True
+ )
+ self.assertEqual(response.status_code, 404)
+
+ def test_add_exercise_get(self):
+ """
+ GET request to add exercise should display add exercise form
+ """
+ self.client.login(
+ username=self.user.username,
+ password=self.user_plaintext_pass
+ )
+ response = self.client.get(reverse('yaksh:add_exercise')
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed(response, 'yaksh/add_exercise.html')
+ self.assertIsNotNone(response.context['form'])
+
+ def test_add_exercise_post_existing_exercise(self):
+ """
+ POST request to edit exercise
+ """
+ self.client.login(
+ username=self.user.username,
+ password=self.user_plaintext_pass
+ )
+ tzone = pytz.timezone('UTC')
+ response = self.client.post(reverse('yaksh:add_exercise',
+ kwargs={'quiz_id': self.exercise.id}),
+ data={
+ 'description': 'updated demo exercise',
+ }
+ )
+
+ updated_exercise = Quiz.objects.get(id=self.exercise.id)
+ self.assertEqual(updated_exercise.active, True)
+ self.assertEqual(updated_exercise.duration, 1000)
+ self.assertEqual(updated_exercise.attempts_allowed, -1)
+ self.assertEqual(updated_exercise.time_between_attempts, 0)
+ self.assertEqual(updated_exercise.description, 'updated demo exercise')
+ self.assertEqual(updated_exercise.pass_criteria, 0)
+ self.assertTrue(updated_exercise.is_exercise)
+ self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, '/exam/manage/courses/all_quizzes/')
+
+ def test_add_exercise_post_new_exercise(self):
+ """
+ POST request to add new exercise
+ """
+ self.client.login(
+ username=self.user.username,
+ password=self.user_plaintext_pass
+ )
+
+ tzone = pytz.timezone('UTC')
+ response = self.client.post(reverse('yaksh:add_exercise'),
+ data={
+ 'description': "Demo Exercise",
+ }
+ )
+ quiz_list = Quiz.objects.all().order_by('-id')
+ new_exercise = quiz_list[0]
+ self.assertEqual(new_exercise.active, True)
+ self.assertEqual(new_exercise.duration, 1000)
+ self.assertEqual(new_exercise.attempts_allowed, -1)
+ self.assertEqual(new_exercise.time_between_attempts, 0)
+ self.assertEqual(new_exercise.description, 'Demo Exercise')
+ self.assertEqual(new_exercise.pass_criteria, 0)
+ self.assertTrue(new_exercise.is_exercise)
+ self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, '/exam/manage/courses/all_quizzes/')
+
def test_show_all_quizzes(self):
self.client.login(
username=self.user.username,