]> git.parisson.com Git - django_quiz.git/commitdiff
code cleanup and extra tests
authorTom Walker <tomwalker0472@gmail.com>
Sun, 27 Jul 2014 15:20:52 +0000 (16:20 +0100)
committerTom Walker <tomwalker0472@gmail.com>
Sun, 27 Jul 2014 15:20:52 +0000 (16:20 +0100)
.gitignore
essay/views.py
quiz/admin.py
quiz/models.py
quiz/tests.py
quiz/views.py
true_false/models.py

index cf86186ad3b1a0f82562fef69bd1630bc985e2a8..364a537addf7bd96d7bbdeca1bf599201895f813 100644 (file)
@@ -8,4 +8,8 @@
 /plan.txt
 /dist*
 *.egg-info*
-build*
\ No newline at end of file
+build*
+/.coverage
+/.coveragerc
+/coverage_html_report/
+/htmlcov/
index 497e34224c65e7884dffd9078ff789c0959971d4..5d608b0731b7e766b27533f30a8c1e258d2af515 100644 (file)
@@ -1 +1 @@
-#from django.shortcuts import render
+# from django.shortcuts import render
index 1ba051f3770df80bb7df674ad97e015d73f175d5..00e4d1e7a0e2249f580169e3f5ca03de163012ba 100644 (file)
@@ -7,18 +7,19 @@ from multichoice.models import MCQuestion, Answer
 from true_false.models import TF_Question
 from essay.models import Essay_Question
 
+
 class AnswerInline(admin.TabularInline):
     model = Answer
 
-"""
-below is from
-http://stackoverflow.com/questions/11657682/
-django-admin-interface-using-horizontal-filter-with-
-inline-manytomany-field
-"""
-
 
 class QuizAdminForm(forms.ModelForm):
+    """
+    below is from
+    http://stackoverflow.com/questions/11657682/
+    django-admin-interface-using-horizontal-filter-with-
+    inline-manytomany-field
+    """
+
     class Meta:
         model = Quiz
 
@@ -82,6 +83,7 @@ class TFQuestionAdmin(admin.ModelAdmin):
     search_fields = ('content', 'explanation')
     filter_horizontal = ('quiz',)
 
+
 class EssayQuestionAdmin(admin.ModelAdmin):
     list_display = ('content', 'category', )
     list_filter = ('category',)
index 60ed009c46006e7c105f2aa4c419c3f06b500797..b52e33c5289ea092aec148a625cb550f50b7db0f 100644 (file)
@@ -1,4 +1,6 @@
-import re, json
+import re
+import json
+
 from django.db import models
 from django.core.exceptions import ValidationError
 from django.core.validators import MaxValueValidator
@@ -124,11 +126,6 @@ class Quiz(models.Model):
     def anon_q_list(self):
         return str(self.id) + "_q_list"
 
-"""
-Progress is used to track an individual signed in users score on different
-quiz's and categories
-"""
-
 
 class ProgressManager(models.Manager):
 
@@ -141,8 +138,8 @@ class ProgressManager(models.Manager):
 
 class Progress(models.Model):
     """
-    Currently stores the score for each category, max possible they could
-    have got, and previous exam paper scores.
+    Progress is used to track an individual signed in users score on different
+    quiz's and categories
 
     Data stored in csv using the format:
         category, score, possible, category, score, possible, ...
@@ -194,10 +191,7 @@ class Progress(models.Model):
                 output[cat.category] = [0, 0]
 
         if len(self.score) > len(score_before):
-            """
-            If a new category has been added, save changes. Otherwise nothing
-            will be saved.
-            """
+            # If a new category has been added, save changes.
             self.save()
 
         return output
@@ -260,9 +254,7 @@ class Progress(models.Model):
             self.save()
 
         else:
-            """
-            if not present but existing category, add with the points passed in
-            """
+            #  if not present but existing, add with the points passed in
             self.score += (str(category) + "," +
                            str(score_to_add) + "," +
                            str(possible_to_add) + ",")
@@ -393,7 +385,7 @@ class Sitting(models.Model):
         """
         if len(self.incorrect_questions) > 0:
             self.incorrect_questions += ','
-        self.incorrect_questions +=  str(question.id) + ","
+        self.incorrect_questions += str(question.id) + ","
         if self.complete:
             self.add_to_score(-1)
         self.save()
index 85b7340afd0c72da07ed222d551d33d5ec65c295..55c8d35cc7fff05c2e1d00b2de4d859f52f21242 100644 (file)
@@ -277,11 +277,6 @@ class TestSitting(TestCase):
         self.assertEqual(self.sitting.current_score, 1)
 
 
-'''
-Tests relating to views
-'''
-
-
 class TestNonQuestionViews(TestCase):
     '''
     Starting on views not directly involved with questions.
@@ -782,6 +777,26 @@ class TestQuestionViewsUser(TestCase):
         self.assertContains(response, 'only one sitting is permitted.')
         self.assertTemplateUsed('single_complete.html')
 
+    def test_essay_question(self):
+        quiz3 = Quiz.objects.create(id=3,
+                                    title='test quiz 3',
+                                    description='d3',
+                                    url='tq3',
+                                    category=self.c1,
+                                    answers_at_end=True,
+                                    exam_paper=True)
+        essay = Essay_Question.objects.create(id=4, content='tell all')
+        essay.quiz.add(quiz3)
+        self.client.login(username='jacob', password='top_secret')
+
+        response = self.client.post('/tq3/take/')
+        self.assertContains(response, '<textarea')
+
+        response = self.client.post('/tq3/take/',
+                                    {'answers': 'The meaning of life is...',
+                                     'question_id': 4})
+        self.assertContains(response, 'result')
+
 
 class TestTemplateTags(TestCase):
 
index 9889fb720756f70b5d176bcd29e70e16328004f4..f7e5895bbdf3c2a3cc5d95021e066ce018d5e94a 100644 (file)
@@ -36,9 +36,10 @@ class ViewQuizListByCategory(ListView):
     template_name = 'view_quiz_category.html'
 
     def dispatch(self, request, *args, **kwargs):
-        self.category = get_object_or_404(Category,
-                                          category=
-                                          self.kwargs['category_name'])
+        self.category = get_object_or_404(
+            Category,
+            category=self.kwargs['category_name']
+        )
 
         return super(ViewQuizListByCategory, self).\
             dispatch(request, *args, **kwargs)
index bc51ac83abb9a459be31020f1933e691232ada6f..da79d6ed7145dde17c090bd13d564a7845cd4a1c 100644 (file)
@@ -38,6 +38,3 @@ class TF_Question(Question):
         verbose_name = "True/False Question"
         verbose_name_plural = "True/False Questions"
         ordering = ['category']
-
-    def __unicode__(self):
-        return unicode(self.content)