Commit 68adce0fd6cdac9078c6fdcfce63c18cd6282832
1 parent
1b3a4c82
Exists in
master
and in
5 other branches
[Issue #99]
Showing
1 changed file
with
93 additions
and
14 deletions
Show diff stats
forum/tests/test_view_forum.py
... | ... | @@ -10,7 +10,6 @@ from forum.models import Forum, Post, PostAnswer |
10 | 10 | class ForumViewTestCase (TestCase): |
11 | 11 | |
12 | 12 | def setUp(self): |
13 | - self.client = Client() | |
14 | 13 | |
15 | 14 | self.user = User.objects.create_user( |
16 | 15 | username = 'test', |
... | ... | @@ -21,6 +20,26 @@ class ForumViewTestCase (TestCase): |
21 | 20 | ) |
22 | 21 | assign_role(self.user, 'system_admin') |
23 | 22 | |
23 | + self.user_professor = User.objects.create_user( | |
24 | + username = 'professor', | |
25 | + email = 'professor@amadeus.com', | |
26 | + is_staff = False, | |
27 | + is_active = True, | |
28 | + password = 'testing', | |
29 | + type_profile = 1 | |
30 | + ) | |
31 | + assign_role(self.user_professor, 'professor') | |
32 | + | |
33 | + self.user_student = User.objects.create_user( | |
34 | + username = 'student', | |
35 | + email = 'student@amadeus.com', | |
36 | + is_staff = False, | |
37 | + is_active = True, | |
38 | + password = 'testing', | |
39 | + type_profile = 2 | |
40 | + ) | |
41 | + assign_role(self.user_student, 'student') | |
42 | + | |
24 | 43 | self.category = CourseCategory.objects.create( |
25 | 44 | name = 'Category test', |
26 | 45 | slug = 'category_test' |
... | ... | @@ -87,10 +106,18 @@ class ForumViewTestCase (TestCase): |
87 | 106 | ) |
88 | 107 | self.answer.save() |
89 | 108 | |
90 | - | |
109 | + self.client = Client() | |
91 | 110 | self.client.login(username='test', password='testing') |
92 | - self.index_url = reverse('course:forum:view', kwargs={'slug':self.forum.slug}) | |
93 | - self.create_url = reverse('course:forum:create') | |
111 | + | |
112 | + self.client_professor = Client() | |
113 | + self.client_professor.login (username='professor', password='testing') | |
114 | + | |
115 | + self.client_student = Client() | |
116 | + self.client_student.login (username='student', password='testing') | |
117 | + | |
118 | + | |
119 | + | |
120 | + | |
94 | 121 | self.update_url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) |
95 | 122 | |
96 | 123 | self.createPost_url = reverse('course:forum:create_post') |
... | ... | @@ -99,42 +126,94 @@ class ForumViewTestCase (TestCase): |
99 | 126 | ######################### ForumDetailView ######################### |
100 | 127 | |
101 | 128 | def test_ForumDetail_view_ok (self): |
102 | - response = self.client.get(self.index_url) | |
129 | + url = reverse('course:forum:view', kwargs={'slug':self.forum.slug}) | |
130 | + | |
131 | + response = self.client.get(url) | |
132 | + self.assertEquals(response.status_code, 200) | |
133 | + | |
134 | + response = self.client_professor.get(url) | |
135 | + self.assertEquals(response.status_code, 200) | |
136 | + | |
137 | + response = self.client_student.get(url) | |
103 | 138 | self.assertEquals(response.status_code, 200) |
104 | - self.assertTemplateUsed(response, 'forum/forum_view.html') | |
105 | 139 | |
106 | 140 | def test_ForumDetail_context(self): |
107 | - response = self.client.get(self.index_url) | |
141 | + url = reverse('course:forum:view', kwargs={'slug':self.forum.slug}) | |
142 | + | |
143 | + response = self.client.get(url) | |
144 | + self.assertTrue('forum' in response.context) | |
145 | + | |
146 | + response = self.client_professor.get(url) | |
147 | + self.assertTrue('forum' in response.context) | |
148 | + | |
149 | + response = self.client_student.get(url) | |
108 | 150 | self.assertTrue('forum' in response.context) |
109 | 151 | |
152 | + | |
110 | 153 | ######################### CreateForumView ######################### |
111 | 154 | |
112 | 155 | def test_CreateForum_view_ok (self): |
113 | - response = self.client.get(self.create_url) | |
156 | + url = reverse('course:forum:create') | |
157 | + | |
158 | + response = self.client.get(url) | |
114 | 159 | self.assertEquals(response.status_code, 200) |
115 | - self.assertTemplateUsed(response, 'forum/forum_form.html') | |
116 | 160 | |
117 | - def test_CreateForum_context(self): | |
118 | - response = self.client.get(self.create_url) | |
161 | + response = self.client_professor.get(url) | |
162 | + self.assertEquals(response.status_code, 200) | |
163 | + | |
164 | + response = self.client_student.get(url) | |
165 | + self.assertEquals(response.status_code, 200) | |
166 | + | |
167 | + def test_CreateForum_context(self): | |
168 | + url = reverse('course:forum:create') | |
169 | + | |
170 | + response = self.client.get(url) | |
171 | + self.assertTrue('form' in response.context) | |
172 | + | |
173 | + response = self.client_professor.get(url) | |
174 | + self.assertTrue('form' in response.context) | |
175 | + | |
176 | + response = self.client_student.get(url) | |
119 | 177 | self.assertTrue('form' in response.context) |
120 | 178 | |
121 | 179 | def test_CreateForum_form_error (self): |
180 | + url = reverse('course:forum:create') | |
122 | 181 | data = {'name':'', 'limit_date': '', 'description':'', 'topic':''} |
123 | - response = self.client.post(self.create_url, data) | |
182 | + list_forum = Forum.objects.all().count() | |
183 | + | |
184 | + response = self.client.post(url, data) | |
185 | + self.assertEquals (response.status_code, 400) | |
186 | + self.assertEquals(list_forum, Forum.objects.all().count()) | |
187 | + | |
188 | + response = self.client_professor.post(url, data) | |
124 | 189 | self.assertEquals (response.status_code, 400) |
190 | + self.assertEquals(list_forum, Forum.objects.all().count()) | |
191 | + | |
192 | + response = self.client_student.post(url, data) | |
193 | + self.assertEquals (response.status_code, 400) | |
194 | + self.assertEquals(list_forum, Forum.objects.all().count()) | |
125 | 195 | |
126 | 196 | def test_CreateForum_form_ok (self): |
197 | + url = reverse('course:forum:create') | |
127 | 198 | data = { |
128 | 199 | 'name':'Forum Test2', |
129 | 200 | 'limit_date': '2017-10-05', |
130 | 201 | 'description':'Test', |
131 | 202 | 'topic':str(self.topic.id) |
132 | 203 | } |
204 | + list_forum = Forum.objects.all().count() | |
133 | 205 | |
134 | - response = self.client.post(self.create_url, data) | |
206 | + response = self.client.post(url, data) | |
135 | 207 | self.assertEquals (response.status_code, 302) |
208 | + self.assertEquals(list_forum+1, Forum.objects.all().count()) | |
136 | 209 | |
137 | - forum = Forum.objects.get(name='Forum Test2') | |
210 | + response = self.client_professor.post(url, data) | |
211 | + self.assertEquals (response.status_code, 302) | |
212 | + self.assertEquals(list_forum+2, Forum.objects.all().count()) | |
213 | + | |
214 | + response = self.client_student.post(url, data) | |
215 | + self.assertEquals (response.status_code, 302) | |
216 | + self.assertEquals(list_forum+3, Forum.objects.all().count()) | |
138 | 217 | |
139 | 218 | ######################### UpdateForumView ######################### |
140 | 219 | ... | ... |