Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
23825b24
Kaydet (Commit)
23825b24
authored
Haz 07, 2017
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Haz 07, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Simplified tutorial's test names and docstrings.
üst
49b9c89d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
36 deletions
+35
-36
tutorial05.txt
docs/intro/tutorial05.txt
+35
-36
No files found.
docs/intro/tutorial05.txt
Dosyayı görüntüle @
23825b24
...
@@ -171,12 +171,12 @@ Put the following in the ``tests.py`` file in the ``polls`` application:
...
@@ -171,12 +171,12 @@ Put the following in the ``tests.py`` file in the ``polls`` application:
from .models import Question
from .models import Question
class QuestionM
ethod
Tests(TestCase):
class QuestionM
odel
Tests(TestCase):
def test_was_published_recently_with_future_question(self):
def test_was_published_recently_with_future_question(self):
"""
"""
was_published_recently()
should return False for questions whos
e
was_published_recently()
returns False for questions whose pub_dat
e
pub_date
is in the future.
is in the future.
"""
"""
time = timezone.now() + datetime.timedelta(days=30)
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_date=time)
future_question = Question(pub_date=time)
...
@@ -200,7 +200,7 @@ and you'll see something like::
...
@@ -200,7 +200,7 @@ and you'll see something like::
System check identified no issues (0 silenced).
System check identified no issues (0 silenced).
F
F
======================================================================
======================================================================
FAIL: test_was_published_recently_with_future_question (polls.tests.QuestionM
ethod
Tests)
FAIL: test_was_published_recently_with_future_question (polls.tests.QuestionM
odel
Tests)
----------------------------------------------------------------------
----------------------------------------------------------------------
Traceback (most recent call last):
Traceback (most recent call last):
File "/path/to/mysite/polls/tests.py", line 16, in test_was_published_recently_with_future_question
File "/path/to/mysite/polls/tests.py", line 16, in test_was_published_recently_with_future_question
...
@@ -282,8 +282,8 @@ more comprehensively:
...
@@ -282,8 +282,8 @@ more comprehensively:
def test_was_published_recently_with_old_question(self):
def test_was_published_recently_with_old_question(self):
"""
"""
was_published_recently()
should return False for questions whos
e
was_published_recently()
returns False for questions whose pub_dat
e
pub_date
is older than 1 day.
is older than 1 day.
"""
"""
time = timezone.now() - datetime.timedelta(days=1)
time = timezone.now() - datetime.timedelta(days=1)
old_question = Question(pub_date=time)
old_question = Question(pub_date=time)
...
@@ -291,8 +291,8 @@ more comprehensively:
...
@@ -291,8 +291,8 @@ more comprehensively:
def test_was_published_recently_with_recent_question(self):
def test_was_published_recently_with_recent_question(self):
"""
"""
was_published_recently()
should return True for questions whos
e
was_published_recently()
returns True for questions whose pub_dat
e
pub_date
is within the last day.
is within the last day.
"""
"""
time = timezone.now() - datetime.timedelta(hours=23, minutes=59, seconds=59)
time = timezone.now() - datetime.timedelta(hours=23, minutes=59, seconds=59)
recent_question = Question(pub_date=time)
recent_question = Question(pub_date=time)
...
@@ -450,7 +450,7 @@ class:
...
@@ -450,7 +450,7 @@ class:
def create_question(question_text, days):
def create_question(question_text, days):
"""
"""
Create
s
a question with the given `question_text` and published the
Create a question with the given `question_text` and published the
given number of `days` offset to now (negative for questions published
given number of `days` offset to now (negative for questions published
in the past, positive for questions that have yet to be published).
in the past, positive for questions that have yet to be published).
"""
"""
...
@@ -458,19 +458,19 @@ class:
...
@@ -458,19 +458,19 @@ class:
return Question.objects.create(question_text=question_text, pub_date=time)
return Question.objects.create(question_text=question_text, pub_date=time)
class QuestionViewTests(TestCase):
class Question
Index
ViewTests(TestCase):
def test_
index_view_with_
no_questions(self):
def test_no_questions(self):
"""
"""
If no questions exist, an appropriate message
should be
displayed.
If no questions exist, an appropriate message
is
displayed.
"""
"""
response = self.client.get(reverse('polls:index'))
response = self.client.get(reverse('polls:index'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "No polls are available.")
self.assertContains(response, "No polls are available.")
self.assertQuerysetEqual(response.context['latest_question_list'], [])
self.assertQuerysetEqual(response.context['latest_question_list'], [])
def test_
index_view_with_a_
past_question(self):
def test_past_question(self):
"""
"""
Questions with a pub_date in the past
should b
e displayed on the
Questions with a pub_date in the past
ar
e displayed on the
index page.
index page.
"""
"""
create_question(question_text="Past question.", days=-30)
create_question(question_text="Past question.", days=-30)
...
@@ -480,9 +480,9 @@ class:
...
@@ -480,9 +480,9 @@ class:
['<Question: Past question.>']
['<Question: Past question.>']
)
)
def test_
index_view_with_a_
future_question(self):
def test_future_question(self):
"""
"""
Questions with a pub_date in the future
should not be
displayed on
Questions with a pub_date in the future
aren't
displayed on
the index page.
the index page.
"""
"""
create_question(question_text="Future question.", days=30)
create_question(question_text="Future question.", days=30)
...
@@ -490,10 +490,10 @@ class:
...
@@ -490,10 +490,10 @@ class:
self.assertContains(response, "No polls are available.")
self.assertContains(response, "No polls are available.")
self.assertQuerysetEqual(response.context['latest_question_list'], [])
self.assertQuerysetEqual(response.context['latest_question_list'], [])
def test_
index_view_with_
future_question_and_past_question(self):
def test_future_question_and_past_question(self):
"""
"""
Even if both past and future questions exist, only past questions
Even if both past and future questions exist, only past questions
should b
e displayed.
ar
e displayed.
"""
"""
create_question(question_text="Past question.", days=-30)
create_question(question_text="Past question.", days=-30)
create_question(question_text="Future question.", days=30)
create_question(question_text="Future question.", days=30)
...
@@ -503,7 +503,7 @@ class:
...
@@ -503,7 +503,7 @@ class:
['<Question: Past question.>']
['<Question: Past question.>']
)
)
def test_
index_view_with_
two_past_questions(self):
def test_two_past_questions(self):
"""
"""
The questions index page may display multiple questions.
The questions index page may display multiple questions.
"""
"""
...
@@ -521,20 +521,19 @@ Let's look at some of these more closely.
...
@@ -521,20 +521,19 @@ Let's look at some of these more closely.
First is a question shortcut function, ``create_question``, to take some
First is a question shortcut function, ``create_question``, to take some
repetition out of the process of creating questions.
repetition out of the process of creating questions.
``test_
index_view_with_no_questions`` doesn't create any questions, but checks
``test_
no_questions`` doesn't create any questions, but checks the message:
the message: "No polls are available." and verifies the ``latest_question_list``
"No polls are available." and verifies the ``latest_question_list`` is empty.
is empty. Note that the :class:`django.test.TestCase` class provides some
Note that the :class:`django.test.TestCase` class provides some additional
a
dditional a
ssertion methods. In these examples, we use
assertion methods. In these examples, we use
:meth:`~django.test.SimpleTestCase.assertContains()` and
:meth:`~django.test.SimpleTestCase.assertContains()` and
:meth:`~django.test.TransactionTestCase.assertQuerysetEqual()`.
:meth:`~django.test.TransactionTestCase.assertQuerysetEqual()`.
In ``test_
index_view_with_a_past_question``, we create a question and verify that it
In ``test_
past_question``, we create a question and verify that it appears in
appears in
the list.
the list.
In ``test_index_view_with_a_future_question``, we create a question with a
In ``test_future_question``, we create a question with a ``pub_date`` in the
``pub_date`` in the future. The database is reset for each test method, so the
future. The database is reset for each test method, so the first question is no
first question is no longer there, and so again the index shouldn't have any
longer there, and so again the index shouldn't have any questions in it.
questions in it.
And so on. In effect, we are using the tests to tell a story of admin input
And so on. In effect, we are using the tests to tell a story of admin input
and user experience on the site, and checking that at every state and for every
and user experience on the site, and checking that at every state and for every
...
@@ -565,21 +564,21 @@ in the future is not:
...
@@ -565,21 +564,21 @@ in the future is not:
.. snippet::
.. snippet::
:filename: polls/tests.py
:filename: polls/tests.py
class Question
IndexDetail
Tests(TestCase):
class Question
DetailView
Tests(TestCase):
def test_
detail_view_with_a_
future_question(self):
def test_future_question(self):
"""
"""
The detail view of a question with a pub_date in the future
should
The detail view of a question with a pub_date in the future
return a 404 not found.
return
s
a 404 not found.
"""
"""
future_question = create_question(question_text='Future question.', days=5)
future_question = create_question(question_text='Future question.', days=5)
url = reverse('polls:detail', args=(future_question.id,))
url = reverse('polls:detail', args=(future_question.id,))
response = self.client.get(url)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.assertEqual(response.status_code, 404)
def test_
detail_view_with_a_
past_question(self):
def test_past_question(self):
"""
"""
The detail view of a question with a pub_date in the past
should
The detail view of a question with a pub_date in the past
display the question's text.
display
s
the question's text.
"""
"""
past_question = create_question(question_text='Past Question.', days=-5)
past_question = create_question(question_text='Past Question.', days=-5)
url = reverse('polls:detail', args=(past_question.id,))
url = reverse('polls:detail', args=(past_question.id,))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment