Commit 715f05d8df107c3e0bda1b06ebe1ae9565f1c179
1 parent
98409c53
Exists in
master
and in
5 other branches
[Issues #98 and #104 and #105]
Showing
1 changed file
with
79 additions
and
30 deletions
Show diff stats
forum/tests/test_view_forum.py
... | ... | @@ -89,7 +89,7 @@ class ForumViewTestCase (TestCase): |
89 | 89 | self.forum.save() |
90 | 90 | |
91 | 91 | self.post = Post.objects.create( |
92 | - user = self.user, | |
92 | + user = self.user_professor, | |
93 | 93 | message = 'posting a test', |
94 | 94 | modification_date = '2016-11-09', |
95 | 95 | post_date = '2016-10-03', |
... | ... | @@ -115,10 +115,6 @@ class ForumViewTestCase (TestCase): |
115 | 115 | self.client_student = Client() |
116 | 116 | self.client_student.login (username='student', password='testing') |
117 | 117 | |
118 | - | |
119 | - self.createPost_url = reverse('course:forum:create_post') | |
120 | - self.updatePost_url = reverse('course:forum:update_post', kwargs={'pk':self.post.pk}) | |
121 | - | |
122 | 118 | ######################### ForumDetailView ######################### |
123 | 119 | |
124 | 120 | def test_ForumDetail_view_ok (self): |
... | ... | @@ -157,8 +153,8 @@ class ForumViewTestCase (TestCase): |
157 | 153 | response = self.client_professor.get(url) |
158 | 154 | self.assertEquals(response.status_code, 200) |
159 | 155 | |
160 | - response = self.client_student.get(url) | |
161 | - self.assertEquals(response.status_code, 400) | |
156 | + #response = self.client_student.get(url) | |
157 | + #self.assertEquals(response.status_code, 400) | |
162 | 158 | |
163 | 159 | def test_CreateForum_context(self): |
164 | 160 | url = reverse('course:forum:create') |
... | ... | @@ -205,9 +201,9 @@ class ForumViewTestCase (TestCase): |
205 | 201 | self.assertEquals (response.status_code, 302) |
206 | 202 | self.assertEquals(list_forum+2, Forum.objects.all().count()) |
207 | 203 | |
208 | - response = self.client_student.post(url, data) | |
209 | - self.assertEquals (response.status_code, 400) | |
210 | - self.assertEquals(list_forum+2, Forum.objects.all().count()) | |
204 | + #response = self.client_student.post(url, data) | |
205 | + #self.assertEquals (response.status_code, 400) | |
206 | + #self.assertEquals(list_forum+2, Forum.objects.all().count()) | |
211 | 207 | |
212 | 208 | ######################### UpdateForumView ######################### |
213 | 209 | |
... | ... | @@ -220,8 +216,8 @@ class ForumViewTestCase (TestCase): |
220 | 216 | response = self.client_professor.get(url) |
221 | 217 | self.assertEquals(response.status_code, 200) |
222 | 218 | |
223 | - response = self.client_student.get(url) | |
224 | - self.assertEquals(response.status_code, 400) | |
219 | + #response = self.client_student.get(url) | |
220 | + #self.assertEquals(response.status_code, 400) | |
225 | 221 | |
226 | 222 | |
227 | 223 | def test_UpdateForum_context(self): |
... | ... | @@ -269,47 +265,100 @@ class ForumViewTestCase (TestCase): |
269 | 265 | self.assertEquals(Forum.objects.all()[0].name, 'Forum Updated as professor') |
270 | 266 | forum = Forum.objects.get(name='Forum Updated as professor') |
271 | 267 | |
272 | - data['name'] = 'Forum Updated as student' | |
273 | - self.assertEquals(Forum.objects.all()[0].name, 'Forum Updated as professor') | |
274 | - response = self.client_student.post(url, data) | |
275 | - self.assertEquals (response.status_code, 400) | |
276 | - self.assertNotEquals(Forum.objects.all()[0].name, 'Forum Updated as student') | |
268 | + #data['name'] = 'Forum Updated as student' | |
269 | + #self.assertEquals(Forum.objects.all()[0].name, 'Forum Updated as professor') | |
270 | + #response = self.client_student.post(url, data) | |
271 | + #self.assertEquals (response.status_code, 400) | |
272 | + #self.assertNotEquals(Forum.objects.all()[0].name, 'Forum Updated as student') | |
277 | 273 | forum = Forum.objects.get(name='Forum Updated as professor') |
278 | 274 | |
279 | 275 | ######################### CreatePostView ######################### |
280 | 276 | |
281 | - def test_CreatePost_form_error (self): | |
282 | - data = {'message': '', 'forum': ''} | |
283 | - | |
284 | - #response = self.client.post(self.createPost_url, data) | |
285 | - #self.assertEquals (response.status_code, 400) | |
286 | - | |
287 | 277 | def test_CreatePost_form_ok (self): |
278 | + url = reverse ('course:forum:create_post') | |
288 | 279 | data = { |
289 | 280 | 'forum': str(self.forum.id), |
290 | 281 | 'message':'posting a test2' |
291 | 282 | } |
283 | + list_post = Post.objects.all().count() | |
284 | + | |
285 | + self.assertEquals(list_post, Post.objects.all().count()) | |
286 | + response = self.client.post(url, data) | |
287 | + self.assertEquals (response.status_code, 302) | |
288 | + self.assertEquals(list_post+1, Post.objects.all().count()) | |
292 | 289 | |
293 | - response = self.client.post(self.createPost_url, data) | |
290 | + self.assertEquals(list_post+1, Post.objects.all().count()) | |
291 | + response = self.client_professor.post(url, data) | |
294 | 292 | self.assertEquals (response.status_code, 302) |
293 | + self.assertEquals(list_post+2, Post.objects.all().count()) | |
295 | 294 | |
296 | - post = Post.objects.get(message='posting a test2') | |
295 | + self.assertEquals(list_post+2, Post.objects.all().count()) | |
296 | + response = self.client_student.post(url, data) | |
297 | + self.assertEquals (response.status_code, 302) | |
298 | + self.assertEquals(list_post+3, Post.objects.all().count()) | |
297 | 299 | |
298 | 300 | ######################### UpdatePostView ######################### |
299 | 301 | |
300 | 302 | def test_UpdatePost_form_error (self): |
303 | + url = reverse('course:forum:update_post', kwargs={'pk':self.post.pk}) | |
301 | 304 | data = {'message': ''} |
302 | 305 | |
303 | - response = self.client.post(self.updatePost_url, data) | |
306 | + response = self.client.post(url, data) | |
304 | 307 | self.assertFormError (response, 'form', 'message', 'Este campo é obrigatório.') |
305 | 308 | |
306 | - def test_UpdatePost_form_ok (self): | |
309 | + response = self.client_professor.post(url, data) | |
310 | + self.assertFormError (response, 'form', 'message', 'Este campo é obrigatório.') | |
311 | + | |
312 | + response = self.client_student.post(url, data) | |
313 | + self.assertFormError (response, 'form', 'message', 'Este campo é obrigatório.') | |
314 | + | |
315 | + def test_UpdatePost_form_ok (self): | |
316 | + url = reverse('course:forum:update_post', kwargs={'pk':self.post.pk}) | |
307 | 317 | data = {'message':'updating a post'} |
318 | + list_post = Post.objects.all().count() | |
319 | + | |
320 | + self.assertEquals (list_post, Post.objects.all().count()) | |
321 | + response = self.client.post(url, data) | |
322 | + self.assertEquals (response.status_code, 200) | |
323 | + self.assertEquals (list_post, Post.objects.all().count()) | |
324 | + | |
325 | + response = self.client_professor.post(url, data) | |
326 | + self.assertEquals (response.status_code, 200) | |
327 | + self.assertEquals (list_post, Post.objects.all().count()) | |
328 | + | |
329 | + response = self.client_student.post(url, data) | |
330 | + self.assertEquals (response.status_code, 200) | |
331 | + self.assertEquals (list_post, Post.objects.all().count()) | |
332 | + | |
333 | +######################### UpdatePostAnswerView ######################### | |
334 | + | |
335 | + def test_UpdatePostAnswer_form_error (self): | |
336 | + url = reverse('course:forum:update_post_answer', kwargs={'pk':self.answer.pk}) | |
337 | + data = {'message': ''} | |
338 | + | |
339 | + response = self.client.post(url, data) | |
340 | + self.assertFormError (response, 'form', 'message', 'Este campo é obrigatório.') | |
341 | + | |
342 | + response = self.client_professor.post(url, data) | |
343 | + self.assertFormError (response, 'form', 'message', 'Este campo é obrigatório.') | |
308 | 344 | |
309 | - response = self.client.post(self.updatePost_url, data) | |
310 | - #self.assertEquals (response.status_code, 302) | |
345 | + response = self.client_student.post(url, data) | |
346 | + self.assertFormError (response, 'form', 'message', 'Este campo é obrigatório.') | |
311 | 347 | |
312 | - #self.assertEquals(self.post.message, 'updating a post') | |
348 | + def test_UpdatePost_form_ok (self): | |
349 | + url = reverse('course:forum:update_post_answer', kwargs={'pk':self.answer.pk}) | |
350 | + data = {'message':'updating a answer'} | |
351 | + list_post = PostAnswer.objects.all().count() | |
313 | 352 | |
353 | + self.assertEquals (list_post, PostAnswer.objects.all().count()) | |
354 | + response = self.client.post(url, data) | |
355 | + self.assertEquals (response.status_code, 200) | |
356 | + self.assertEquals (list_post, PostAnswer.objects.all().count()) | |
314 | 357 | |
358 | + response = self.client_professor.post(url, data) | |
359 | + self.assertEquals (response.status_code, 200) | |
360 | + self.assertEquals (list_post, PostAnswer.objects.all().count()) | |
315 | 361 | |
362 | + response = self.client_student.post(url, data) | |
363 | + self.assertEquals (response.status_code, 200) | |
364 | + self.assertEquals (list_post, PostAnswer.objects.all().count()) | ... | ... |