finish the first test case for polls app

main
roger 2 years ago
parent 5bbfa35af9
commit 1820dca352
  1. 7
      polls/models.py
  2. 10
      polls/tests.py

@ -1,4 +1,7 @@
import datetime
from django.db import models
from django.utils import timezone
# Create your models here.
@ -9,6 +12,10 @@ class Question(models.Model):
def __str__(self):
return self.question_text
def was_published_recently(self):
# return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
now = timezone.now()
return now - datetime.timedelta(days=1) <= self.pub_date <= now
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)

@ -1,3 +1,13 @@
from django.test import TestCase
import datetime
from django.utils import timezone
from .models import Question
# Create your tests here.
class QuestionModelTests(TestCase):
def test_was_published_recently_with_future_question(self):
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_date=time)
self.assertIs(future_question.was_published_recently(), False)

Loading…
Cancel
Save