From: Tom Walker Date: Sun, 27 Jul 2014 15:20:52 +0000 (+0100) Subject: code cleanup and extra tests X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=1c5928fe5a597a85b0ac4322b7add71802dc6c69;p=django_quiz.git code cleanup and extra tests --- diff --git a/.gitignore b/.gitignore index cf86186..364a537 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,8 @@ /plan.txt /dist* *.egg-info* -build* \ No newline at end of file +build* +/.coverage +/.coveragerc +/coverage_html_report/ +/htmlcov/ diff --git a/essay/views.py b/essay/views.py index 497e342..5d608b0 100644 --- a/essay/views.py +++ b/essay/views.py @@ -1 +1 @@ -#from django.shortcuts import render +# from django.shortcuts import render diff --git a/quiz/admin.py b/quiz/admin.py index 1ba051f..00e4d1e 100644 --- a/quiz/admin.py +++ b/quiz/admin.py @@ -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',) diff --git a/quiz/models.py b/quiz/models.py index 60ed009..b52e33c 100644 --- a/quiz/models.py +++ b/quiz/models.py @@ -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() diff --git a/quiz/tests.py b/quiz/tests.py index 85b7340..55c8d35 100644 --- a/quiz/tests.py +++ b/quiz/tests.py @@ -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, '