Modify test case and logic of can_vote in Question model

This commit is contained in:
sosokker 2023-09-05 21:55:41 +07:00
parent d61dd2ce4b
commit 215be4d95c
2 changed files with 5 additions and 4 deletions

View File

@ -74,7 +74,8 @@ class Question(models.Model):
now = timezone.now()
if self.end_date is None:
return self.pub_date <= now
return self.pub_date <= now <= self.end_date
else:
return self.pub_date <= now <= self.end_date
class Choice(models.Model):

View File

@ -86,13 +86,13 @@ class QuestionModelTests(TestCase):
def test_can_vote_with_question_ending_in_future(self):
"""
can_vote() should return False for questions that are published but have
an end date in the future.
can_vote() should return True for questions that are published and
the current time is within the allowed voting period.
"""
pub_date = timezone.now() - datetime.timedelta(hours=1)
end_date = timezone.now() + datetime.timedelta(hours=2)
question = Question(pub_date=pub_date, end_date=end_date)
self.assertIs(question.can_vote(), False)
self.assertIs(question.can_vote(), True)
def create_question(question_text, days):