Ejemplo n.º 1
0
    def test_new_quiz_result_created_on_save(self):
        quiz_select_form = QuizSelectForm(data={ 'quiz': self.quiz.id, 'name': 'J Doe'})
        self.assertEqual(0, QuizResult.objects.count())
        quiz_select_form.is_valid()
        quiz_select_form.save()

        quiz_results = QuizResult.objects.filter(name='J Doe', quiz=self.quiz)
        self.assertEqual(1, len(quiz_results))
Ejemplo n.º 2
0
def home(request):
    if request.method == 'POST':
        form = QuizSelectForm(data=request.POST)

        if form.is_valid():
            quiz_result_id = form.save()
            return redirect(reverse('quiz', args=(quiz_result_id,)))
    else:
        form = QuizSelectForm()

    context = {
        'form': form,
        'has_quizzes': Quiz.objects.count() > 0
    }

    return render_to_response('quiz/home.html',
                               context,
                               context_instance=RequestContext(request))