From 5273c74a166e27d2648082d763fd9b8edb343192 Mon Sep 17 00:00:00 2001 From: Tom Walker Date: Sat, 21 Jun 2014 22:19:15 +0100 Subject: [PATCH] tests for all quiz/views that are not related to questions, started on question related views --- quiz/tests.py | 80 ++++++++++++++++++++++++++++++++++++ quiz/views.py | 7 ++-- templates/quiz/progress.html | 58 +++++++++++++------------- templates/quiz/signup.html | 9 ++++ 4 files changed, 121 insertions(+), 33 deletions(-) create mode 100644 templates/quiz/signup.html diff --git a/quiz/tests.py b/quiz/tests.py index 25838e9..c7562da 100644 --- a/quiz/tests.py +++ b/quiz/tests.py @@ -2,6 +2,7 @@ from django.contrib.auth.models import User from django.test import TestCase +from django.test.client import Client from quiz.models import Category, Quiz, Progress, Sitting, Question from multichoice.models import MCQuestion @@ -219,6 +220,9 @@ Tests relating to views """ class TestNonQuestionViews(TestCase): + """ + Starting on questions not directly involved with questions. + """ def setUp(self): Category.objects.new_category(category = "elderberries") c1 = Category.objects.get(id = 1) @@ -253,3 +257,79 @@ class TestNonQuestionViews(TestCase): self.assertContains(response, 'test quiz 1') self.assertNotContains(response, 'test quiz 2') + + def test_progress_anon(self): + response = self.client.get('/q/progress/') + self.assertContains(response, 'Sign up') + + session = self.client.session + session["session_score"] = 1 + session["session_score_possible"] = 2 + session.save() + + response = self.client.get('/q/progress/') + self.assertContains(response, '1 out of 2') + + def test_progress_user(self): + self.user = User.objects.create_user(username = "jacob", + email = "jacob@jacob.com", + password = "top_secret") + + c = Client() + c.login(username='jacob', password='top_secret') + p1 = Progress.objects.new_progress(self.user) + p1.update_score("elderberries", 1, 2) + + response = c.get('/q/progress/') + + self.assertContains(response, "elderberries") + + +class TestQuestionViewsAnon(TestCase): + + def setUp(self): + Category.objects.new_category(category = "elderberries") + c1 = Category.objects.get(id = 1) + + quiz1 = Quiz.objects.create(id = 1, + title = "test quiz 1", + description = "d1", + url = "tq1", + category = c1) + + self.user = User.objects.create_user(username = "jacob", + email = "jacob@jacob.com", + password = "top_secret") + + question1 = MCQuestion.objects.create(id = 1, + content = "squawk",) + question1.quiz.add(quiz1) + + question2 = MCQuestion.objects.create(id = 2, + content = "squeek",) + question2.quiz.add(quiz1) + + +class TestQuestionViewsAnon(TestCase): + + def setUp(self): + Category.objects.new_category(category = "elderberries") + c1 = Category.objects.get(id = 1) + + quiz1 = Quiz.objects.create(id = 1, + title = "test quiz 1", + description = "d1", + url = "tq1", + category = c1) + + self.user = User.objects.create_user(username = "jacob", + email = "jacob@jacob.com", + password = "top_secret") + + question1 = MCQuestion.objects.create(id = 1, + content = "squawk",) + question1.quiz.add(quiz1) + + question2 = MCQuestion.objects.create(id = 2, + content = "squeek",) + question2.quiz.add(quiz1) diff --git a/quiz/views.py b/quiz/views.py index b853cc9..8b977f8 100644 --- a/quiz/views.py +++ b/quiz/views.py @@ -121,9 +121,10 @@ def load_anon_next_question(request, quiz): show_advert = False """ - This is a counter that allows you to add something into the template every - X amount of pages. In my original site, I used this to show a full page - advert every 10 pages. + This is a counter that allows you to add something into the + template every X amount of pages. + In my original site, I used this to show a full page advert + every 10 pages. """ # try: diff --git a/templates/quiz/progress.html b/templates/quiz/progress.html index dc52846..32c6902 100644 --- a/templates/quiz/progress.html +++ b/templates/quiz/progress.html @@ -23,8 +23,6 @@ {% endif %} - - {% if cat_scores %}

Question Category Scores

@@ -36,44 +34,44 @@ - + {% for cat, value in cat_scores.items %} - + {% ifnotequal cat "empty" %} - + {% if forloop.first %}
- + {% endif %} - + {% if exams %}
@@ -123,9 +121,9 @@

Below are the results of exams that you have sat.

- + - + @@ -134,23 +132,23 @@ - + {% for exam in exams %} - + {% user_previous_exam exam %} - + {% endfor %} - + - +
Quiz Title%
- + {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/quiz/signup.html b/templates/quiz/signup.html new file mode 100644 index 0000000..dbdcaad --- /dev/null +++ b/templates/quiz/signup.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} +{% block title %}Progress{% endblock %} + +{% block content %} +

Sign up

+ +

Your current score is {{ anon_score }} out of {{ anon_possible }}

+ +{% endblock %} -- 2.39.5