Commit a9fde23f7df7e1765dfd9f9302f92f8015388cd6

Authored by filipecmedeiros
1 parent 4be136dd

Unit test: create a forum [Issue #99]

Showing 1 changed file with 87 additions and 4 deletions   Show diff stats
forum/tests/test_view_forum.py
... ... @@ -4,7 +4,7 @@ from django.core.urlresolvers import reverse
4 4 from rolepermissions.shortcuts import assign_role
5 5  
6 6 from users.models import User
7   -from courses.models import Category, Course, Subject, Topic
  7 +from courses.models import CourseCategory, Course, Subject, Topic
8 8 from forum.models import Forum
9 9  
10 10 class ForumDetailViewTestCase (TestCase):
... ... @@ -21,7 +21,7 @@ class ForumDetailViewTestCase (TestCase):
21 21 )
22 22 assign_role(self.user, 'system_admin')
23 23  
24   - self.category = Category.objects.create(
  24 + self.category = CourseCategory.objects.create(
25 25 name = 'Category test',
26 26 slug = 'category_test'
27 27 )
... ... @@ -80,11 +80,94 @@ class ForumDetailViewTestCase (TestCase):
80 80  
81 81 def test_context(self):
82 82 self.client.login(username='test', password='testing')
  83 +
  84 + response = self.client.get(self.url)
  85 + self.assertTrue('forum' in response.context)
  86 +
  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')
  100 +
  101 + self.category = CourseCategory.objects.create(
  102 + name = 'Category test',
  103 + slug = 'category_test'
  104 + )
  105 + self.category.save()
  106 +
  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()
  118 +
  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()
  129 +
  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()
  137 +
  138 + self.url = reverse('course:forum:create')
  139 +
  140 + def test_view_ok (self):
  141 + self.client.login(username='test', password='testing')
83 142  
84 143 response = self.client.get(self.url)
  144 + self.assertEquals(response.status_code, 200)
  145 + self.assertTemplateUsed(response, 'forum/forum_form.html')
85 146  
  147 + def test_context(self):
  148 + self.client.login(username='test', password='testing')
  149 +
  150 + response = self.client.get(self.url)
86 151 self.assertTrue('form' in response.context)
87   - self.assertTrue('forum' in response.context)
88   - self.assertTrue('title' in response.context)
89 152  
  153 + def test_form_error (self):
  154 + self.client.login(username='test', password='testing')
  155 + data = {'name':'', 'limit_date': '', 'description':'', 'topic':''}
  156 +
  157 + response = self.client.post(self.url, data)
  158 + self.assertEquals (response.status_code, 400)
90 159  
  160 + def test_form_ok (self):
  161 + self.client.login(username='test', password='testing')
  162 + data = {
  163 + 'name':'Forum Teste',
  164 + 'limit_date': '2017-10-05',
  165 + 'description':'Test',
  166 + 'topic':str(self.topic.id)
  167 + }
  168 +
  169 + response = self.client.post(self.url, data)
  170 + self.assertEquals (response.status_code, 302)
  171 +
  172 + forum = Forum.objects.get(name='Forum Teste')
  173 +
91 174 \ No newline at end of file
... ...