Skip to content

Commit

Permalink
Merge branch 'feature/unit-test', #4
Browse files Browse the repository at this point in the history
  • Loading branch information
noxan committed Sep 11, 2015
2 parents 3f1f2a2 + 4afc013 commit ff4d7b1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
6 changes: 4 additions & 2 deletions polls/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.db import models
from django.contrib.auth.models import User
from django.db import models
from django.utils.encoding import python_2_unicode_compatible


@python_2_unicode_compatible
class Poll(models.Model):
question = models.CharField(max_length=255)
description = models.TextField(blank=True)
Expand All @@ -18,7 +20,7 @@ def count_total_votes(self):
def can_vote(self, user):
return not self.vote_set.filter(user=user).exists()

def __unicode__(self):
def __str__(self):
return self.question


Expand Down
2 changes: 1 addition & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.test.utils import get_runner

if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
Expand Down
1 change: 1 addition & 0 deletions tests/test_settings.py → tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SECRET_KEY = 'fake-key'

INSTALLED_APPS = [
'polls',
'tests',
]

Expand Down
26 changes: 26 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
from django.test import TestCase

from polls.models import Poll


class PollTests(TestCase):
def setUp(self):
self.poll = Poll.objects.create(
question='How are you?'
)

def test_model_creation(self):
self.assertIsNotNone(self.poll)
self.assertIsInstance(self.poll, Poll)

def test_model_save(self):
self.poll.save()
self.assertIsNotNone(self.poll.pk)
self.assertTrue(self.poll.pk > 0)

def test_to_string(self):
if sys.version_info > (3,):
self.assertEquals(str(self.poll), 'How are you?')
else:
self.assertEquals(unicode(self.poll), 'How are you?')
16 changes: 0 additions & 16 deletions tests/tests.py

This file was deleted.

0 comments on commit ff4d7b1

Please sign in to comment.