polls 앱에서 Question.was_puslished_recently() 메소드는 Question이 어제 게시된 경우에도 True를 반환하며, Question의 pub_date가 미래로 설정된 경우에도 True를 반환한다.
python manage.py shell 을 통해 버그를 확인 해본다.
테스트 모듈을 tests.py 로 생성한다. Django의 테스트 시스템은 해당 모듈을 자동으로 찾는다.
// polls/tests.py
import datetime
from django.test import TestCase
from django.utils import timezone
from .models import Question
class QuestionModelTests(TestCase):
def test_was_published_recently_with_future_question(self):
"""
was_published_recently() returns False for questions whose pub_date
is in the future.
"""
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_date=time)
self.assertIs(future_question.was_published_recently(), False)
python manage.py test polls
결과
Question 모델의 was_published_recently() 메소드의 버그를 수정하고 다시 테스트
** clinet 테스트는 나중에 좀 더 다루도록 하자.