コード例 #1
0
    def test_was_published_recently(self):
        """Does the published recently filter work with current and old q's?"""
        from polls.models import Question
        q = Question(question_text="test 1", pub_date=timezone.now())
        q2 = Question(question_text="test 2",
                      pub_date=timezone.now() - datetime.timedelta(days=2))

        assert q.was_published_recently() is True
        assert q2.was_published_recently() is False
コード例 #2
0
ファイル: tests.py プロジェクト: stefsy/djroku
 def test_was_published_recently_with_recent_question(self):
     """
     should return true
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True)
コード例 #3
0
ファイル: tests.py プロジェクト: grdavis/django_tutorial
 def test_was_published_recently_with_old_question(self):
 	"""
 	should return False if the question is older than a day
 	"""
 	time = timezone.now() - datetime.timedelta(days=1)
 	past_question = Question(pub_date=time)
 	self.assertEqual(past_question.was_published_recently(), False)
コード例 #4
0
ファイル: tests.py プロジェクト: ntmagda93/pollsApplication
 def test_was_publishsed_recently_with_future_question(self):
     """
     was_published_recently() should return false for future questions
     """
     time = timezone.now() + timezone.timedelta(days=30)
     future_question = Question(pub_date=time)
     self.assertEqual(future_question.was_published_recently(), False)
コード例 #5
0
ファイル: test_models.py プロジェクト: Spaghet/django_study
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() should return true for questions less than a day old in the past.
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.was_published_recently(), True)
コード例 #6
0
ファイル: tests.py プロジェクト: aldraco/django-app
 def test_was_published_recently_with_recent_question(self):
     """
 was_published_recently() should return True for q's whose pub_dates are within the last day
 """
     one_hour_ago = timezone.now() - datetime.timedelta(hours=1)  # one hour ago
     recent_question = Question(pub_date=one_hour_ago)
     self.assertEqual(recent_question.was_published_recently(), True)
コード例 #7
0
ファイル: test_models.py プロジェクト: Spaghet/django_study
 def test_was_published_recently_with_old_questions(self):
     """
     was_published_recently() should return False for questions more than a day old.
     """
     time = timezone.now() - datetime.timedelta(days=30)
     old_question = Question(pub_date=time)
     self.assertIs(old_question.was_published_recently(), False)
コード例 #8
0
ファイル: test.py プロジェクト: ProX666/django_tut
    def test_was_published_recently_with_future_question(self):
        """
        was_published_recently() should return False for questions whose
        pub_date is in the future
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertEqual(future_question.was_published_recently(), False)

	def test_was_published_recently_with_old_question(self):
		"""
		was_published_recently() should return False for questions whose
		pub_date is older than 1 day
		"""
		time = timezone.now() - datetime.timedelta(days=30)
		old_question = Question(pub_date=time)
		self.assertEqual(old_question.was_published_recently(), False)

	def test_was_published_recently_with_recent_question(self):
		"""
		was_published_recently() should return True for questions whose
		pub_date is within the last day
		"""
		time = timezone.now() - datetime.timedelta(hours=1)
		recent_question = Question(pub_date=time)
		self.assertEqual(recent_question.was_published_recently(), True)
コード例 #9
0
	def test_was_published_recently_with_recent_questions(self):
		""" was_published_recently() should return True for questions whose
		pub_date is within the last day
		"""
		time = timezone.now() - datetime.timedelta(hours=1)
		recent_question = Question(pub_date=time)
		self.assertEqual(recent_question.was_published_recently(), True)
コード例 #10
0
ファイル: tests.py プロジェクト: Markwaardig/Assessment
	def test_was_published_recently_with_old_question(self):
    	"""
    	was_published_recently() should return False for questions whose
    	pub_date is older than 1 day
    	"""
    	time = timezone.now() - datetime.timedelta(days=30)
    	old_question = Question(pub_date=time)
    	self.assertEqual(old_question.was_published_recently(), False)

	def test_was_published_recently_with_recent_question(self):
    	"""
    	was_published_recently() should return True for questions whose
    	pub_date is within the last day
    	"""
    	time = timezone.now() - datetime.timedelta(hours=1)
    	recent_question = Question(pub_date=time)
    	self.assertEqual(recent_question.was_published_recently(), True)

        ### inserted

    def create_question(question_text, days):
        """
        Creates a question with the given `question_text` published the given
        number of `days` offset to now (negative for questions published
        in the past, positive for questions that have yet to be published).
        """
        time = timezone.now() + datetime.timedelta(days=days)
        return Question.objects.create(question_text=question_text,
                                       pub_date=time)
