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 create_question(self, question_text, choice_texts): question = Question(question_text=question_text) question.save() for choice_text in choice_texts: Choice(question=question, choice_text=choice_text).save() return question
def test_was_published_recently_with_old_question(self): """ was_published_recently() returns False for questions whose pub_date is older than 1 day. """ time = timezone.now() - datetime.timedelta(days=1, seconds=1) old_question = Question(pub_date=time) self.assertIs(old_question.was_published_recently(), False)
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())
def test_was_published_recently_with_old_question(self): """ Tendría que retornar falso si creamos una Question de más de un día. """ time = timezone.now() - datetime.timedelta(days=1, seconds=1) old_question = Question(pub_date=time) self.assertIs(old_question.was_published_recently(), False)
def test_was_published_recentrly(self): # 1日よりも少しだけ古い obj = Question(pub_date=timezone.now() - timedelta(days=1, minutes=1)) self.assertFalse(obj.was_published_recently(), '1日と1分前に公開') # 1日よりも少しだけ新しい obj = Question(pub_date=timezone.now() - timedelta(days=1) + timedelta(minutes=1)) self.assertTrue(obj.was_published_recently(), '1日と1分後に公開') # つい最近公開 obj = Question(pub_date=timezone.now() - timedelta(minutes=1)) self.assertTrue(obj.was_published_recently(), '1分前に公開') # もうちょっとしたら公開 obj = Question(pub_date=timezone.now() + timedelta(minutes=1)) self.assertFalse(obj.was_published_recently(), '1分後に公開')
def test_was_published_recently_with_recent_question(self): """ Test recently 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.assertIs(recent_question.was_published_recently(), True)
def test_was_published_recently_with_future_question(self): """ 将来发布的问卷应该返回False :return: boolean """ time = timezone.now() + datetime.timedelta(days=30) future_question = Question(pub_date=time) self.assertIs(future_question.was_published_recently(), False)
def test_was_published_recently_with_recent_question(self): """ 最近一天内的问卷,返回True """ 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)
def test_was_published_recently_with_old_question(self): """ 超过1天的问卷返回False :return: boolean """ time = timezone.now() - datetime.timedelta(days=1, seconds=1) old_question = Question(pub_date=time) self.assertIs(old_question.was_published_recently(), False)
def create_event_poll(request, event_id): event = Event.objects.get(pk=event_id) question_text = request.POST['question_text'] poll = Question(question_text=question_text, creator=request.user, event=event).save() messages.success(request, 'Added a Poll for the event...') return HttpResponseRedirect(reverse('event:detail', args=(event_id, )))
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())
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)
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 test_was_published_recently_with_future_question(self): """ was_published_recently() returns False for question whose pub_date is in the future """ time = timezone.now() + datetime.timedelta(days=30) future_question = Question(pub_date=time) assert future_question.was_published_recently() == False
def test_was_published_recently_with_future_question(self): """ was_published_recently() возвращает False для вопроса, который имеет pub_date - будущее время """ time = timezone.now() + timezone.timedelta(days=30) future_question = Question(question_text='Абаракадабра?', pub_date=time) future_question.save() self.assertIs(future_question.was_published_recently(), False)
def test_was_published_recentlyd_true(self): first_question = Question() first_question.question_text = "have to be True" first_question.pub_date = timezone.now() first_question.save() saved_item = Question.objects.all().first() self.assertTrue(saved_item.was_published_recently())
def test_add_question(): """ Test if we can add a question to the database safely """ pub_date = timezone.now() question = Question(question_text="Test question", pub_date=pub_date) question.save() assert question.question_text == "Test question" assert question.pub_date == pub_date
def test_was_published_recently_with_old_question(self): """ was_published_recently() return False for questions whose pub_date is in the future. :return: """ time = timezone.now() - datetime.timedelta(days=1, seconds=1) old_question = Question(pub_date=time) # 创建一个出版时间超过1天的Question self.assertIs(old_question.was_published_recently(), False) # 对于出版时间超过1天的记录,返回值应该是False
def test_was_published_recently_with_future_question(self): """ was_published_recently() return False for questions whose pub_date is in the future. :return: """ time = timezone.now() + datetime.timedelta(days=30) future_question = Question(pub_date=time) # 创建一个出版时间在未来的Question self.assertIs(future_question.was_published_recently(), False) # 对于出版时间在外来的记录,返回值应该是False
def test_was_published_recently_with_future_question(self): """ Was_published_recently() returns False for questions whose pub_date is in future. :return:False """ time = timezone.now() + datetime.timedelta(days=30) future_question = Question(pub_date=time) self.assertIs(future_question.was_published_recently(), False)
def test_was_published_recently_with_old_question(self): """ It should return False if a question was published more than 1 day ago. """ old_date = timezone.now() - datetime.timedelta(days=1, seconds=1) old_question = Question(pub_date=old_date) self.assertIs(old_question.was_published_recently(), False)
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)
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)
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)
def test_was_published_recently_with_old_question(self): """Test for was_published_recently(). was_published_recently() must returns False for questions whose pub_date is older than 1 day. """ time = timezone.now() - datetime.timedelta(days=1, seconds=1) end_time = time + self.add_time_one_year old_question = Question(pub_date=time, end_date=end_time) self.assertIs(old_question.was_published_recently(), False)
def test_was_published_recently_with_future_question(self): """Test for was_published_recently(). was_published_recently() must returns False for questions whose pub_date is in the future. """ time = timezone.now() + datetime.timedelta(days=30) end_time = time + self.add_time_one_year future_question = Question(pub_date=time, end_date=end_time) self.assertIs(future_question.was_published_recently(), False)
def test_was_published_recently_with_recent_question(self): """ was_published_recently() returns False for questions whose pub_date is older than 1 day. """ recent_time = timezone.now() - datetime.timedelta( hours=23, minutes=59, seconds=58) recent_question = Question(pub_date=recent_time) self.assertIs(recent_question.was_published_recently(), True)
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)