Commit d715495dd28b7136071943599ab22d13e72d4474

Authored by filipecmedeiros
1 parent e208cd51

Adding unit test on view ForumDetailView [Issue #87]

amadeus/local_settings.py.example 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +import os
  2 +
  3 +DEBUG = True
  4 +
  5 +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  6 +
  7 +DATABASES = {
  8 + 'default': {
  9 + 'ENGINE': 'django.db.backends.postgresql',
  10 + 'NAME': 'amadeus',
  11 + 'USER': 'amadeus_admin',
  12 + 'PASSWORD': 'amadeus',
  13 + 'HOST': '127.0.0.1',
  14 + 'PORT': '5432',
  15 + }
  16 +}
0 17 \ No newline at end of file
... ...
forum/tests/test_view_forum.py 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +from django.test import TestCase, Client
  2 +
  3 +from django.core.urlresolvers import reverse
  4 +from rolepermissions.shortcuts import assign_role
  5 +
  6 +from users.models import User
  7 +from courses.models import Category, Course, Subject, Topic
  8 +from forum.models import Forum
  9 +
  10 +class ForumDetailViewTestCase (TestCase):
  11 +
  12 + def setUp(self):
  13 + self.client = Client()
  14 +
  15 + self.user = User.objects.create_user(
  16 + username = 'test',
  17 + email = 'testing@amadeus.com',
  18 + is_staff = True,
  19 + is_active = True,
  20 + password = 'testing'
  21 + )
  22 + assign_role(self.user, 'system_admin')
  23 +
  24 + self.category = Category.objects.create(
  25 + name = 'Category test',
  26 + slug = 'category_test'
  27 + )
  28 + self.category.save()
  29 +
  30 + self.course = Course.objects.create(
  31 + name = 'Course Test',
  32 + slug = 'course_test',
  33 + max_students = 50,
  34 + init_register_date = '2016-08-26',
  35 + end_register_date = '2016-10-01',
  36 + init_date = '2016-10-05',
  37 + end_date = '2017-10-05',
  38 + category = self.category
  39 + )
  40 + self.course.save()
  41 +
  42 + self.subject = Subject.objects.create(
  43 + name = 'Subject Test',
  44 + slug='subject-test',
  45 + description = "description of the subject test",
  46 + visible = True,
  47 + course = self.course,
  48 + init_date = '2016-10-05',
  49 + end_date = '2017-10-05',
  50 + )
  51 + self.subject.save()
  52 +
  53 + self.topic = Topic.objects.create(
  54 + name = 'Topic Test',
  55 + description = "description of the topic test",
  56 + subject = self.subject,
  57 + owner = self.user,
  58 + )
  59 + self.topic.save()
  60 +
  61 + self.forum = Forum.objects.create(
  62 + topic=self.topic,
  63 + name = 'forum test',
  64 + slug='forum-test',
  65 + description = 'description of the forum test',
  66 + create_date = '2016-10-02',
  67 + modification_date = '2016-10-03',
  68 + limit_date = '2017-10-05',
  69 + )
  70 + self.forum.save()
  71 +
  72 + self.url = reverse('course:forum:view', kwargs={'slug':self.forum.slug})
  73 +
  74 + def test_view_ok (self):
  75 + self.client.login(username='test', password='testing')
  76 +
  77 + response = self.client.get(self.url)
  78 + self.assertEquals(response.status_code, 200)
  79 + self.assertTemplateUsed(response, 'forum/forum_view.html')
  80 +
  81 + def test_context(self):
  82 + self.client.login(username='test', password='testing')
  83 +
  84 + response = self.client.get(self.url)
  85 +
  86 + self.assertTrue('form' in response.context)
  87 + self.assertTrue('forum' in response.context)
  88 + self.assertTrue('title' in response.context)
  89 +
  90 +
... ...