diff options
author | ankitjavalkar | 2017-10-18 15:40:58 +0530 |
---|---|---|
committer | ankitjavalkar | 2017-10-25 12:54:53 +0530 |
commit | 90402ae9b0f2d4038099e9ea4e39f832063dd0dd (patch) | |
tree | af3b1d776ed2dc52d35654307589d6d611259fb2 /yaksh | |
parent | 8939dfcefc151ba41c7cb0a2ed32effab9120b0e (diff) | |
download | online_test-90402ae9b0f2d4038099e9ea4e39f832063dd0dd.tar.gz online_test-90402ae9b0f2d4038099e9ea4e39f832063dd0dd.tar.bz2 online_test-90402ae9b0f2d4038099e9ea4e39f832063dd0dd.zip |
- Fix and add test cases
- Fix god-mode/user-mode url pattern
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 11 | ||||
-rw-r--r-- | yaksh/test_models.py | 24 | ||||
-rw-r--r-- | yaksh/urls.py | 2 |
3 files changed, 24 insertions, 13 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 6dc8ce2..de794c4 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1196,11 +1196,12 @@ class AnswerPaper(models.Model): def get_current_question(self, questions): if self.questions_order: - question_id = int(self.questions_order.split(',')[0]) - question = questions.get(id=question_id) - else: - question = questions.first() - return question + available_question_ids = questions.values_list('id', flat=True) + ordered_question_ids = [int(q) for q in self.questions_order.split(',')] + for qid in ordered_question_ids: + if qid in available_question_ids: + return questions.get(id=qid) + return questions.first() def questions_left(self): """Returns the number of questions left.""" diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 3ba7a71..f7662ad 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -513,13 +513,14 @@ class AnswerPaperTestCases(unittest.TestCase): ) self.qtn_paper_with_single_question.save() - self.questions = Question.objects.all()[0:3] + all_questions = Question.objects.all() + self.questions = all_questions[0:3] self.start_time = timezone.now() self.end_time = self.start_time + timedelta(minutes=20) - self.question1 = self.questions[0] - self.question2 = self.questions[1] - self.question3 = self.questions[2] - self.question4 = Question.objects.all()[3] + self.question1 = all_questions[0] + self.question2 = all_questions[1] + self.question3 = all_questions[2] + self.question4 = all_questions[3] # create answerpaper self.answerpaper = AnswerPaper(user=self.user, @@ -578,6 +579,7 @@ class AnswerPaperTestCases(unittest.TestCase): self.answerpaper_single_question.attempt_number = already_attempted + 1 self.answerpaper_single_question.save() self.answerpaper_single_question.questions.add(self.question4) + self.answerpaper_single_question.questions_unanswered.add(self.question4) self.answerpaper_single_question.save() # answers for the Answer Paper self.single_answer = Answer(question=self.question4, @@ -651,18 +653,26 @@ class AnswerPaperTestCases(unittest.TestCase): # Test add_completed_question and next_question # When all questions are answered + # Before questions are answered + self.assertEqual(self.answerpaper_single_question.questions_left(), 1) + current_question = self.answerpaper_single_question.add_completed_question( - self.question1.id + self.question4.id ) + # Then + self.assertEqual( + self.answerpaper_single_question.questions_answered.all()[0], + self.question4 + ) self.assertEqual(self.answerpaper_single_question.questions_left(), 0) self.assertIsNotNone(current_question) self.assertEqual(current_question.summary, "Q4") # When next_question = self.answerpaper_single_question.next_question( - self.question1.id + self.question4.id ) # Then diff --git a/yaksh/urls.py b/yaksh/urls.py index 2e25bee..4c5593a 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -100,7 +100,7 @@ urlpatterns = [ views.regrade, name='regrade'), url(r'^manage/regrade/paper/(?P<course_id>\d+)/(?P<answerpaper_id>\d+)/$', views.regrade, name='regrade'), - url(r'^manage/(?P<mode>[\w\-]+)/(?P<quiz_id>\d+)/$', views.test_quiz), + url(r'^manage/(?P<mode>godmode|usermode)/(?P<quiz_id>\d+)/$', views.test_quiz), url(r'^manage/create_demo_course/$', views.create_demo_course), url(r'^manage/courses/download_course_csv/(?P<course_id>\d+)/$', views.download_course_csv, name="download_course_csv"), |