Commit ddf5ac5dcd8a333c110c9dbdb07292240de35c27

Authored by Jailson Dias
1 parent 448aa9ec

tests topics #33

Showing 1 changed file with 106 additions and 0 deletions   Show diff stats
courses/tests/test_topic.py 0 → 100644
... ... @@ -0,0 +1,106 @@
  1 +# coding=utf-8
  2 +
  3 +from django.test import TestCase, Client
  4 +from django.core.urlresolvers import reverse
  5 +
  6 +from rolepermissions.shortcuts import assign_role
  7 +
  8 +from courses.models import Category, Course, Subject, Topic
  9 +from users.models import User
  10 +
  11 +class TopicTestCase(TestCase):
  12 + def setUp(self):
  13 + self.client = Client()
  14 +
  15 + self.user_professor = User.objects.create_user(
  16 + username = 'professor',
  17 + email = 'professor@amadeus.com',
  18 + is_staff = False,
  19 + is_active = True,
  20 + password = 'testing',
  21 + type_profile = 1
  22 + )
  23 + assign_role(self.user_professor, 'professor')
  24 +
  25 + self.user_student = User.objects.create_user(
  26 + username = 'student',
  27 + email = 'student@amadeus.com',
  28 + is_staff = False,
  29 + is_active = True,
  30 + password = 'testing',
  31 + type_profile = 2
  32 + )
  33 + assign_role(self.user_student, 'student')
  34 +
  35 + self.category = Category(
  36 + name = 'Categoria Teste',
  37 + slug = 'categoria_teste'
  38 + )
  39 + self.category.save()
  40 +
  41 + self.course = Course(
  42 + name = 'Curso Teste',
  43 + slug = 'curso_teste',
  44 + max_students = 50,
  45 + init_register_date = '2016-08-26',
  46 + end_register_date = '2016-10-01',
  47 + init_date = '2016-10-05',
  48 + end_date = '2017-10-05',
  49 + category = self.category
  50 + )
  51 + self.course.save()
  52 +
  53 + self.subject = Subject(
  54 + name = 'Subject Test',
  55 + description = "description of the subject test",
  56 + visible = True,
  57 + course = self.course,
  58 + )
  59 + self.subject.save()
  60 + self.subject.professors.add(self.user_professor)
  61 +
  62 + self.topic = Topic(
  63 + name = 'Topic Test',
  64 + description = "description of the topic test",
  65 + subject = self.subject,
  66 + owner = self.user_professor,
  67 + )
  68 + self.topic.save()
  69 +
  70 + def test_topic_create(self):
  71 + self.client.login(username='professor', password='testing')
  72 + topic = self.subject.topics.all().count()
  73 + url = reverse('course:create_topic',kwargs={'slug':self.subject.slug})
  74 + data = {
  75 + "name": 'create topic test',
  76 + "description":'description of the topic test',
  77 + }
  78 + response = self.client.post(url, data)
  79 + self.assertEqual(topic + 1, self.subject.topics.all().count()) # create a new subject
  80 +
  81 + self.client.login(username='student', password='testing')
  82 + topic = self.subject.topics.all().count()
  83 + response = self.client.post(url, data)
  84 + self.assertEqual(topic + 1, self.subject.topics.all().count()) # create a new subject
  85 +
  86 + def test_topic_update(self):
  87 + self.client.login(username='professor', password='testing')
  88 + print (self.subject.topics.all())
  89 + url = reverse('course:update_topic',kwargs={'slug':self.subject.topics.all()[0].slug})
  90 + data = {
  91 + "name": 'new name',
  92 + "description":'description of the subject test',
  93 + 'visible': True,
  94 + }
  95 + self.assertEqual(self.subject.topics.all()[0].name, "Topic Test") # old name
  96 + response = self.client.post(url, data)
  97 + self.assertEqual(self.subject.topics.all()[0].name, 'new name') # new name
  98 +
  99 + data = {
  100 + "name": 'new name 2',
  101 + "description":'description of the subject test',
  102 + 'visible': True,
  103 + }
  104 + self.client.login(username='student', password='testing')
  105 + response = self.client.post(url, data)
  106 + self.assertEqual(self.subject.topics.all()[0].name, 'new name 2') # new name
... ...