class ChoiceModelTesting(TestCase): def setUp(self): self.choice = ChoiceFactory() def test_vote_me_adds_1_vote(self): """The Choice.vote_me method adds exactly 1 to the votes of the instance.""" assert(self.choice.votes == 0) self.choice.vote_me() self.assertEqual(self.choice.votes, 1) self.choice.delete() def test_vote_me_saves_results(self): """The Choice.vote_me method updates the DB (not only the object instance)""" assert(self.choice.votes == 0) self.choice.vote_me() pk = self.choice.pk del(self.choice) # Obj removed just to be extreme and show the votes value comes from the DB. self.assertEqual(Choice.objects.get(pk=pk).votes, 1) def test_vote_me_work_only_on_DB_saved_instances(self): """The Choice.vote_me method works only on saved objects.""" c = Choice() self.assertRaises(IntegrityError, c.vote_me)