mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
[1.10.x] Fixed #26747 -- Used more specific assertions in the Django test suite.
Backport of 4f336f6652
from master
This commit is contained in:
parent
70b7d6b4ea
commit
13d60298ea
87 changed files with 404 additions and 404 deletions
|
@ -180,7 +180,7 @@ Put the following in the ``tests.py`` file in the ``polls`` application:
|
|||
"""
|
||||
time = timezone.now() + datetime.timedelta(days=30)
|
||||
future_question = Question(pub_date=time)
|
||||
self.assertEqual(future_question.was_published_recently(), False)
|
||||
self.assertIs(future_question.was_published_recently(), False)
|
||||
|
||||
What we have done here is created a :class:`django.test.TestCase` subclass
|
||||
with a method that creates a ``Question`` instance with a ``pub_date`` in the
|
||||
|
@ -203,8 +203,8 @@ and you'll see something like::
|
|||
----------------------------------------------------------------------
|
||||
Traceback (most recent call last):
|
||||
File "/path/to/mysite/polls/tests.py", line 16, in test_was_published_recently_with_future_question
|
||||
self.assertEqual(future_question.was_published_recently(), False)
|
||||
AssertionError: True != False
|
||||
self.assertIs(future_question.was_published_recently(), False)
|
||||
AssertionError: True is not False
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 1 test in 0.001s
|
||||
|
@ -285,7 +285,7 @@ more comprehensively:
|
|||
"""
|
||||
time = timezone.now() - datetime.timedelta(days=30)
|
||||
old_question = Question(pub_date=time)
|
||||
self.assertEqual(old_question.was_published_recently(), False)
|
||||
self.assertIs(old_question.was_published_recently(), False)
|
||||
|
||||
def test_was_published_recently_with_recent_question(self):
|
||||
"""
|
||||
|
@ -294,7 +294,7 @@ more comprehensively:
|
|||
"""
|
||||
time = timezone.now() - datetime.timedelta(hours=1)
|
||||
recent_question = Question(pub_date=time)
|
||||
self.assertEqual(recent_question.was_published_recently(), True)
|
||||
self.assertIs(recent_question.was_published_recently(), True)
|
||||
|
||||
And now we have three tests that confirm that ``Question.was_published_recently()``
|
||||
returns sensible values for past, recent, and future questions.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue