]> git.parisson.com Git - django_quiz.git/commitdiff
cleaned up an 'any()' check, extending tests for quiz/models.progress.update_score()
authortomwalker <tomwalker0472@gmail.com>
Thu, 25 Sep 2014 15:31:11 +0000 (16:31 +0100)
committertomwalker <tomwalker0472@gmail.com>
Thu, 25 Sep 2014 15:31:11 +0000 (16:31 +0100)
quiz/models.py
quiz/tests.py

index 4ab5a56116ec4f8bf3aca891f6a67c7f5bb249b7..13898db1e9fd496e19638282bbd7423abb1a4ada 100644 (file)
@@ -243,11 +243,11 @@ class Progress(models.Model):
         category_test = Category.objects.filter(category=question.category)\
                                         .exists()
 
-        if any([category_test is False,
-                score_to_add is False,
-                possible_to_add is False,
-                str(score_to_add).isdigit() is False,
-                str(possible_to_add).isdigit() is False]):
+        if any([item is False for item in [category_test,
+                                           score_to_add,
+                                           possible_to_add,
+                                           isinstance(score_to_add, int),
+                                           isinstance(possible_to_add, int)]]):
             return "error", "category does not exist or invalid score"
 
         to_find = re.escape(str(question.category)) +\
index cb495b287520e88709b8a2a5d42cebf936b59903..09d68b5fef7aceeb59bdc3a74bd152e1e006bfac 100644 (file)
@@ -165,12 +165,21 @@ class TestProgress(TestCase):
         self.assertIn('cheese', self.p1.list_all_cat_scores)
         self.assertEqual([3, 4, 75], self.p1.list_all_cat_scores['cheese'])
 
+        # pass in string instead of question instance
         with self.assertRaises(AttributeError):
             self.p1.update_score('hamster', 3, 4)
 
-        non_int = self.p1.update_score(question2, '1', 'a')
+        non_int = self.p1.update_score(question2, '1', 2)
         self.assertIn('error', str(non_int))
 
+        # negative possible score
+        self.p1.update_score(question2, 0, -1)
+        self.assertEqual([3, 5, 60], self.p1.list_all_cat_scores['cheese'])
+
+        # negative added score
+        self.p1.update_score(question2, -1, 1)
+        self.assertEqual([4, 6, 67], self.p1.list_all_cat_scores['cheese'])
+
 
 class TestSitting(TestCase):
     def setUp(self):