Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- user@comp:~/code/python/django/mysite$ python manage.py test polls
- Creating test database for alias 'default'...
- ----------------------------------------------------------------------
- Ran 0 tests in 0.000s
- OK
- Destroying test database for alias 'default'...
- ======================================================================================================
- tests.py
- ======================================================================================================
- from django.test import TestCase
- from django.utils import timezone
- import datetime
- from polls.models import Poll
- # Create your tests here.
- class PollMethodTests(TestCase):
- def was_published_recently_with_future_poll(self):
- """
- was_published_recently() should return False for polls whose
- pub_date is in the future
- """
- #future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30))
- self.assertEqual(True, False)
- =======================================================================================================
- models.py being tested
- =======================================================================================================
- from django.db import models
- import datetime
- from django.utils import timezone
- # Create your models here.
- class Poll(models.Model):
- question = models.CharField(max_length=200)
- pub_date = models.DateTimeField('date published')
- def __unicode__(self):
- return self.question
- def was_published_recently(self):
- now = timezone.now()
- return now - datetime.timedelta(days=1) <= self.pub_date < now
- class Choice(models.Model):
- poll = models.ForeignKey(Poll)
- choice_text = models.CharField(max_length=200)
- votes = models.IntegerField(default=0)
- def __unicode__(self):
- return self.choice_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement