Commit 881afe125378484d4a0915c4a16089bc63514436
1 parent
98d703b0
Exists in
master
and in
5 other branches
Adding unit test on model post [Issue #87]
Showing
4 changed files
with
284 additions
and
80 deletions
Show diff stats
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +# -*- coding: utf-8 -*- | ||
2 | +# Generated by Django 1.10 on 2016-10-03 16:10 | ||
3 | +from __future__ import unicode_literals | ||
4 | + | ||
5 | +from django.db import migrations, models | ||
6 | +import django.db.models.deletion | ||
7 | +import s3direct.fields | ||
8 | + | ||
9 | + | ||
10 | +class Migration(migrations.Migration): | ||
11 | + | ||
12 | + dependencies = [ | ||
13 | + ('courses', '0002_auto_20161001_2117'), | ||
14 | + ] | ||
15 | + | ||
16 | + operations = [ | ||
17 | + migrations.CreateModel( | ||
18 | + name='ActivityFile', | ||
19 | + fields=[ | ||
20 | + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
21 | + ('pdf', s3direct.fields.S3DirectField()), | ||
22 | + ('name', models.CharField(max_length=100)), | ||
23 | + ('diet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='files', to='courses.Activity')), | ||
24 | + ], | ||
25 | + options={ | ||
26 | + 'verbose_name_plural': 'Activitys Files', | ||
27 | + 'verbose_name': 'Activity File', | ||
28 | + }, | ||
29 | + ), | ||
30 | + ] |
@@ -0,0 +1,106 @@ | @@ -0,0 +1,106 @@ | ||
1 | +from django.test import TestCase, Client | ||
2 | +from django.core.urlresolvers import reverse | ||
3 | +from rolepermissions.shortcuts import assign_role | ||
4 | + | ||
5 | +from users.models import User | ||
6 | +from courses.models import Category, Course, Subject, Topic | ||
7 | +from forum.models import Forum | ||
8 | + | ||
9 | +class ForumTestCase (TestCase): | ||
10 | + | ||
11 | + def setUp(self): | ||
12 | + self.user_professor = User.objects.create_user( | ||
13 | + username = 'professor', | ||
14 | + email = 'professor@amadeus.com', | ||
15 | + is_staff = False, | ||
16 | + is_active = True, | ||
17 | + password = 'testing', | ||
18 | + type_profile = 1 | ||
19 | + ) | ||
20 | + assign_role(self.user_professor, 'professor') | ||
21 | + | ||
22 | + self.user_student = User.objects.create_user( | ||
23 | + username = 'student', | ||
24 | + email = 'student@amadeus.com', | ||
25 | + is_staff = False, | ||
26 | + is_active = True, | ||
27 | + password = 'testing', | ||
28 | + type_profile = 2 | ||
29 | + ) | ||
30 | + assign_role(self.user_student, 'student') | ||
31 | + | ||
32 | + self.category = Category.objects.create( | ||
33 | + name = 'Categoria Teste', | ||
34 | + slug = 'categoria_teste' | ||
35 | + ) | ||
36 | + self.category.save() | ||
37 | + | ||
38 | + self.course = Course.objects.create( | ||
39 | + name = 'Curso Teste', | ||
40 | + slug = 'curso_teste', | ||
41 | + max_students = 50, | ||
42 | + init_register_date = '2016-08-26', | ||
43 | + end_register_date = '2016-10-01', | ||
44 | + init_date = '2016-10-05', | ||
45 | + end_date = '2017-10-05', | ||
46 | + category = self.category | ||
47 | + ) | ||
48 | + self.course.save() | ||
49 | + | ||
50 | + self.subject = Subject.objects.create( | ||
51 | + name = 'Subject Test', | ||
52 | + description = "description of the subject test", | ||
53 | + visible = True, | ||
54 | + course = self.course, | ||
55 | + init_date = '2016-10-05', | ||
56 | + end_date = '2017-10-05', | ||
57 | + ) | ||
58 | + self.subject.save() | ||
59 | + self.subject.professors.add(self.user_professor) | ||
60 | + | ||
61 | + self.topic = Topic.objects.create( | ||
62 | + name = 'Topic Test', | ||
63 | + description = "description of the topic test", | ||
64 | + subject = self.subject, | ||
65 | + owner = self.user_professor, | ||
66 | + ) | ||
67 | + self.topic.save() | ||
68 | + | ||
69 | + self.forum = Forum.objects.create( | ||
70 | + topic=self.topic, | ||
71 | + name = 'forum test', | ||
72 | + description = 'description of the forum test', | ||
73 | + create_date = '2016-10-02', | ||
74 | + modification_date = '2016-10-03', | ||
75 | + limit_date = '2017-10-05', | ||
76 | + ) | ||
77 | + self.forum.save() | ||
78 | + | ||
79 | + def test_create_forum (self): | ||
80 | + forum = Forum.objects.create( | ||
81 | + topic=self.topic, | ||
82 | + name = 'forum test2', | ||
83 | + description = 'description of the forum test', | ||
84 | + create_date = '2016-10-02', | ||
85 | + modification_date = '2016-10-03', | ||
86 | + limit_date = '2017-10-05', | ||
87 | + ) | ||
88 | + forum.save() | ||
89 | + | ||
90 | + self.assertEquals(forum, Forum.objects.filter(name='forum test2')[0]) | ||
91 | + | ||
92 | + def test_update_forum(self): | ||
93 | + self.forum.name = 'forum test updated' | ||
94 | + self.forum.save() | ||
95 | + | ||
96 | + self.assertEquals(self.forum, Forum.objects.get(name='forum test updated')) | ||
97 | + | ||
98 | + def test_delete_forum (self): | ||
99 | + forum = Forum.objects.get(name='forum test') | ||
100 | + self.forum.delete() | ||
101 | + | ||
102 | + try: | ||
103 | + forum = Forum.objects.get(name='forum test') | ||
104 | + except: | ||
105 | + pass | ||
106 | + | ||
0 | \ No newline at end of file | 107 | \ No newline at end of file |
@@ -0,0 +1,148 @@ | @@ -0,0 +1,148 @@ | ||
1 | +from django.test import TestCase | ||
2 | +from rolepermissions.shortcuts import assign_role | ||
3 | + | ||
4 | +from users.models import User | ||
5 | +from courses.models import Category, Course, Subject, Topic | ||
6 | +from forum.models import Forum, Post | ||
7 | + | ||
8 | +class PostTestCase (TestCase): | ||
9 | + | ||
10 | + def setUp (self): | ||
11 | + self.user_professor = User.objects.create_user( | ||
12 | + username = 'professor', | ||
13 | + email = 'professor@amadeus.com', | ||
14 | + is_staff = False, | ||
15 | + is_active = True, | ||
16 | + password = 'testing', | ||
17 | + type_profile = 1 | ||
18 | + ) | ||
19 | + assign_role(self.user_professor, 'professor') | ||
20 | + | ||
21 | + self.user_student = User.objects.create_user( | ||
22 | + username = 'student', | ||
23 | + email = 'student@amadeus.com', | ||
24 | + is_staff = False, | ||
25 | + is_active = True, | ||
26 | + password = 'testing', | ||
27 | + type_profile = 2 | ||
28 | + ) | ||
29 | + assign_role(self.user_student, 'student') | ||
30 | + | ||
31 | + self.category = Category.objects.create( | ||
32 | + name = 'Categoria Teste', | ||
33 | + slug = 'categoria_teste' | ||
34 | + ) | ||
35 | + self.category.save() | ||
36 | + | ||
37 | + self.course = Course.objects.create( | ||
38 | + name = 'Curso Teste', | ||
39 | + slug = 'curso_teste', | ||
40 | + max_students = 50, | ||
41 | + init_register_date = '2016-08-26', | ||
42 | + end_register_date = '2016-10-01', | ||
43 | + init_date = '2016-10-05', | ||
44 | + end_date = '2017-10-05', | ||
45 | + category = self.category | ||
46 | + ) | ||
47 | + self.course.save() | ||
48 | + | ||
49 | + self.subject = Subject.objects.create( | ||
50 | + name = 'Subject Test', | ||
51 | + description = "description of the subject test", | ||
52 | + visible = True, | ||
53 | + course = self.course, | ||
54 | + init_date = '2016-10-05', | ||
55 | + end_date = '2017-10-05', | ||
56 | + ) | ||
57 | + self.subject.save() | ||
58 | + self.subject.professors.add(self.user_professor) | ||
59 | + | ||
60 | + self.topic = Topic.objects.create( | ||
61 | + name = 'Topic Test', | ||
62 | + description = "description of the topic test", | ||
63 | + subject = self.subject, | ||
64 | + owner = self.user_professor, | ||
65 | + ) | ||
66 | + self.topic.save() | ||
67 | + | ||
68 | + self.forum = Forum.objects.create( | ||
69 | + topic=self.topic, | ||
70 | + name = 'forum test', | ||
71 | + description = 'description of the forum test', | ||
72 | + create_date = '2016-10-02', | ||
73 | + modification_date = '2016-10-03', | ||
74 | + limit_date = '2017-10-05', | ||
75 | + ) | ||
76 | + self.forum.save() | ||
77 | + | ||
78 | + self.post_professor = Post.objects.create( | ||
79 | + user = self.user_professor, | ||
80 | + message = 'posting a test on forum as professor', | ||
81 | + modification_date = '2016-11-09', | ||
82 | + post_date = '2016-10-03', | ||
83 | + forum = self.forum, | ||
84 | + ) | ||
85 | + self.post_professor.save() | ||
86 | + | ||
87 | + self.post_student = Post.objects.create( | ||
88 | + user = self.user_student, | ||
89 | + message = 'posting a test on forum as student', | ||
90 | + modification_date = '2016-11-09', | ||
91 | + post_date = '2016-10-03', | ||
92 | + forum = self.forum, | ||
93 | + ) | ||
94 | + self.post_student.save() | ||
95 | + | ||
96 | + def test_create_post_professor (self): | ||
97 | + post_professor = Post.objects.create( | ||
98 | + user = self.user_professor, | ||
99 | + message = 'posting', | ||
100 | + modification_date = '2016-11-09', | ||
101 | + post_date = '2016-10-03', | ||
102 | + forum = self.forum, | ||
103 | + ) | ||
104 | + post_professor.save() | ||
105 | + | ||
106 | + self.assertEquals (post_professor, Post.objects.get(user=self.user_professor, message='posting')) | ||
107 | + | ||
108 | + def test_create_post_student (self): | ||
109 | + post_student = Post.objects.create( | ||
110 | + user = self.user_student, | ||
111 | + message = 'posting', | ||
112 | + modification_date = '2016-11-09', | ||
113 | + post_date = '2016-10-03', | ||
114 | + forum = self.forum, | ||
115 | + ) | ||
116 | + post_student.save() | ||
117 | + | ||
118 | + self.assertEquals (post_student, Post.objects.get(user=self.user_student, message='posting')) | ||
119 | + | ||
120 | + def test_update_post_professor (self): | ||
121 | + self.post_professor.message = 'updating a post as professor' | ||
122 | + self.post_professor.save() | ||
123 | + | ||
124 | + self.assertEquals(self.post_professor, Post.objects.all()[1]) | ||
125 | + | ||
126 | + def test_update_post_student (self): | ||
127 | + self.post_student.message = 'updating a post as student' | ||
128 | + self.post_student.save() | ||
129 | + | ||
130 | + self.assertEquals(self.post_student, Post.objects.all()[1]) | ||
131 | + | ||
132 | + def test_delete_post_professor (self): | ||
133 | + post = Post.objects.get(user=self.user_professor, message='posting a test on forum as professor') | ||
134 | + self.post_professor.delete() | ||
135 | + | ||
136 | + try: | ||
137 | + post = Post.objects.get(user=self.user_professor, message='posting a test on forum as professor') | ||
138 | + except: | ||
139 | + pass | ||
140 | + | ||
141 | + def test_delete_post_student (self): | ||
142 | + post = Post.objects.get(user=self.user_student, message='posting a test on forum as student') | ||
143 | + self.post_student.delete() | ||
144 | + | ||
145 | + try: | ||
146 | + post = Post.objects.get(user=self.user_student, message='posting a test on forum as student') | ||
147 | + except: | ||
148 | + pass | ||
0 | \ No newline at end of file | 149 | \ No newline at end of file |
forum/tests/test_models.py
@@ -1,80 +0,0 @@ | @@ -1,80 +0,0 @@ | ||
1 | -from django.test import TestCase, Client | ||
2 | -from django.core.urlresolvers import reverse | ||
3 | -from rolepermissions.shortcuts import assign_role | ||
4 | - | ||
5 | -from users.models import User | ||
6 | -from courses.models import Category, Course, Subject, Topic | ||
7 | -from forum.models import Forum | ||
8 | - | ||
9 | -class ForumTestCase (TestCase): | ||
10 | - | ||
11 | - def setUp(self): | ||
12 | - self.user_professor = User.objects.create_user( | ||
13 | - username = 'professor', | ||
14 | - email = 'professor@amadeus.com', | ||
15 | - is_staff = False, | ||
16 | - is_active = True, | ||
17 | - password = 'testing', | ||
18 | - type_profile = 1 | ||
19 | - ) | ||
20 | - assign_role(self.user_professor, 'professor') | ||
21 | - | ||
22 | - self.user_student = User.objects.create_user( | ||
23 | - username = 'student', | ||
24 | - email = 'student@amadeus.com', | ||
25 | - is_staff = False, | ||
26 | - is_active = True, | ||
27 | - password = 'testing', | ||
28 | - type_profile = 2 | ||
29 | - ) | ||
30 | - assign_role(self.user_student, 'student') | ||
31 | - | ||
32 | - self.category = Category.objects.create( | ||
33 | - name = 'Categoria Teste', | ||
34 | - slug = 'categoria_teste' | ||
35 | - ) | ||
36 | - self.category.save() | ||
37 | - | ||
38 | - self.course = Course.objects.create( | ||
39 | - name = 'Curso Teste', | ||
40 | - slug = 'curso_teste', | ||
41 | - max_students = 50, | ||
42 | - init_register_date = '2016-08-26', | ||
43 | - end_register_date = '2016-10-01', | ||
44 | - init_date = '2016-10-05', | ||
45 | - end_date = '2017-10-05', | ||
46 | - category = self.category | ||
47 | - ) | ||
48 | - self.course.save() | ||
49 | - | ||
50 | - self.subject = Subject.objects.create( | ||
51 | - name = 'Subject Test', | ||
52 | - description = "description of the subject test", | ||
53 | - visible = True, | ||
54 | - course = self.course, | ||
55 | - init_date = '2016-10-05', | ||
56 | - end_date = '2017-10-05', | ||
57 | - ) | ||
58 | - self.subject.save() | ||
59 | - self.subject.professors.add(self.user_professor) | ||
60 | - | ||
61 | - self.topic = Topic.objects.create( | ||
62 | - name = 'Topic Test', | ||
63 | - description = "description of the topic test", | ||
64 | - subject = self.subject, | ||
65 | - owner = self.user_professor, | ||
66 | - ) | ||
67 | - self.topic.save() | ||
68 | - | ||
69 | - def test_create_forum (self): | ||
70 | - forum = Forum.objects.create( | ||
71 | - topic=self.topic, | ||
72 | - name = 'forum test', | ||
73 | - description = 'description of the forum test', | ||
74 | - create_date = '2016-10-02', | ||
75 | - modification_date = '2016-10-03', | ||
76 | - limit_date = '2017-10-05', | ||
77 | - ) | ||
78 | - forum.save() | ||
79 | - | ||
80 | - self.assertEquals(forum, Forum.objects.all()[0]) | ||
81 | \ No newline at end of file | 0 | \ No newline at end of file |