From 2a462e6846a85ee4fc3249f61f3a716ec34e8b45 Mon Sep 17 00:00:00 2001 From: Eleonore9 Date: Sat, 6 Jul 2013 17:08:03 +0200 Subject: [PATCH] code style changes --- example2/polls/tests/test_models.py | 143 ++++++++++++++++------------ 1 file changed, 80 insertions(+), 63 deletions(-) diff --git a/example2/polls/tests/test_models.py b/example2/polls/tests/test_models.py index badd16d..e0487d6 100644 --- a/example2/polls/tests/test_models.py +++ b/example2/polls/tests/test_models.py @@ -4,78 +4,95 @@ from django.utils import timezone from polls.models import Poll from polls.models import Choice - + class PollTestCase(TestCase): - - def setUp(self): - self.poll = Poll.objects.create(question = "mine", pub_date = timezone.now()) - self.poll.save() - - def test_creation(self): - p = Poll.objects.create(question = "lo lo", pub_date = timezone.now()) - p.save() - self.assertEqual(Poll.objects.count(), 2) # Cause setup created one already - - def test_update(self): - # TODO Add code - # change self.poll.question to "yours" - self.poll.question = "yours" - # do self.poll.save() - self.poll.save() - # TODO Add assertions - # make p = Poll.objects.get() - p = Poll.objects.get() - # add self.assertEqual(p.question, "yours") - self.assertEqual(p.question, "yours") - - def test_delete(self): - # TODO Add code - # get from the db using poll question - p = Poll.objects.get() - # delete poll from the db - p.delete() + def setUp(self): + self.poll = Poll.objects.create( + question="mine", + pub_date=timezone.now() + ) + self.poll.save() - # TODO Add assertions - # check if d is empty - self.assertEqual(Poll.objects.count(), 0) + def test_creation(self): + p = Poll.objects.create( + question="lo lo", + pub_date=timezone.now() + ) + p.save() + self.assertEqual(Poll.objects.count(), 2) + # Cause setup created one already + + def test_update(self): + # TODO Add code + # change self.poll.question to "yours" + self.poll.question = "yours" + # do self.poll.save() + self.poll.save() + + # TODO Add assertions + # make p = Poll.objects.get() + p = Poll.objects.get() + # add self.assertEqual(p.question, "yours") + self.assertEqual(p.question, "yours") + + def test_delete(self): + # TODO Add code + # get from the db using poll question + p = Poll.objects.get() + # delete poll from the db + p.delete() + + # TODO Add assertions + # check if d is empty + self.assertEqual(Poll.objects.count(), 0) class ChoiceTestCase(TestCase): - def setUp(self): - self.poll = Poll.objects.create(question = "mine", pub_date = timezone.now()) - self.poll.save() - self.choice = Choice.objects.create(poll=self.poll, choice_text = "first text", votes = 2) - self.choice.save() - - def test_choice_creation(self): - # code - # add another choice - p = Choice.objects.create(poll=self.poll, choice_text = "second text", votes = 5) - p.save() + def setUp(self): + self.poll = Poll.objects.create( + question="mine", + pub_date=timezone.now() + ) + self.poll.save() + self.choice = Choice.objects.create( + poll=self.poll, + choice_text="first text", + votes=2 + ) - # assertion - #check that there are two choices - self.assertEqual(Choice.objects.count(), 2) + def test_choice_creation(self): + # code + # add another choice + p = Choice.objects.create( + poll=self.poll, + choice_text="second text", + votes=5 + ) + p.save() - def test_choice_update(self): - # code - # change a choice - self.choice.choice_text = "third text" - self.choice.save() - p = Choice.objects.get() + # assertion + #check that there are two choices + self.assertEqual(Choice.objects.count(), 2) - # assertion - # check the choice is egal to the new choice - self.assertEqual(p.choice_text, "third text") + def test_choice_update(self): + # code + # change a choice + self.choice.choice_text = "third text" + self.choice.save() + p = Choice.objects.get() - def test_choice_delete(self): - # code - # get Choice obj and delete it - p = Choice.objects.get() - p.delete() + # assertion + # check the choice is egal to the new choice + self.assertEqual(p.choice_text, "third text") - # assertion - # check there are nothing in db - self.assertEqual(Choice.objects.count(), 0) \ No newline at end of file + def test_choice_delete(self): + # code + # get Choice obj and delete it + p = Choice.objects.get() + p.delete() + + # assertion + # check there are nothing in db + self.assertEqual(Choice.objects.count(), 0)