質問編集履歴
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
```
|
8
|
+
|
7
|
-
|
9
|
+
(urls.py)
|
8
10
|
|
9
11
|
path('draw_update/<int:pk>/', views.DrawUpdateView.as_view(), name="draw_update"),
|
10
12
|
|
@@ -12,7 +14,9 @@
|
|
12
14
|
|
13
15
|
|
14
16
|
|
17
|
+
```
|
18
|
+
|
15
|
-
|
19
|
+
(view.py)
|
16
20
|
|
17
21
|
class DrawUpdateView(LoginRequiredMixin, generic.UpdateView):
|
18
22
|
|
@@ -50,9 +54,47 @@
|
|
50
54
|
|
51
55
|
|
52
56
|
|
53
|
-
```
|
57
|
+
```
|
54
58
|
|
59
|
+
(test_view.py)
|
60
|
+
|
61
|
+
class TestDrawUpdateView(LoggedInTestCase):
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
def test_update_draw_success(self):
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
draw = Draw.objects.create(user=self.test_user,draw_number=1111)
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
params = {'draw_number':2222}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
response = self.client.post(reverse_lazy('draw:draw_update',kwargs={'pk':draw.pk}),params)
|
78
|
+
|
79
|
+
|
80
|
+
|
55
|
-
self.assertRedirects(response, reverse_lazy('draw:draw_detail',kwargs={'pk':draw.pk}))
|
81
|
+
self.assertRedirects(response, reverse_lazy('draw:draw_detail',kwargs={'pk':draw.pk}))
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
self.assertEqual(Draw.objects.get(pk=draw.pk).draw_number,2222)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
def test_update_draw_failure(self):
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
response = self.client.post(reverse_lazy('draw:draw_update',kwargs={'pk':999}))
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
self.assertEqual(response.status_code, 404)
|
56
98
|
|
57
99
|
```
|
58
100
|
|
1
コード等追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1 +1,63 @@
|
|
1
|
-
DjangoにてTestを行ったのですが、AssertionErrorが出てしまい、色々調べて試してみたのですが解決できませんでした。
|
1
|
+
DjangoにてTestを行ったのですが、おそらく更新の箇所でAssertionErrorが出てしまい、色々調べて試してみたのですが解決できませんでした。
|
2
|
+
|
3
|
+
教えて頂けると助かります。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```urls.py
|
8
|
+
|
9
|
+
path('draw_update/<int:pk>/', views.DrawUpdateView.as_view(), name="draw_update"),
|
10
|
+
|
11
|
+
```
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
```view.py
|
16
|
+
|
17
|
+
class DrawUpdateView(LoginRequiredMixin, generic.UpdateView):
|
18
|
+
|
19
|
+
model = Draw
|
20
|
+
|
21
|
+
template_name = 'draw_update.html'
|
22
|
+
|
23
|
+
form_class = DrawCreateForm
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
def get_success_url(self):
|
28
|
+
|
29
|
+
return reverse_lazy('draw:draw_detail', kwargs={'pk': self.kwargs['pk']})
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def form_valid(self, form):
|
34
|
+
|
35
|
+
messages.success(self.request, '図面情報を更新しました。')
|
36
|
+
|
37
|
+
return super().form_valid(form)
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
def form_invalid(self, form):
|
42
|
+
|
43
|
+
messages.error(self.request, '図面情報の更新に失敗しました。')
|
44
|
+
|
45
|
+
return super().form_invalid(form)
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
```test_view.py
|
54
|
+
|
55
|
+
self.assertRedirects(response, reverse_lazy('draw:draw_detail',kwargs={'pk':draw.pk}))
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
エラーメッセージ
|
62
|
+
|
63
|
+
AssertionError: 200 != 302 : Response didn't redirect as expected: Response code was 200 (expected 302)
|