コード例 #11
0
ファイル: tests.py プロジェクト: Betrezen/Projects
 def test_was_published_recently_with_future_poll(self):
     """
     was_published_recently() should return False for polls whose
     pub_date is in the future
     """
     future_poll = Question(pub_date=timezone.now() + datetime.timedelta(days=30))
     self.assertEqual(future_poll.was_published_recently(), False)
コード例 #12
0
	def test_was_published_recently_with_old_question(self):
		"""
		was_published_recently should return False for questions whose pub_date is older than 1 day
		"""
		time = timezone.now() - datetime.timedelta(days=30)
		old_question = Question(pub_date=time)
		self.assertEqual(old_question.was_published_recently(), False)
コード例 #13
0
	def test_was_published_recently_with_recent_question(self):
		"""
		was_published_recently() shoudl return True for questions whose pub_date is within a day old.
		"""
		time = timezone.now()
		current_question = Question(pub_date=time)
		self.assertEqual(current_question.was_published_recently(), True)
コード例 #14
0
ファイル: tests.py プロジェクト: AprilWZhao/pollsApp
 def test_was_published_recently_with_future_question(self):
     """
     was_published_recently() should return False for questions whose pub_date is in the future.
     """
     time = timezone.now()+datetime.timedelta(days=30)
     future_question = Question(pub_date=time)
     self.assertEqual(future_question.was_published_recently(), False)
コード例 #15
0
	def test_was_published_recently_with_old_question(self):
		"""
		was_published_recently() should return False for questions whose pub_date is over a day in the past
		"""
		time = timezone.now() - datetime.timedelta(days=2)
		past_question = Question(pub_date=time)
		self.assertEqual(past_question.was_published_recently(), False)
コード例 #16
0
ファイル: tests.py プロジェクト: ntmagda93/pollsApplication
    def test_was_published_recently_with_normal_question(self):
        """
        was_published_recently() should return true for question published less than 1 day ago
        """

        time = timezone.now() - timezone.timedelta(hours=2)
        normal_question = Question(pub_date = time)
        self.assertEqual(normal_question.was_published_recently(), True)
コード例 #17
0
ファイル: tests.py プロジェクト: 99ballons/django_tutorial
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently() should return false if the pub_date is
     older than 1 day
     """
     time = timezone.now() - datetime.timedelta(days=2)
     old_question = Question(pub_date=time)
     self.assertEquals(old_question.was_published_recently(), False, "Question posted 2 days ago")
コード例 #18
0
ファイル: tests.py プロジェクト: 99ballons/django_tutorial
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() should return true if the pub_date is 
     within 1 Day
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True, "Question posted 1 hour ago")
コード例 #19
0
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently should return False if its pub_date is
     not within the last day.
     """
     time = timezone.now() - datetime.timedelta(days = 5)
     old_question = Question(pub_date = time)
     self.assertEqual(old_question.was_published_recently(), False)
コード例 #20
0
ファイル: tests.py プロジェクト: ntmagda93/pollsApplication
    def test_was_published_recently_with_old_questions(self):
        """
        was_published_recently() should return flase for question published older that 1 day
        """

        time = timezone.now() - timezone.timedelta(days=2)
        old_question = Question(pub_date=time)
        self.assertEqual(old_question.was_published_recently(), False)
コード例 #21
0
ファイル: tests.py プロジェクト: aman01/mysite
	def test_was_published_recently_with_future_question(self):
		#pass
		"""docstring for QuestionMethodTest"TestCasef __init__(self, arg):
		def test_was_published_recently_with_future_question(self):
		pass"""
		time = timezone.now() + datetime.timedelta(days=30)
		future_question = Question(pub_date = time)
		self.assertEqual(future_question.was_published_recently(),False)
