Ejemplo n.º 1
0
 def test_is_published_with_old_and_recent_question(self):
     """is_published() returns True for questions whose pub_date is in the older or within the last day."""
     old_time = timezone.now() - datetime.timedelta(days=1, seconds=1)
     new_time = timezone.now() - datetime.timedelta(seconds=1)
     old_question = Question(pub_date=old_time)
     new_question = Question(pub_date=new_time)
     self.assertIs(old_question.is_published(), True)
     self.assertIs(new_question.is_published(), True)
Ejemplo n.º 2
0
 def test_published_after_end_time(self):
     """Check that the vote is currently allowed after publication date."""
     pub = \
         timezone.now() - datetime.timedelta(hours=23, minutes=59)
     end = pub + abs(datetime.timedelta(hours=22, minutes=59))
     recent_question = Question(pub_date=pub, end_date=end)
     self.assertIs(recent_question.is_published(), True)
Ejemplo n.º 3
0
 def test_published_before_pub_time(self):
     """Check the vote is currently allowed before publication date."""
     pub = \
         timezone.now() + datetime.timedelta(hours=23, minutes=59)
     end = pub + abs(datetime.timedelta(days=2))
     recent_question = Question(pub_date=pub, end_date=end)
     self.assertIs(recent_question.is_published(), False)
Ejemplo n.º 4
0
 def test_is_published_with_future_question(self):
     """
     Test published question by future. If yes, return False.
     """
     time = timezone.now() + datetime.timedelta(days=30)
     future_question = Question(pub_date=time)
     self.assertFalse(future_question.is_published())
Ejemplo n.º 5
0
 def test_is_published_with_old_question(self):
     """
     Test published question by past. If yes, return True.
     """
     time = timezone.now() - datetime.timedelta(days=1, seconds=1)
     old_question = Question(pub_date=time)
     self.assertTrue(old_question.is_published())
Ejemplo n.º 6
0
 def test_is_published_with_future_question(self):
     """is_published() 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.assertFalse(
         future_question.is_published(),
         "is_published should be False because it's not release yet")
Ejemplo n.º 7
0
 def test_can_vote_before_pub_date(self):
     """The user could not vote before pub date."""
     now = timezone.now()
     question = Question("Test1", pub_date=now + datetime.timedelta(days=1))
     self.assertTrue(now < question.pub_date)
     self.assertFalse(question.is_published())
     self.assertFalse(question.can_vote())
Ejemplo n.º 8
0
 def test_is_published_with_future_question(self):
     """
     is_published() 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.assertIs(future_question.is_published(), False)
Ejemplo n.º 9
0
 def test_published_between_pub_and_end_time(self):
     """Check the vote is currently allowed\
         between publication and end date."""
     pub = \
         timezone.now() - datetime.timedelta(hours=23, minutes=59)
     end = pub + abs(datetime.timedelta(days=2))
     recent_question = Question(pub_date=pub, end_date=end)
     self.assertIs(recent_question.is_published(), True)
Ejemplo n.º 10
0
 def test_is_published_with_recent_question(self):
     """
     Test published question by now. If yes, return True.
     """
     time = timezone.now() - datetime.timedelta(
         hours=23, minutes=59, seconds=59)
     recent_question = Question(pub_date=time)
     self.assertTrue(recent_question.is_published())
Ejemplo n.º 11
0
 def test_is_published_after_pub_date(self):
     """The question is not published after pub date."""
     now = timezone.now()
     question = Question("Test1",
                         pub_date=now - datetime.timedelta(days=2),
                         end_date=now - datetime.timedelta(days=1))
     self.assertTrue(now > question.end_date)
     self.assertTrue(question.is_published())
Ejemplo n.º 12
0
 def test_is_publish_with_one_year_question(self):
     """
     is_published() return True for questions whose pub_date
     is older than current time no matter how old it is.
     """
     time = timezone.now() - datetime.timedelta(days=365)
     very_old_question = Question(pub_date=time)
     self.assertIs(very_old_question.is_published(), True)
Ejemplo n.º 13
0
 def test_can_vote_after_end_date(self):
     """The user could not vote after end date."""
     now = timezone.now()
     question = Question("Test1",
                         pub_date=now - datetime.timedelta(days=2),
                         end_date=now - datetime.timedelta(days=1))
     self.assertTrue(now > question.end_date)
     self.assertTrue(question.is_published())
     self.assertFalse(question.can_vote())
Ejemplo n.º 14
0
 def test_is_published_on_date(self):
     """The question is published on pub date time."""
     now = timezone.now()
     question = Question("Test1",
                         pub_date=now - datetime.timedelta(days=1),
                         end_date=now + datetime.timedelta(days=3))
     self.assertTrue(now >= question.pub_date)
     self.assertTrue(now <= question.end_date)
     self.assertTrue(question.is_published())
Ejemplo n.º 15
0
    def test_is_published(self):
        """Test if question is published.

        Test if the question can vote.

        """
        time = timezone.now() + datetime.timedelta(days=-1)
        past_question = Question(pub_date=time)
        self.assertIs(past_question.is_published(), True)
