Commit 81b96087513980aad028039caf0d0bb7fd54dfb2

Authored by filipecmedeiros
1 parent a9fde23f

Unit test: update forum [Issue #103]

Showing 1 changed file with 47 additions and 74 deletions   Show diff stats
forum/tests/test_view_forum.py
@@ -7,7 +7,7 @@ from users.models import User @@ -7,7 +7,7 @@ from users.models import User
7 from courses.models import CourseCategory, Course, Subject, Topic 7 from courses.models import CourseCategory, Course, Subject, Topic
8 from forum.models import Forum 8 from forum.models import Forum
9 9
10 -class ForumDetailViewTestCase (TestCase): 10 +class ForumViewTestCase (TestCase):
11 11
12 def setUp(self): 12 def setUp(self):
13 self.client = Client() 13 self.client = Client()
@@ -69,105 +69,78 @@ class ForumDetailViewTestCase (TestCase): @@ -69,105 +69,78 @@ class ForumDetailViewTestCase (TestCase):
69 ) 69 )
70 self.forum.save() 70 self.forum.save()
71 71
72 - self.url = reverse('course:forum:view', kwargs={'slug':self.forum.slug})  
73 -  
74 - def test_view_ok (self): 72 +
75 self.client.login(username='test', password='testing') 73 self.client.login(username='test', password='testing')
  74 + self.index_url = reverse('course:forum:view', kwargs={'slug':self.forum.slug})
  75 + self.create_url = reverse('course:forum:create')
  76 + self.update_url = reverse('course:forum:update', kwargs={'pk':self.forum.pk})
  77 +
  78 +######################### ForumDetailView #########################
76 79
77 - response = self.client.get(self.url) 80 + def test_ForumDetail_view_ok (self):
  81 + response = self.client.get(self.index_url)
78 self.assertEquals(response.status_code, 200) 82 self.assertEquals(response.status_code, 200)
79 self.assertTemplateUsed(response, 'forum/forum_view.html') 83 self.assertTemplateUsed(response, 'forum/forum_view.html')
80 84
81 - def test_context(self):  
82 - self.client.login(username='test', password='testing')  
83 -  
84 - response = self.client.get(self.url) 85 + def test_ForumDetail_context(self):
  86 + response = self.client.get(self.index_url)
85 self.assertTrue('forum' in response.context) 87 self.assertTrue('forum' in response.context)
86 88
87 -class CreateForumViewTestCase (TestCase):  
88 -  
89 - def setUp(self):  
90 - self.client = Client()  
91 -  
92 - self.user = User.objects.create_user(  
93 - username = 'test',  
94 - email = 'testing@amadeus.com',  
95 - is_staff = True,  
96 - is_active = True,  
97 - password = 'testing'  
98 - )  
99 - assign_role(self.user, 'system_admin') 89 +######################### CreateForumView #########################
100 90
101 - self.category = CourseCategory.objects.create(  
102 - name = 'Category test',  
103 - slug = 'category_test'  
104 - )  
105 - self.category.save() 91 + def test_CreateForum_view_ok (self):
  92 + response = self.client.get(self.create_url)
  93 + self.assertEquals(response.status_code, 200)
  94 + self.assertTemplateUsed(response, 'forum/forum_form.html')
  95 +
  96 + def test_CreateForum_context(self):
  97 + response = self.client.get(self.create_url)
  98 + self.assertTrue('form' in response.context)
106 99
107 - self.course = Course.objects.create(  
108 - name = 'Course Test',  
109 - slug = 'course_test',  
110 - max_students = 50,  
111 - init_register_date = '2016-08-26',  
112 - end_register_date = '2016-10-01',  
113 - init_date = '2016-10-05',  
114 - end_date = '2017-10-05',  
115 - category = self.category  
116 - )  
117 - self.course.save() 100 + def test_CreateForum_form_error (self):
  101 + data = {'name':'', 'limit_date': '', 'description':'', 'topic':''}
  102 + response = self.client.post(self.create_url, data)
  103 + self.assertEquals (response.status_code, 400)
118 104
119 - self.subject = Subject.objects.create(  
120 - name = 'Subject Test',  
121 - slug='subject-test',  
122 - description = "description of the subject test",  
123 - visible = True,  
124 - course = self.course,  
125 - init_date = '2016-10-05',  
126 - end_date = '2017-10-05',  
127 - )  
128 - self.subject.save() 105 + def test_CreateForum_form_ok (self):
  106 + data = {
  107 + 'name':'Forum Test2',
  108 + 'limit_date': '2017-10-05',
  109 + 'description':'Test',
  110 + 'topic':str(self.topic.id)
  111 + }
129 112
130 - self.topic = Topic.objects.create(  
131 - name = 'Topic Test',  
132 - description = "description of the topic test",  
133 - subject = self.subject,  
134 - owner = self.user,  
135 - )  
136 - self.topic.save() 113 + response = self.client.post(self.create_url, data)
  114 + self.assertEquals (response.status_code, 302)
137 115
138 - self.url = reverse('course:forum:create') 116 + forum = Forum.objects.get(name='Forum Test2')
139 117
140 - def test_view_ok (self):  
141 - self.client.login(username='test', password='testing') 118 +######################### UpdateForumView #########################
142 119
143 - response = self.client.get(self.url) 120 + def test_UpdateForum_view_ok (self):
  121 + response = self.client.get(self.update_url)
144 self.assertEquals(response.status_code, 200) 122 self.assertEquals(response.status_code, 200)
145 self.assertTemplateUsed(response, 'forum/forum_form.html') 123 self.assertTemplateUsed(response, 'forum/forum_form.html')
146 -  
147 - def test_context(self):  
148 - self.client.login(username='test', password='testing')  
149 -  
150 - response = self.client.get(self.url) 124 +
  125 + def test_UpdateForum_context(self):
  126 + response = self.client.get(self.update_url)
151 self.assertTrue('form' in response.context) 127 self.assertTrue('form' in response.context)
152 128
153 - def test_form_error (self):  
154 - self.client.login(username='test', password='testing')  
155 - data = {'name':'', 'limit_date': '', 'description':'', 'topic':''} 129 + def test_UpdateForum_form_error (self):
  130 + data = {'name':'', 'limit_date': '', 'description':''}
156 131
157 - response = self.client.post(self.url, data) 132 + response = self.client.post(self.update_url, data)
158 self.assertEquals (response.status_code, 400) 133 self.assertEquals (response.status_code, 400)
159 134
160 - def test_form_ok (self):  
161 - self.client.login(username='test', password='testing') 135 + def test_UpdateForum_form_ok (self):
162 data = { 136 data = {
163 - 'name':'Forum Teste', 137 + 'name':'Forum Updated',
164 'limit_date': '2017-10-05', 138 'limit_date': '2017-10-05',
165 'description':'Test', 139 'description':'Test',
166 'topic':str(self.topic.id) 140 'topic':str(self.topic.id)
167 } 141 }
168 142
169 - response = self.client.post(self.url, data) 143 + response = self.client.post(self.update_url, data)
170 self.assertEquals (response.status_code, 302) 144 self.assertEquals (response.status_code, 302)
171 145
172 - forum = Forum.objects.get(name='Forum Teste')  
173 -  
174 \ No newline at end of file 146 \ No newline at end of file
  147 + forum = Forum.objects.get(name='Forum Updated')
175 \ No newline at end of file 148 \ No newline at end of file