def test_can_vote(self): """Test if question can vote. Test if the question can vote. """ time_pub = timezone.now() + datetime.timedelta(days=-2) time_end = timezone.now() + datetime.timedelta(days=2) available_question = Question(pub_date=time_pub, end_date=time_end) unavailable_question = Question(pub_date=time_end, end_date=time_pub) self.assertIs(available_question.can_vote(), True) self.assertIs(unavailable_question.can_vote(), False)
def test_current_question(self): """A question is current if it has been published and not yet closed""" date = timezone.now() + datetime.timedelta(minutes=1) question = Question(question_text="Is this the future?", pub_date=date) self.assertFalse( question.can_vote() ) # question with now as start day is current date = timezone.now() question = Question(question_text="Is this the present?", pub_date=date) self.assertTrue( question.can_vote() ) # question from the distant past, but no closing date date = timezone.now() - datetime.timedelta(days=365) question = Question(question_text="Is this the present?", pub_date=date) self.assertTrue( question.can_vote() )
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())
def test_between_pub_and_end_time(self): """Test that the user can vote between pub time and end time.""" 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.can_vote(), True)
def test_vote_after_end_time(self): """Test that the user can vote or not after the end time.""" pub = \ timezone.now() - datetime.timedelta(hours=23, minutes=59) end = pub + abs(datetime.timedelta(hours=22, minutes=59, seconds=59)) recent_question = Question(pub_date=pub, end_date=end) self.assertIs(recent_question.can_vote(), False)
def test_can_vote_with_past_question(self): """can_vote returns False for question whose pub_date is in the past.""" pub_time = timezone.now() - datetime.timedelta( hours=23, minutes=59, seconds=59) end_time = timezone.now() - datetime.timedelta(hours=22) older_question = Question(pub_date=pub_time, end_date=end_time) self.assertIs(older_question.can_vote(), False)
def test_can_vote_with_recent_question(self): """can_vote returns True for questions that have not been closed.""" pub_time = timezone.now() - datetime.timedelta( hours=23, minutes=59, seconds=59) end_time = timezone.now() + datetime.timedelta(days=1) recent_question = Question(pub_date=pub_time, end_date=end_time) self.assertIs(recent_question.can_vote(), True)
def test_vote_before_pub_time(self): """Test that the user can vote or not before publish time.""" pub = \ timezone.now() + datetime.timedelta(hours=5, minutes=5, seconds=5) end = pub + abs(datetime.timedelta(hours=5, minutes=5, seconds=5)) recent_question = Question(pub_date=pub, end_date=end) self.assertIs(recent_question.can_vote(), False)
def test_can_vote_with_future_question(self): """can_vote() 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.can_vote(), "can_vote should be False because it's not release yet")
def test_can_vote_with_current_date_is_after_end_date(self): """can_vote() returns False if voting is currently allowed for this question after the end date.""" time = timezone.now() - datetime.timedelta( hours=23, minutes=59, seconds=59) time_of_pub_date = timezone.now() - datetime.timedelta(days=5) recent_question = Question(pub_date=time_of_pub_date, end_date=time) self.assertIs(recent_question.can_vote(), False)
def test_can_vote_passed_end_date_question(self): """can_vote() returns False for questions that have passed the end_date.""" pub_time = timezone.now() end_time = timezone.now() + timezone.timedelta(seconds=1) question = Question(pub_date=pub_time, end_date=end_time) question.end_date -= timezone.timedelta(seconds=2) self.assertIs(question.can_vote(), False)
def test_can_vote_with_recent_question(self): """ Test question which can be voted by now. If yes, return True. """ time = timezone.now() + datetime.timedelta(days=30) recent_question = Question(pub_date=timezone.now(), end_date=time) self.assertTrue(recent_question.can_vote())
def test_can_vote_with_old_question(self): """ Test question which can be voted by past. If yes, return False. """ time = timezone.now() - datetime.timedelta(days=30) old_question = Question(pub_date=timezone.now(), end_date=time) self.assertFalse(old_question.can_vote())
def test_can_vote_with_future_question(self): """ Test question which can be voted by future. If yes, return False. """ time = timezone.now() + datetime.timedelta(days=30) future_question = Question(pub_date=time) self.assertFalse(future_question.can_vote())
def test_can_vote_with_future_question(self): """ can_vote() 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.can_vote(), False)
def test_can_vote_with_recent_question_and_not_end_yet(self): """can_vote() returns True for questions whose pub_date is in the past and is not closed.""" time = timezone.now() future_question = Question(pub_date=time, end_date=time + timezone.timedelta(days=30)) self.assertTrue( future_question.can_vote(), "can_vote should be True because it's release and not closed")
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())
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())
def test_can_vote_with_closed_question(self): """ can_vote() return False for questions whose end_date is already pass. """ pub_date_time = timezone.now() - datetime.timedelta(days=7) end_date_time = timezone.now() - datetime.timedelta(days=1) closed_question = Question(pub_date=pub_date_time, end_date=end_date_time) self.assertIs(closed_question.can_vote(), False)
def test_can_vote_with_open_question(self): """ can_vote() return True for questions whose still open. pub_date is in the past and end_date is in the future. """ pub_date_time = timezone.now() - datetime.timedelta(days=1) end_date_time = timezone.now() + datetime.timedelta(days=1) open_question = Question(pub_date=pub_date_time, end_date=end_date_time) self.assertIs(open_question.can_vote(), True)
def test_can_vote_is_work(self): """Test for can_vote(). can_vote() must returns True for questions whose pub_date is already published and end_date is not come yet. """ 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.can_vote(), True) question2 = Question(pub_date=day_before, end_date=after_day) self.assertIs(question2.can_vote(), True) question3 = Question(pub_date=after_day, end_date=after_day + self.add_time_one_year) self.assertIs(question3.can_vote(), False) question4 = Question(pub_date=after_day, end_date=time) self.assertIs(question4.can_vote(), False) question5 = Question(pub_date=time, end_date=time) self.assertIs(question5.can_vote(), False) question6 = Question(pub_date=day_before, end_date=time) self.assertIs(question6.can_vote(), False)
def test_can_vote_with_now_is_after_pub_date_and_before_end_date(self): """can_vote() return True if you're voting currently is between pub_date and end_date.""" pub_date = timezone.now() - datetime.timedelta(days=2) end_date = timezone.now() + datetime.timedelta(days=10) now = Question(pub_date=pub_date, end_date=end_date) self.assertIs(now.can_vote(), True)
def test_can_vote_with_published_question_and_it_opened(self): """can_vote() return True for the questions that is_published() is True but not reach to end_date.""" time = timezone.now() - datetime.timedelta(days=1, seconds=1) end_date_time = time + datetime.timedelta(days=10) question = Question(pub_date=time, end_date=end_date_time) self.assertIs(question.can_vote(), True)
def test_can_vote_with_unpublished_question(self): """can_vote() return False for the questions that is_published() is False.""" time = timezone.now() + datetime.timedelta(days=30) end_date_time = time + datetime.timedelta(seconds=10) question = Question(pub_date=time, end_date=end_date_time) self.assertIs(question.can_vote(), False)
def test_can_vote_with_old_question_and_is_end(self): """can_vote() returns False for questions whose pub_date is in the past and is closed.""" time = timezone.now() - timezone.timedelta(days=30) future_question = Question(pub_date=time, end_date=time) self.assertFalse(future_question.can_vote(), "can_vote should be False because it's closed")
def test_can_vote_with_now_equal_to_pub_date(self): """can_vote() return True if you're voting currently is on pub_date.""" pub_date = timezone.now() end_date = timezone.now() + datetime.timedelta(days=1) now = Question(pub_date=pub_date, end_date=end_date) self.assertIs(now.can_vote(), True)
def test_published_question_can_vote(self): """can_vote() method will return True if voted in question that not expired.""" 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.can_vote(), True)
def test_past_question_can_vote(self): """can_vote() method will return False if voted in past question.""" pub = timezone.now() - datetime.timedelta(days=7) end = timezone.now() - datetime.timedelta(days=5) past_question = Question(pub_date=pub, end_date=end) self.assertIs(past_question.can_vote(), False)
def test_can_vote_with_now_is_equal_to_end_date(self): """can_vote() return False if you're voting currently is on end_date.""" pub_date = timezone.now() + datetime.timedelta(days=1) end_date = timezone.now() before = Question(pub_date=pub_date, end_date=end_date) self.assertIs(before.can_vote(), False)
def test_can_vote_before_question(self): """Check if the question can vote before the published date.""" pub_time = timezone.now() + datetime.timedelta(days=1) question = Question(pub_date=pub_time) self.assertFalse(question.can_vote())