]> git.parisson.com Git - django_quiz.git/commitdiff
slight improvement of readability using any() in quiz/models, and working on views...
authorTom Walker <tomwalker0472@gmail.com>
Mon, 23 Jun 2014 21:42:28 +0000 (22:42 +0100)
committerTom Walker <tomwalker0472@gmail.com>
Mon, 23 Jun 2014 21:42:28 +0000 (22:42 +0100)
quiz/models.py
quiz/tests.py

index 32ba608efd2897a56d8ff188d15398ce78a98a02..d1ce6ac365e794ec0927735bef65e693692daa6e 100644 (file)
@@ -244,9 +244,9 @@ class Progress(models.Model):
         category_test = Category.objects.filter(category = category_queried) \
                                         .exists()
 
-        if category_test == False or score_to_add == False or \
-           possible_to_add == False or str(score_to_add).isdigit() == False or \
-           str(possible_to_add).isdigit() == False:
+        if any([category_test == False, score_to_add == False,
+                possible_to_add == False, str(score_to_add).isdigit() == False,
+                str(possible_to_add).isdigit() == False]):
             return "error",  "category does not exist or invalid score"
 
         to_find = re.escape(str(category_queried)) + r",(\d+),(\d+),"
index 3df4e08981c2e4235b16728ec41016633f2e9809..afebe9321b5d8d31500767a0d6fe8260e50165b6 100644 (file)
@@ -1,9 +1,12 @@
 # -*- coding: iso-8859-15 -*-
 
 from django.contrib.auth.models import User, AnonymousUser
+from django.core.urlresolvers import resolve
+from django.http import HttpRequest
 from django.test import TestCase
 from django.test.client import Client, RequestFactory
 
+
 from quiz.models import Category, Quiz, Progress, Sitting, Question
 from quiz.views import quiz_take
 from multichoice.models import MCQuestion
@@ -312,15 +315,39 @@ class TestQuestionViewsAnon(TestCase):
 
         self.factory = RequestFactory()
 
-    def test_quiz_take_anon(self):
-        request = self.client.get('/q/tq1/')
-        request.user = AnonymousUser()
-        request.session = self.client.session
-        request.session['set_expiry'] = 0
+    def test_quiz_take_anon_view_only(self):
+        found = resolve('/q/tq1/')
 
-        print request
+        self.assertEqual(found.func, quiz_take)
+        self.assertEqual(found.kwargs, {'quiz_name': 'tq1'})
+        self.assertEqual(found.url_name, 'quiz_start_page')
 
-        self.assertContains(response, 'Sign up')
+        response = self.client.get('/q/tq1/')
+
+        self.assertContains(response, 'squawk', status_code = 200)
+        self.assertEqual(self.client.session.get_expiry_age(), 259200)
+        self.assertEqual(self.client.session['1_q_list'], [1, 2])
+        self.assertEqual(self.client.session['1_score'], 0)
+        self.assertEqual(self.client.session['page_count'], 0)
+        self.assertEqual(response.context['quiz'].id, 1)
+        self.assertEqual(response.context['question'].content, "squawk")
+        self.assertEqual(response.context['question_type'], "MCQuestion")
+        self.assertEqual(response.context['previous'], {})
+        self.assertEqual(response.context['show_advert'], False)
+        self.assertTemplateUsed('question.html')
+
+        session = self.client.session
+        session.set_expiry(1) # session is set when user first
+        session.save()        # accesses a quiz
+
+        response2 = self.client.get('/q/tq1/')
+        self.assertEqual(self.client.session.get_expiry_age(), 1)
+        self.assertEqual(self.client.session['1_q_list'], [1, 2])
+        self.assertEqual(self.client.session['1_score'], 0)
+        self.assertEqual(self.client.session['page_count'], 0)
+
+    def test_quiz_take_anon_submit(self):
+        response = self.client.get('/q/tq1/')
 
 
 class TestQuestionViewsUser(TestCase):