mirror of
https://github.com/Sosokker/ku-polls.git
synced 2025-12-19 05:24:05 +01:00
Modify test case and logic of can_vote in Question model
This commit is contained in:
parent
d61dd2ce4b
commit
215be4d95c
@ -74,7 +74,8 @@ class Question(models.Model):
|
|||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
if self.end_date is None:
|
if self.end_date is None:
|
||||||
return self.pub_date <= now
|
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):
|
class Choice(models.Model):
|
||||||
|
|||||||
@ -86,13 +86,13 @@ class QuestionModelTests(TestCase):
|
|||||||
|
|
||||||
def test_can_vote_with_question_ending_in_future(self):
|
def test_can_vote_with_question_ending_in_future(self):
|
||||||
"""
|
"""
|
||||||
can_vote() should return False for questions that are published but have
|
can_vote() should return True for questions that are published and
|
||||||
an end date in the future.
|
the current time is within the allowed voting period.
|
||||||
"""
|
"""
|
||||||
pub_date = timezone.now() - datetime.timedelta(hours=1)
|
pub_date = timezone.now() - datetime.timedelta(hours=1)
|
||||||
end_date = timezone.now() + datetime.timedelta(hours=2)
|
end_date = timezone.now() + datetime.timedelta(hours=2)
|
||||||
question = Question(pub_date=pub_date, end_date=end_date)
|
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):
|
def create_question(question_text, days):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user