コード例 #22
0
    def test_was_published_recently_with_future_question(self):
        """
        Was_published_recently() Tendría que retornar falso
        cuando se crea una Question con pub_date en el futuro.
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)

        self.assertIs(future_question.was_published_recently(), False)
コード例 #23
0
    def test_was_published_recently_with_recent_question(self):
        """
        Tendría que retornar True si creamos una Question dentro del rango de un día
        """
        time = timezone.now() - datetime.timedelta(
            hours=23, minutes=59, seconds=59)
        recent_question = Question(pub_date=time)

        self.assertIs(recent_question.was_published_recently(), True)
コード例 #24
0
 def test_was_published_recently_with_recent_question(self):
     """
     1天内的问卷返回True
     :return: boolean
     """
     time = timezone.now() - datetime.timedelta(
         hours=23, minutes=59, seconds=59)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.was_published_recently(), True)
コード例 #25
0
    def test_was_published_recently_with_future_question(self):
        """
        was_published_recently() returns False for questions whose pub_date is in the future.
        :return:
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)

        self.assertIs(future_question.was_published_recently(), False)
コード例 #26
0
    def test_was_published_recently_with_old_question(self):
        """
        was_published_recently() returns False for questions whose pub_date is older than 1 day.
        :return:
        """
        time = timezone.now() - datetime.timedelta(days=1, seconds=1)
        old_question = Question(pub_date=time)

        self.assertIs(old_question.was_published_recently(), False)
コード例 #27
0
    def test_was_published_recently_with_future_question(self):
        """
		was_published_recently() should return false for question
		whose pub_date is in the future
		"""

        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertEqual(future_question.was_published_recently(), False)
コード例 #28
0
ファイル: tests.py プロジェクト: hardvic/django_study_proj
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() should return True whose pub_date is
     within in last day.
     :return:
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.was_published_recently(), True)
コード例 #29
0
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently() should return False for questions whose
     pub_date is older than 1 day
     :return:
     """
     time = timezone.now() - datetime.timedelta(days=30)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), False)
コード例 #30
0
ファイル: tests.py プロジェクト: vinlinch/mysite
 def test_was_published_recently_with_future_poll(self):
     """
     was_published_recently() should return False for polls whose
     pub_date is in the future
     :return:
     """
     future_poll = Question(pub_date=timezone.now() +
                            datetime.timedelta(days=30))
     self.assertEqual(future_poll.was_published_recently(), False)
コード例 #31
0
ファイル: tests.py プロジェクト: Noboomta/ISP-SKE-KU-2020
    def test_was_published_recently_with_future_question(self):
        """Test if future question is not published.

        Test if future question is not published.

        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertIs(future_question.was_published_recently(), False)
コード例 #32
0
ファイル: tests.py プロジェクト: Andchenn/vote
def test_was_published_recently_with_old_question(self):
    """
    只要是超过1天 的问卷,返回False
    :param self:
    :return:
    """
    time = timezone.now() - datetime.timedelta(days=1, seconds=1)
    old_question = Question(pub_date=time)
    self.assertIs(old_question.was_published_recently(), False)
コード例 #33
0
ファイル: tests.py プロジェクト: Noboomta/ISP-SKE-KU-2020
    def test_was_published_recently_with_old_question(self):
        """Test if old question is published.

        Test if old question is published.

        """
        time = timezone.now() - datetime.timedelta(days=1, seconds=1)
        old_question = Question(pub_date=time)
        self.assertIs(old_question.was_published_recently(), False)
コード例 #34
0
ファイル: test.py プロジェクト: jimchim/polling
    def test_was_published_recently_with_recent_question(self):
        """
        was_published_recently() function should return True for questions
        whose pub_date is within 1 day in the past
        """

        time = timezone.now() - datetime.timedelta(days = 0.5)
        recent_question = Question(pub_date = time)
        self.assertEqual(recent_question.was_published_recently(), True)
