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
"""
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)
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)
{% 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 %}