Commit 5a4105802ad0cf40264cf1c42498686bcf813e6d
1 parent
68adce0f
Exists in
master
and in
5 other branches
[Issue #103]
Showing
1 changed file
with
46 additions
and
11 deletions
Show diff stats
forum/tests/test_view_forum.py
... | ... | @@ -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 | - | |
120 | - | |
121 | - self.update_url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) | |
122 | 118 | |
123 | 119 | self.createPost_url = reverse('course:forum:create_post') |
124 | 120 | self.updatePost_url = reverse('course:forum:update_post', kwargs={'pk':self.post.pk}) |
... | ... | @@ -218,21 +214,45 @@ class ForumViewTestCase (TestCase): |
218 | 214 | ######################### UpdateForumView ######################### |
219 | 215 | |
220 | 216 | def test_UpdateForum_view_ok (self): |
221 | - response = self.client.get(self.update_url) | |
217 | + url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) | |
218 | + | |
219 | + response = self.client.get(url) | |
220 | + self.assertEquals(response.status_code, 200) | |
221 | + | |
222 | + response = self.client_professor.get(url) | |
223 | + self.assertEquals(response.status_code, 200) | |
224 | + | |
225 | + response = self.client_student.get(url) | |
222 | 226 | self.assertEquals(response.status_code, 200) |
223 | - self.assertTemplateUsed(response, 'forum/forum_form.html') | |
227 | + | |
224 | 228 | |
225 | - def test_UpdateForum_context(self): | |
226 | - response = self.client.get(self.update_url) | |
229 | + def test_UpdateForum_context(self): | |
230 | + url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) | |
231 | + | |
232 | + response = self.client.get(url) | |
233 | + self.assertTrue('form' in response.context) | |
234 | + | |
235 | + response = self.client_professor.get(url) | |
236 | + self.assertTrue('form' in response.context) | |
237 | + | |
238 | + response = self.client_student.get(url) | |
227 | 239 | self.assertTrue('form' in response.context) |
228 | 240 | |
229 | 241 | def test_UpdateForum_form_error (self): |
242 | + url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) | |
230 | 243 | data = {'name':'', 'limit_date': '', 'description':''} |
231 | 244 | |
232 | - response = self.client.post(self.update_url, data) | |
245 | + response = self.client.post(url, data) | |
246 | + self.assertEquals (response.status_code, 400) | |
247 | + | |
248 | + response = self.client_professor.post(url, data) | |
249 | + self.assertEquals (response.status_code, 400) | |
250 | + | |
251 | + response = self.client_student.post(url, data) | |
233 | 252 | self.assertEquals (response.status_code, 400) |
234 | 253 | |
235 | 254 | def test_UpdateForum_form_ok (self): |
255 | + url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) | |
236 | 256 | data = { |
237 | 257 | 'name':'Forum Updated', |
238 | 258 | 'limit_date': '2017-10-05', |
... | ... | @@ -240,11 +260,26 @@ class ForumViewTestCase (TestCase): |
240 | 260 | 'topic':str(self.topic.id) |
241 | 261 | } |
242 | 262 | |
243 | - response = self.client.post(self.update_url, data) | |
263 | + self.assertEquals(Forum.objects.all()[0].name, 'forum test') | |
264 | + response = self.client.post(url, data) | |
244 | 265 | self.assertEquals (response.status_code, 302) |
245 | - | |
266 | + self.assertEquals(Forum.objects.all()[0].name, 'Forum Updated') | |
246 | 267 | forum = Forum.objects.get(name='Forum Updated') |
247 | 268 | |
269 | + data['name'] = 'Forum Updated as professor' | |
270 | + self.assertEquals(Forum.objects.all()[0].name, 'Forum Updated') | |
271 | + response = self.client_professor.post(url, data) | |
272 | + self.assertEquals (response.status_code, 302) | |
273 | + self.assertEquals(Forum.objects.all()[0].name, 'Forum Updated as professor') | |
274 | + forum = Forum.objects.get(name='Forum Updated as professor') | |
275 | + | |
276 | + data['name'] = 'Forum Updated as student' | |
277 | + self.assertEquals(Forum.objects.all()[0].name, 'Forum Updated as professor') | |
278 | + response = self.client_student.post(url, data) | |
279 | + self.assertEquals (response.status_code, 302) | |
280 | + self.assertEquals(Forum.objects.all()[0].name, 'Forum Updated as student') | |
281 | + forum = Forum.objects.get(name='Forum Updated as student') | |
282 | + | |
248 | 283 | ######################### CreatePostView ######################### |
249 | 284 | |
250 | 285 | def test_CreatePost_form_error (self): | ... | ... |