コード例 #35
0
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() returns True for questions whose pub_date
     is within the last day.
     """
     time = timezone.now() - datetime.timedelta(
         hours=23, minutes=59, seconds=59)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.was_published_recently(), True)
コード例 #36
0
ファイル: tests.py プロジェクト: vinlinch/mysite
 def test_was_published_recently_with_old_poll(self):
     """
     was_published_recently() should return False for polls whose pub_date
     is older than 1 day
     :return:
     """
     old_poll = Question(pub_date=timezone.now() -
                         datetime.timedelta(days=30))
     self.assertEqual(old_poll.was_published_recently(), False)
コード例 #37
0
ファイル: tests.py プロジェクト: leexuan0128/MyPracticeInOne
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() should return True for questions whose pub_date is within the same day
     """
     time = timezone.now() - datetime.timedelta(
         hours=23, minutes=59,
         seconds=30)  # assume the running time is <30s
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.was_published_recently(), True)
コード例 #38
0
ファイル: tests.py プロジェクト: vinlinch/mysite
 def test_was_published_recently_with_recent_poll(self):
     """
     was_published_recently() should return True for polls whose pub_date
     is within the last day
     :return:
     """
     recent_poll = Question(pub_date=timezone.now() -
                            datetime.timedelta(hours=1))
     self.assertEqual(recent_poll.was_published_recently(), True)
コード例 #39
0
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recenlty() should return True for questions whose pub_date
     is within the last day
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True)
         
コード例 #40
0
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently() returns False for question whose
     Pub_date is olded than 1 day
     """
     time = timezone.now() - datetime.timedelta(days=1, seconds=1)
     # old_question = mixer.blend('polls.Question', pub_date=time)
     old_question = Question(pub_date=time)
     assert old_question.was_published_recently() == False
コード例 #41
0
    def test_was_published_recently_with_recent_question(self):
        """Test if recent question is published recently.

        Test if recent question is published recently.

        """
        time = timezone.now() - datetime.timedelta(
            hours=23, minutes=59, seconds=59)
        recent_question = Question(pub_date=time)
        self.assertIs(recent_question.was_published_recently(), True)
コード例 #42
0
ファイル: test_poll_dates.py プロジェクト: ZEZAY/ku-polls
    def test_was_published_recently_with_recent_question(self):
        """Test for was_published_recently().

        was_published_recently() must returns True for questions whose pub_date is within the last day.
        """
        delta = datetime.timedelta(hours=23, minutes=59, seconds=59)
        time = timezone.now() - delta
        end_time = time + self.add_time_one_year
        recent_question = Question(pub_date=time, end_date=end_time)
        self.assertIs(recent_question.was_published_recently(), True)
コード例 #43
0
    def test_was_published_recently_with_recent_question(self):
        """
        It should return True if a question was published until 1 day ago.
        """

        recent_date = timezone.now() - datetime.timedelta(
            hours=23, minutes=59, seconds=59)
        recent_question = Question(pub_date=recent_date)

        self.assertIs(recent_question.was_published_recently(), True)
コード例 #44
0
    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)

        # Assert future question will return false, otherwise, there is a bug
        self.assertIs(future_question.was_published_recently(), False)
コード例 #45
0
ファイル: tests.py プロジェクト: GlynPrice/DjangoPythonPolls
 def pubStatusOfQuestion(self, theQuestionP, timePublishedP, pubStatusP):
   aQuestion = Question(question_text = theQuestionP, pub_date = timePublishedP)
   #aQuestion is created, but as it is not saved it is no put in the
   #db.sqlite3 database
   pubStatusP[0] = aQuestion.was_published_recently()
   #print aQuestion.id
   #print aQuestion.question_text
   #print aQuestion.pub_date
   #print "    pubStatusOfQuestion: ", pubStatusP[0], pubStatusP, "    ",
   return 0
コード例 #46
0
 def test_was_published_recently_with_future_question(self):
     # 미래의 datetime객체를 time변수에 할당
     time = timezone.now() + datetime.timedelta(days=30)
     # 새 Question인스턴스를 생성, pub_date값에 미래시간을 주어줌
     future_question = Question(pub_date=time)
     # 주어진 2개의 객체가 같아야 할 것(is)으로 기대함
     # 같지 않은면 실패
     self.assertIs(
         future_question.was_published_recently(),
         False,
     )
コード例 #47
0
ファイル: tests.py プロジェクト: OkThought/DjangoPoll
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently() returns False for a question
     with pub_date older than one day the past
     """
     for step_back in [
             timezone.timedelta(days=1, seconds=1),
             timezone.timedelta(days=2),
     ]:
         past_time = timezone.now() - step_back
         past_question = Question(pub_date=past_time)
         self.assertFalse(past_question.was_published_recently())
