summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/models.py6
-rw-r--r--yaksh/test_models.py11
2 files changed, 11 insertions, 6 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 4dd045a..6a7b800 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1186,12 +1186,6 @@ class QuestionPaper(models.Model):
ans_paper.questions_order = ",".join(question_ids)
ans_paper.save()
ans_paper.questions_unanswered.add(*questions)
- except AnswerPaper.MultipleObjectsReturned:
- ans_paper = AnswerPaper.objects.filter(user=user,
- attempt_number=attempt_num,
- question_paper=self,
- course_id=course_id
- ).order_by('id').last()
return ans_paper
def _is_attempt_allowed(self, user, course_id):
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 7086a1e..9166a3e 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -12,6 +12,7 @@ from datetime import datetime, timedelta
from django.utils import timezone
import pytz
from django.contrib.auth.models import Group
+from django.db import IntegrityError
from django.core.files import File
from django.forms.models import model_to_dict
from textwrap import dedent
@@ -1313,6 +1314,16 @@ class AnswerPaperTestCases(unittest.TestCase):
self.assertEqual(self.user2_answerpaper2.current_question(),
self.question1)
+ def test_duplicate_attempt_answerpaper(self):
+ with self.assertRaises(IntegrityError):
+ new_answerpaper = AnswerPaper.objects.create(
+ user=self.answerpaper.user,
+ question_paper=self.answerpaper.question_paper,
+ attempt_number=self.answerpaper.attempt_number,
+ start_time=self.answerpaper.start_time,
+ end_time=self.answerpaper.end_time
+ )
+
###############################################################################
class CourseTestCases(unittest.TestCase):