teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

情報の追加

2017/12/22 12:50

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -15,18 +15,27 @@
15
15
  File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/urls/resolvers.py", line 497, in _rx
16
16
  raise NoReverseMatch(msg)
17
17
  django.urls.exceptions.NoReverseMatch: Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['p]
18
-
18
+                        ・
19
19
  ======================================================================
20
- ERROR: test_past_question (polls.tests.QuestionDetailViewTests)
20
+ ERROR: test_two_past_questions (polls.tests.QuestionIndexViewTests)
21
21
  ----------------------------------------------------------------------
22
22
  Traceback (most recent call last):
23
- File "/Users/XXX/Desktop/django-master/mysite/polls/tests.py", line 230, in test_past_question
23
+ File "/Users/XXX/Desktop/django-master/mysite/polls/tests.py", line 206, in test_two_past_questions
24
+ response = self.client.get(reverse('polls:index'))
25
+ File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/test/client.py", line 536, in get
26
+ **extra)
27
+ File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/test/client.py", line 340, in get
28
+ return self.generic('GET', path, secure=secure, **r)
29
+                       ・
30
+ File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/template/defaulttags.py", line 458,r
24
- url = reverse('polls:detail', args=(past_question.id,))
31
+ url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
25
32
  File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/urls/base.py", line 91, in reverse
26
33
  return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
27
34
  File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/django/urls/resolvers.py", line 497, in _rx
28
35
  raise NoReverseMatch(msg)
29
- django.urls.exceptions.NoReverseMatch: Reverse for 'detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['p]
36
+ django.urls.exceptions.NoReverseMatch: Reverse for 'detail' with arguments '(2,)' not found. 1 pattern(s) tried: ['p]
37
+
38
+ ----------------------------------------------------------------------
30
39
  ```
31
40
  と出ています。
32
41
  tests.pyには
@@ -38,6 +47,47 @@
38
47
  from django.test import TestCase
39
48
 
40
49
  from .models import Question
50
+
51
+
52
+ class QuestionModelTests(TestCase):
53
+
54
+ def test_was_published_recently_with_future_question(self):
55
+ """
56
+ was_published_recently() returns False for questions whose pub_date
57
+ is in the future.
58
+ """
59
+ time = timezone.now() + datetime.timedelta(days=30)
60
+ future_question = Question(pub_date=time)
61
+ self.assertIs(future_question.was_published_recently(), False)
62
+
63
+ def test_was_published_recently_with_old_question(self):
64
+ """
65
+ was_published_recently() returns False for questions whose pub_date
66
+ is older than 1 day.
67
+ """
68
+ time = timezone.now() - datetime.timedelta(days=1, seconds=1)
69
+ old_question = Question(pub_date=time)
70
+ self.assertIs(old_question.was_published_recently(), False)
71
+
72
+ def test_was_published_recently_with_recent_question(self):
73
+ """
74
+ was_published_recently() returns True for questions whose pub_date
75
+ is within the last day.
76
+ """
77
+ time = timezone.now() - datetime.timedelta(hours=23, minutes=59, seconds=59)
78
+ recent_question = Question(pub_date=time)
79
+ self.assertIs(recent_question.was_published_recently(), True)
80
+
81
+ def create_question(question_text, days):
82
+ """
83
+ Create a question with the given `question_text` and published the
84
+ given number of `days` offset to now (negative for questions published
85
+ in the past, positive for questions that have yet to be published).
86
+ """
87
+ time = timezone.now() + datetime.timedelta(days=days)
88
+ return Question.objects.create(question_text=question_text, pub_date=time)
89
+
90
+
41
91
  class QuestionIndexViewTests(TestCase):
42
92
  def test_no_questions(self):
43
93
  """