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)) +\
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):