]> git.parisson.com Git - django_quiz.git/commitdiff
updated tests to work alongside pull request from Richard Mansfield
authortomwalker <tomwalker0472@gmail.com>
Wed, 6 Aug 2014 14:49:05 +0000 (15:49 +0100)
committertomwalker <tomwalker0472@gmail.com>
Wed, 6 Aug 2014 14:49:05 +0000 (15:49 +0100)
.gitignore
quiz/models.py
quiz/templatetags/quiz_tags.py
quiz/tests.py
quiz/views.py

index 364a537addf7bd96d7bbdeca1bf599201895f813..31d02e57ef646ee834dc8f91ba2e830123585e0d 100644 (file)
@@ -13,3 +13,4 @@ build*
 /.coveragerc
 /coverage_html_report/
 /htmlcov/
+/uploads/
\ No newline at end of file
index 7549e50e186098ab69b349b711d97f6a12a2ceef..d8914ba8ed72bf714c692fe44186996f8b7f7590 100644 (file)
@@ -79,8 +79,9 @@ class Quiz(models.Model):
                                                  "are set?")
 
     max_questions = models.PositiveIntegerField(blank=True, null=True,
-                                                help_text="Number of questions to be "
-                                                          "answered on each attempt")
+                                                help_text="Number of questions"
+                                                          " to be answered on"
+                                                          " each attempt.")
 
     answers_at_end = models.BooleanField(blank=False,
                                          default=False,
@@ -466,7 +467,8 @@ class Sitting(models.Model):
     def get_questions(self):
         question_ids = self._question_ids()
         return sorted(
-            self.quiz.question_set.filter(id__in=question_ids).select_subclasses(),
+            self.quiz.question_set.filter(id__in=question_ids)
+                                  .select_subclasses(),
             key=lambda q: question_ids.index(q.id))
 
     @property
@@ -481,6 +483,7 @@ class Sitting(models.Model):
     def get_max_score(self):
         return len(self._question_ids())
 
+
 class Question(models.Model):
     """
     Base class for all question types.
index d1d60132e9ae63b8c64952d8ab5b2320968b212d..2ce044ced3e1c0f84e2f72d19964ce830ce43737 100644 (file)
@@ -19,6 +19,7 @@ def correct_answer_for_all(context, question):
     return {'previous': {'answers': answers},
             'user_was_incorrect': user_was_incorrect}
 
+
 @register.filter
 def answer_choice_to_string(question, answer):
     return question.answer_choice_to_string(answer)
index 26908e50d1e3d597fb6538388fa3845b1e795fb7..29187dd37c9246b6bb1c52041b92302cf5cf82aa 100644 (file)
@@ -402,6 +402,11 @@ class TestQuestionMarking(TestCase):
         self.question1 = MCQuestion.objects.create(id=1, content='squawk')
         self.question1.quiz.add(self.quiz1)
 
+        self.answer1 = Answer.objects.create(id=123,
+                                             question=self.question1,
+                                             content='bing',
+                                             correct=False)
+
         sitting1 = Sitting.objects.new_sitting(self.student, self.quiz1)
         sitting2 = Sitting.objects.new_sitting(self.student, self.quiz2)
         sitting1.complete = True
@@ -483,10 +488,10 @@ class TestQuestionMarking(TestCase):
         self.assertContains(response, 'button')
         self.assertNotContains(response, 'Correct')
 
-        response = self.client.get('/marking/3/', {'id': 3})
+        response = self.client.post('/marking/3/', {'qid': 3})
         self.assertContains(response, 'Correct')
 
-        response = self.client.get('/marking/3/', {'id': 3})
+        response = self.client.post('/marking/3/', {'qid': 3})
         self.assertNotContains(response, 'Correct')
 
 
index 290da4c7603e12a299cb242d8106bb4381475766..00c44d22795eedc219950cda0f7f6de1fce93313 100644 (file)
@@ -232,9 +232,12 @@ class QuizTake(FormView):
         self.request.session.set_expiry(259200)  # expires after 3 days
         questions = self.quiz.get_questions()
         question_list = [question.id for question in questions]
+
         if self.quiz.random_order is True:
             random.shuffle(question_list)
-        if self.quiz.max_questions and self.quiz.max_questions < len(question_list):
+
+        if all(self.quiz.max_questions,
+               self.quiz.max_questions < len(question_list)):
             question_list = question_list[:self.quiz.max_questions]
 
         # session score for anon users
@@ -245,8 +248,8 @@ class QuizTake(FormView):
 
         # session list of question order and incorrect questions
         self.request.session[self.quiz.anon_q_data()] = dict(
-            incorrect_questions = [],
-            order = question_list,
+            incorrect_questions=[],
+            order=question_list,
         )
 
         return self.request.session[self.quiz.anon_q_list()]
@@ -264,7 +267,9 @@ class QuizTake(FormView):
             anon_session_score(self.request.session, 1, 1)
         else:
             anon_session_score(self.request.session, 0, 1)
-            self.request.session[self.quiz.anon_q_data()]['incorrect_questions'].append(self.question.id)
+            self.request\
+                .session[self.quiz.anon_q_data()]['incorrect_questions']\
+                .append(self.question.id)
 
         self.previous = {}
         if self.quiz.answers_at_end is not True:
@@ -299,10 +304,14 @@ class QuizTake(FormView):
 
         if self.quiz.answers_at_end:
             results['questions'] = sorted(
-                self.quiz.question_set.filter(id__in=q_order).select_subclasses(),
-                key=lambda q: q_order.index(q.id)
-                )
-            results['incorrect_questions'] = self.request.session[self.quiz.anon_q_data()]['incorrect_questions']
+                self.quiz.question_set.filter(id__in=q_order)
+                                      .select_subclasses(),
+                key=lambda q: q_order.index(q.id))
+
+            results['incorrect_questions'] = (
+                self.request
+                    .session[self.quiz.anon_q_data()]['incorrect_questions'])
+
         else:
             results['previous'] = self.previous