質問編集履歴
1
情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,19 +32,33 @@
|
|
32
32
|
|
33
33
|
django.urls.exceptions.NoReverseMatch: Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['p]
|
34
34
|
|
35
|
-
|
35
|
+
・
|
36
36
|
|
37
37
|
======================================================================
|
38
38
|
|
39
|
-
ERROR: test_past_question (polls.tests.Question
|
39
|
+
ERROR: test_two_past_questions (polls.tests.QuestionIndexViewTests)
|
40
40
|
|
41
41
|
----------------------------------------------------------------------
|
42
42
|
|
43
43
|
Traceback (most recent call last):
|
44
44
|
|
45
|
-
File "/Users/XXX/Desktop/django-master/mysite/polls/tests.py", line 2
|
45
|
+
File "/Users/XXX/Desktop/django-master/mysite/polls/tests.py", line 206, in test_two_past_questions
|
46
|
+
|
46
|
-
|
47
|
+
response = self.client.get(reverse('polls:index'))
|
48
|
+
|
49
|
+
File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/test/client.py", line 536, in get
|
50
|
+
|
51
|
+
**extra)
|
52
|
+
|
53
|
+
File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/test/client.py", line 340, in get
|
54
|
+
|
55
|
+
return self.generic('GET', path, secure=secure, **r)
|
56
|
+
|
57
|
+
・
|
58
|
+
|
59
|
+
File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/template/defaulttags.py", line 458,r
|
60
|
+
|
47
|
-
url = reverse(
|
61
|
+
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
|
48
62
|
|
49
63
|
File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/urls/base.py", line 91, in reverse
|
50
64
|
|
@@ -54,7 +68,11 @@
|
|
54
68
|
|
55
69
|
raise NoReverseMatch(msg)
|
56
70
|
|
57
|
-
django.urls.exceptions.NoReverseMatch: Reverse for 'detail' with arguments '(
|
71
|
+
django.urls.exceptions.NoReverseMatch: Reverse for 'detail' with arguments '(2,)' not found. 1 pattern(s) tried: ['p]
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
----------------------------------------------------------------------
|
58
76
|
|
59
77
|
```
|
60
78
|
|
@@ -78,6 +96,88 @@
|
|
78
96
|
|
79
97
|
from .models import Question
|
80
98
|
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
class QuestionModelTests(TestCase):
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
def test_was_published_recently_with_future_question(self):
|
108
|
+
|
109
|
+
"""
|
110
|
+
|
111
|
+
was_published_recently() returns False for questions whose pub_date
|
112
|
+
|
113
|
+
is in the future.
|
114
|
+
|
115
|
+
"""
|
116
|
+
|
117
|
+
time = timezone.now() + datetime.timedelta(days=30)
|
118
|
+
|
119
|
+
future_question = Question(pub_date=time)
|
120
|
+
|
121
|
+
self.assertIs(future_question.was_published_recently(), False)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
def test_was_published_recently_with_old_question(self):
|
126
|
+
|
127
|
+
"""
|
128
|
+
|
129
|
+
was_published_recently() returns False for questions whose pub_date
|
130
|
+
|
131
|
+
is older than 1 day.
|
132
|
+
|
133
|
+
"""
|
134
|
+
|
135
|
+
time = timezone.now() - datetime.timedelta(days=1, seconds=1)
|
136
|
+
|
137
|
+
old_question = Question(pub_date=time)
|
138
|
+
|
139
|
+
self.assertIs(old_question.was_published_recently(), False)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
def test_was_published_recently_with_recent_question(self):
|
144
|
+
|
145
|
+
"""
|
146
|
+
|
147
|
+
was_published_recently() returns True for questions whose pub_date
|
148
|
+
|
149
|
+
is within the last day.
|
150
|
+
|
151
|
+
"""
|
152
|
+
|
153
|
+
time = timezone.now() - datetime.timedelta(hours=23, minutes=59, seconds=59)
|
154
|
+
|
155
|
+
recent_question = Question(pub_date=time)
|
156
|
+
|
157
|
+
self.assertIs(recent_question.was_published_recently(), True)
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
def create_question(question_text, days):
|
162
|
+
|
163
|
+
"""
|
164
|
+
|
165
|
+
Create a question with the given `question_text` and published the
|
166
|
+
|
167
|
+
given number of `days` offset to now (negative for questions published
|
168
|
+
|
169
|
+
in the past, positive for questions that have yet to be published).
|
170
|
+
|
171
|
+
"""
|
172
|
+
|
173
|
+
time = timezone.now() + datetime.timedelta(days=days)
|
174
|
+
|
175
|
+
return Question.objects.create(question_text=question_text, pub_date=time)
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
81
181
|
class QuestionIndexViewTests(TestCase):
|
82
182
|
|
83
183
|
def test_no_questions(self):
|