コード例 #48
0
ファイル: tests.py プロジェクト: OkThought/DjangoPoll
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() returns True for a question
     with pub_date within one day the past
     """
     for step_back in [
             timezone.timedelta(hours=23, minutes=59, seconds=59),
             timezone.timedelta(hours=12),
             timezone.timedelta(seconds=1),
             timezone.timedelta(seconds=0),
     ]:
         past_time = timezone.now() - step_back
         past_question = Question(pub_date=past_time)
         self.assertTrue(past_question.was_published_recently())
コード例 #49
0
    def test_was_published_recently_with_recent_question(self):
        """
        was_published_recently() should return True for questions whose
        pub_date is within the last day
        """
        time = timezone.now() - datetime.timedelta(hours=1)
        recent_question = Question(pub_date=time)
        self.assertEqual(recent_question.was_published_recently(), True)
		
	def create_question(question_text, days):
		"""
		Creates a question with the given `question_text` published the given
		number of `days` offset to now (negative for questions published
		in the past, positive for questions that have yet to be published).
		"""
		time = timezone.now() + datetime.timedelta(days=days)
		return Question.objects.create(question_text=question_text,pub_date=time)
コード例 #50
0
 def test_was_published_recently_with_recent_question(self):
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True)
コード例 #51
0
 def test_was_published_recently_with_old_question(self):
     time = timezone.now() - datetime.timedelta(days=30)
     old_question = Question(pub_date=time)
     self.assertEqual(old_question.was_published_recently(), False)
コード例 #52
0
ファイル: tests.py プロジェクト: haoweibo1987/website
    def test_was_published_recently_with_future_question(self):
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)

        self.assertEqual(future_question.was_published_recently(), False)
コード例 #53
0
ファイル: tests.py プロジェクト: evaldobratti/djangolive
	def test_was_published_recently_should_return_true_for_a_recent_question(self):
		time = timezone.now() - datetime.timedelta(hours=1)
		recent_question = Question(pub_date=time)
		self.assertEqual(recent_question.was_published_recently(), True)
コード例 #54
0
 def test_was_published_recently_with_recent_question(self):
     time = timezone.now() + datetime.timedelta(hours=23, minutes=59, seconds=59)
     recent_quesion = Question(pub_date=time)
     self.assertIs(recent_quesion.was_published_recently(), False)
コード例 #55
0
ファイル: ceshi.py プロジェクト: FrankHitman/wechat
import datetime
from django.utils import timezone
from polls.models import Question

future_question = Question(pub_date=timezone.now() + datetime.timedelta(days=30))

future_question.was_published_recently()
コード例 #56
0
ファイル: tests.py プロジェクト: malcolmmathew/december
	def test_was_published_recently_with_recent_question(self):
		time = timezone.now() - datetime.timedelta(days = 0.5)
		recent_question = Question(pub_date=time)
		self.assertEqual(recent_question.was_published_recently(), True)
コード例 #57
0
ファイル: tests.py プロジェクト: evaldobratti/djangolive
	def test_was_published_recently_should_return_false_for_an_old_questino(self):
		time = timezone.now() - datetime.timedelta(days=30)
		old_question = Question(pub_date=time)
		self.assertEqual(old_question.was_published_recently(), False)
コード例 #58
0
ファイル: cc.py プロジェクト: tbjc1magic/HELIOSwebsite
from polls.models import Question, Choice
from django.utils import timezone
import datetime


q1 = Question(question_text="tt",pub_date=timezone.now())
q1.save()
q1.choice_set.create(choice_text='fdsaf',votes=1)
q1.was_published_recently()
q1.delete()
len(Question.objects.all())

q = Question.objects.get(pk=1)

q.choice_set.all()
c=q.choice_set.create(choice_text = 'just fdsa', votes=0)
c.question
q.choice_set.all()

Choice.objects.all()
kk=len(Choice.objects.all())-1

print "key number", c.id,kk
c1  = q.choice_set.get(pk=kk)
print c1
c1.delete()

for sc in Choice.objects.all():
    print sc.choice_text,sc.id

コード例 #59
0
ファイル: tests.py プロジェクト: grdavis/django_tutorial
 def test_was_published_recently_with_recent_question(self):
 	"""
 	should return True if the question is within one day of publication
 	"""
 	recent_question = Question(pub_date = timezone.now() - timezone.timedelta(hours=1))
 	self.assertEqual(recent_question.was_published_recently(), True)
コード例 #60
0
ファイル: tests.py プロジェクト: ralfsteel/mysite
    def test_was_published_recently_with_old_question(self):

    """
    was_published_recently() should return False for questions whose
    pub_date is older than 1 day
    """
    time = timezone.now() - datetime.timedelta(days=30)
    old_question = Question(pub_date=time)
    self.assertEqual(old_question.was_published_recently(), False)

    def test_was_published_recently_with_recent_question(self):
    """
    was_published_recently() should return True for questions whose
    pub_date is within the last day
    """
    time = timezone.now() - datetime.timedelta(hours=1)
    recent_question = Question(pub_date=time)
    self.assertEqual(recent_question.was_published_recently(), True)


class QuestionViewTests(TestCase):
    def test_index_view_with_no_questions(self):
        """
        If no questions exist, an appropriate message should be displayed.
        """
        response = self.client.get(reverse('polls:index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "No polls are available.")
        self.assertQuerysetEqual(response.context['latest_question_list'], [])

    def test_index_view_with_a_past_question(self):
        """
        Questions with a pub_date in the past should be displayed on the
        index page
        """
        create_question(question_text="Past question.", days=-30)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_question_list'],
            ['<Question: Past question.>']
        )

    def test_index_view_with_a_future_question(self):
        """
        Questions with a pub_date in the future should not be displayed on
        the index page.
        """
        create_question(question_text="Future question.", days=30)
        response = self.client.get(reverse('polls:index'))
        self.assertContains(response, "No polls are available.",
                            status_code=200)
        self.assertQuerysetEqual(response.context['latest_question_list'], [])

    def test_index_view_with_future_question_and_past_question(self):
        """
        Even if both past and future questions exist, only past questions
        should be displayed.
        """
        create_question(question_text="Past question.", days=-30)
        create_question(question_text="Future question.", days=30)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_question_list'],
            ['<Question: Past question.>']
        )

    def test_index_view_with_two_past_questions(self):
        """
        The questions index page may display multiple questions.
        """
        create_question(question_text="Past question 1.", days=-30)
        create_question(question_text="Past question 2.", days=-5)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_question_list'],
            ['<Question: Past question 2.>', '<Question: Past question 1.>']
        )


class QuestionIndexDetailTests(TestCase):
    def test_detail_view_with_a_future_question(self):
        """
        The detail view of a question with a pub_date in the future should
        return a 404 not found.
        """
        future_question = create_question(question_text='Future question.',
                                          days=5)
        response = self.client.get(reverse('polls:detail',
                                   args=(future_question.id,)))
        self.assertEqual(response.status_code, 404)

    def test_detail_view_with_a_past_question(self):
        """
        The detail view of a question with a pub_date in the past should
        display the question's text.
        """
        past_question = create_question(question_text='Past Question.',
                                        days=-5)
        response = self.client.get(reverse('polls:detail',
                                   args=(past_question.id,)))
        self.assertContains(response, past_question.question_text,
                            status_code=200)