summaryrefslogtreecommitdiff
path: root/yaksh/test_views.py
diff options
context:
space:
mode:
authorankitjavalkar2018-03-06 20:47:42 +0530
committerankitjavalkar2018-03-07 12:37:44 +0530
commit88fbad3f08dfcf8d139f8bc572860469c64e3104 (patch)
treecf24a8327c677241216cc36be8a268e28a746cc0 /yaksh/test_views.py
parent73d6da4bca9b604a3fe68b8ce843791c948ae285 (diff)
downloadonline_test-88fbad3f08dfcf8d139f8bc572860469c64e3104.tar.gz
online_test-88fbad3f08dfcf8d139f8bc572860469c64e3104.tar.bz2
online_test-88fbad3f08dfcf8d139f8bc572860469c64e3104.zip
Multiple fixes:
- Add views test cases in test_views.py - Add minutes unit to preview_questionpaper template - Add error handling in views when random user accesses questionpaper
Diffstat (limited to 'yaksh/test_views.py')
-rw-r--r--yaksh/test_views.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 3b27338..10cef81 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -4040,6 +4040,24 @@ class TestQuestionPaper(TestCase):
timezone='UTC'
)
+ self.user2_plaintext_pass = 'demo2'
+ self.user2 = User.objects.create_user(
+ username='demo_user2',
+ password=self.user_plaintext_pass,
+ first_name='first_name2',
+ last_name='last_name2',
+ email='demo2@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.user2,
+ roll_number=11,
+ institute='IIT',
+ department='Chemical',
+ position='Student',
+ timezone='UTC'
+ )
+
self.teacher_plaintext_pass = 'demo_teacher'
self.teacher = User.objects.create_user(
username='demo_teacher',
@@ -4194,6 +4212,54 @@ class TestQuestionPaper(TestCase):
self.learning_module.delete()
self.learning_unit.delete()
+ def test_preview_questionpaper_correct(self):
+ self.client.login(
+ username=self.user.username,
+ password=self.user_plaintext_pass
+ )
+
+ # Should successfully preview question paper
+ response = self.client.get(
+ reverse('yaksh:preview_questionpaper',
+ kwargs={"questionpaper_id": self.question_paper.id}
+ )
+ )
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed(response, 'yaksh/preview_questionpaper.html')
+ self.assertEqual(
+ response.context['questions'],
+ self.questions_list
+ )
+ self.assertEqual(response.context['paper'], self.question_paper)
+
+ def test_preview_questionpaper_without_moderator(self):
+ self.client.login(
+ username=self.user2.username,
+ password=self.user_plaintext_pass
+ )
+
+ # Should raise an HTTP 404 response
+ response = self.client.get(
+ reverse('yaksh:preview_questionpaper',
+ kwargs={"questionpaper_id": self.question_paper.id}
+ )
+ )
+ self.assertEqual(response.status_code, 404)
+
+ def test_preview_qustionpaper_without_quiz_owner(self):
+ self.client.login(
+ username=self.teacher.username,
+ password=self.teacher_plaintext_pass
+ )
+
+ # Should raise an HTTP 404 response
+ response = self.client.get(
+ reverse('yaksh:preview_questionpaper',
+ kwargs={"questionpaper_id": self.question_paper.id}
+ )
+ )
+ self.assertEqual(response.status_code, 404)
+
def test_mcq_attempt_right_after_wrong(self):
""" Case:- Check if answerpaper and answer marks are updated after
attempting same mcq question with wrong answer and then right