]> git.parisson.com Git - django_quiz.git/commitdiff
tests for all quiz/views that are not related to questions, started on
authorTom Walker <tomwalker0472@gmail.com>
Sat, 21 Jun 2014 21:19:15 +0000 (22:19 +0100)
committerTom Walker <tomwalker0472@gmail.com>
Sat, 21 Jun 2014 21:19:15 +0000 (22:19 +0100)
question related views

quiz/tests.py
quiz/views.py
templates/quiz/progress.html
templates/quiz/signup.html [new file with mode: 0644]

index 25838e92cbf4f6014190122ea98327b651a940f2..c7562da056ba7d2aa42d652fb688a22829f604aa 100644 (file)
@@ -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)
index b853cc981419695e6b151c099da1d1d24dcc4db6..8b977f86f8b1f1c74918b21906e04967d94b0bef 100644 (file)
@@ -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:
index dc52846fd93bf7c28d26e0e9b87c586e381df608..32c6902547325cbe2d2e7ff4be65a5b48158baa6 100644 (file)
@@ -23,8 +23,6 @@
 {% endif %}
 
 
-
-       
 {% if cat_scores %}
 
 <h1>Question Category Scores</h1>
 <script type="text/javascript">
        google.load('visualization', '1', {packages: ['corechart']});
 </script>
-                                               
+
                {% for cat, value in cat_scores.items %}
-                               
+
                        {% ifnotequal cat "empty" %}
-                               
+
                                {% if forloop.first %}
                                        <div class="row">
                                                <ul class="thumbnails">
                                {% endif %}
-                               
+
                                {% ifequal forloop.counter 5 %}
                                                </ul>
                                        </div>
                                        <div class="row">
                                                <ul class="thumbnails">
                                {% endifequal %}
-                               
+
                                {% ifequal forloop.counter 9 %}
                                                </ul>
                                        </div>
                                        <div class="row">
                                                <ul class="thumbnails">
                                {% endifequal %}
-                               
+
                                {% ifequal forloop.counter 13 %}
                                                </ul>
                                        </div>
                                        <div class="row">
                                                <ul class="thumbnails">
                                {% endifequal %}
-                               
+
                                {% ifequal forloop.counter 17 %}
                                                </ul>
                                        </div>
                                        <div class="row">
                                                <ul class="thumbnails">
                                {% endifequal %}
-                                                       
+
                                                        <li class="span3">
                                                                <div class="thumbnail">
                                                                                                                            <script type="text/javascript">
                                                        var data = google.visualization.arrayToDataTable([
                                                          ["",""],
                                                          ['Correct',  correct],
-                                                         ['Incorrect', difference]                                                       
+                                                         ['Incorrect', difference]
                                                        ]);
-                                                       
+
                                                        var options = {
                                                                legend:{position:'none'},
                                                                title:"{{ cat }}",
                                                                fontSize: 16
                                                                };
-                                                     
+
                                                        // Create and draw the visualization.
                                                        new google.visualization.PieChart(document.getElementById('visualization{{ cat }}')).
                                                            draw(data, options);
                                                      }
-                                                     
-                                               
+
+
                                                      google.setOnLoadCallback(drawVisualization);
                                                    </script>
-                                               
+
                                                <div id="visualization{{ cat }}" ></div>
                                                                </div>
                                                        </li>
-                               
+
                        {% endifnotequal %}
-               
-        
+
+
         {% endfor %}
                                                </ul>
                                        </div>
-       
+
 {% endif %}
-    
+
 {% if exams %}
 
 <hr>
 <p class="lead">
        Below are the results of exams that you have sat.
 </p>
-    
+
 <table class="table table-bordered table-striped">
-       
+
        <thead>
                <tr>
                        <th>Quiz Title</th>
                        <th>%</th>
         </tr>
     </thead>
-    
+
     <tbody>
 
            {% for exam in exams %}
-               
+
                <tr>
                        {% user_previous_exam exam %}
                </tr>
-                       
+
            {% endfor %}
-    
+
     </tbody>
-    
+
 </table>
-    
+
 {% endif %}
 
 </div>
 
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/templates/quiz/signup.html b/templates/quiz/signup.html
new file mode 100644 (file)
index 0000000..dbdcaad
--- /dev/null
@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+{% block title %}Progress{% endblock %}
+
+{% block content %}
+<h1>Sign up</h1>
+
+<p>Your current score is {{ anon_score }} out of {{ anon_possible }}</p>
+
+{% endblock %}