Merge branch 'for-pull-requests' of git://github.com/Eleonore9/django-admin2 into Eleonore9-for-pull-requests

This commit is contained in:
Daniel Greenfeld 2013-07-06 16:22:23 +02:00
commit 2dcc816e29
3 changed files with 85 additions and 4 deletions

View file

@ -1 +1 @@
from test_views import *
from test_models import *

View file

@ -0,0 +1,81 @@
from django.test import TestCase
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()
# 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()
# assertion
#check that there are two choices
self.assertEqual(Choice.objects.count(), 2)
def test_choice_update(self):
# code
# change a choice
self.choice.choice_text = "third text"
self.choice.save()
p = Choice.objects.get()
# assertion
# check the choice is egal to the new choice
self.assertEqual(p.choice_text, "third text")
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)

View file

@ -2,15 +2,15 @@
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'example.settings'
exampleproject_dir = os.path.join(os.path.dirname(__file__), 'example')
os.environ['DJANGO_SETTINGS_MODULE'] = 'example2.settings'
exampleproject_dir = os.path.join(os.path.dirname(__file__), 'example2')
sys.path.insert(0, exampleproject_dir)
from django.test.utils import get_runner
from django.conf import settings
def runtests(tests=('blog', 'djadmin2',)):
def runtests(tests=('polls', 'djadmin2',)):
'''
Takes a list as first argument, enumerating the apps and specific testcases
that should be executed. The syntax is the same as for what you would pass