Ejemplo n.º 16
0
 def test_can_vote(self):
     """The user could vote between pub date and end date interval."""
     now = timezone.now()
     question = Question("Test1",
                         pub_date=now - datetime.timedelta(days=1),
                         end_date=now + datetime.timedelta(days=3))
     self.assertTrue(now >= question.pub_date)
     self.assertTrue(now <= question.end_date)
     self.assertTrue(question.is_published())
     self.assertTrue(question.can_vote())
Ejemplo n.º 17
0
    def test_is_published_is_work(self):
        """Test for is_published().

        is_published() must returns True for questions
        whose pub_date is already published.
        """
        time = timezone.now()
        day_before = time - self.add_time_one_year
        after_day = time + self.add_time_one_year
        question1 = Question(pub_date=time, end_date=after_day)
        self.assertIs(question1.is_published(), True)
        question2 = Question(pub_date=day_before, end_date=after_day)
        self.assertIs(question2.is_published(), True)
        question3 = Question(pub_date=after_day,
                             end_date=after_day + self.add_time_one_year)
        self.assertIs(question3.is_published(), False)
        question4 = Question(pub_date=after_day, end_date=time)
        self.assertIs(question4.is_published(), False)
        question5 = Question(pub_date=time, end_date=time)
        self.assertIs(question5.is_published(), True)
Ejemplo n.º 18
0
 def test_is_published_with_old_question(self):
     """is_published() return True for questions when reach to pub_date."""
     time = timezone.now() - datetime.timedelta(days=1, seconds=1)
     old_question = Question(pub_date=time)
     self.assertIs(old_question.is_published(), True)
Ejemplo n.º 19
0
 def test_is_published_with_recent_question(self):
     """is_published() returns True for questions whose pub_date is in the past."""
     time = timezone.now()
     future_question = Question(pub_date=time)
     self.assertTrue(future_question.is_published(),
                     "is_published should be True because it's release")
Ejemplo n.º 20
0
 def test_is_published_with_old_question(self):
     """is_published() returns True for questions whose pub_date is in the past."""
     time = timezone.now() - datetime.timedelta(days=30)
     future_question = Question(pub_date=time)
     self.assertTrue(future_question.is_published(),
                     "is_published should be False because it's release")
Ejemplo n.º 21
0
 def tsst_not_published_question(self):
     """is_published() method will return False if poll not published."""
     pub = timezone.now() + datetime.timedelta(days=1)
     end = timezone.now() + datetime.timedelta(days=5)
     not_published_question = Question(pub_date=pub, end_date=end)
     self.assertIs(not_published_question.is_published(), False)
Ejemplo n.º 22
0
 def test_published_question(self):
     """is_published() method will return True if poll already published."""
     pub = timezone.now() + datetime.timedelta(days=-1)
     end = timezone.now() + datetime.timedelta(days=5)
     published_question = Question(pub_date=pub, end_date=end)
     self.assertIs(published_question.is_published(), True)
Ejemplo n.º 23
0
 def test_is_published_with_current_date_is_before_publication_date(self):
     """is_published() returns False if current date is before question’s publication date."""
     time = timezone.now() + datetime.timedelta(
         hours=23, minutes=59, seconds=59)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.is_published(), False)
Ejemplo n.º 24
0
 def test_is_published_with_future_question(self):
     """ return False if the current time is before the question was published """
     time = timezone + datetime.timedelta(days=30)
     future_question = Question(pub_date=time)
     self.assertIs(future_question.is_published(), False)
Ejemplo n.º 25
0
 def test_is_published_with_recent_question(self):
     """is_published() return True for questions when reach to pub_date."""
     time = timezone.now() - datetime.timedelta(
         hours=23, minutes=59, seconds=59)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.is_published(), True)
Ejemplo n.º 26
0
 def test_is_published_with_old_question(self):
     """is_published() return Ture if current date is after question's publication date."""
     time = timezone.now() - datetime.timedelta(days=1)
     old_question = Question(pub_date=time)
     self.assertIs(old_question.is_published(), True)
Ejemplo n.º 27
0
 def test_is_published_with_future_question(self):
     """is_published() return False if current date is before question's publication date."""
     time = timezone.now() + datetime.timedelta(days=10)
     future_question = Question(pub_date=time)
     self.assertIs(future_question.is_published(), False)
Ejemplo n.º 28
0
 def test_is_published_with_not_published_question(self):
     """Check is_published with not published question."""
     end_time = timezone.now() + datetime.timedelta(days=1)
     question = Question(pub_date=end_time)
     self.assertFalse(question.is_published())
Ejemplo n.º 29
0
 def test_is_published_with_present_question(self):
     """is_published() return Ture if current date is on question's publication date."""
     time = timezone.now()
     present_question = Question(pub_date=time)
     self.assertIs(present_question.is_published(), True)
Ejemplo n.º 30
0
 def test_is_published(self):
     """Check for normal is_published."""
     time = timezone.now() - datetime.timedelta(days=1)
     question = Question(pub_date=time)
     self.assertTrue(question.is_published())