Commit f47bcf5dd3542dbd7bb2602a8e88acaea73a2e34
1 parent
dd926ce6
Exists in
master
and in
5 other branches
Adding unit test on model PostAnswer [Issue #87 and #89]
Showing
1 changed file
with
130 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,130 @@ | @@ -0,0 +1,130 @@ | ||
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, PostAnswer | ||
7 | + | ||
8 | +class PostAnswerTestCase (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 | + self.answer = PostAnswer.objects.create( | ||
97 | + user = self.user_student, | ||
98 | + post = self.post_professor, | ||
99 | + message = 'testing a post answer', | ||
100 | + modification_date = '2016-10-05', | ||
101 | + answer_date = '2016-10-04', | ||
102 | + ) | ||
103 | + | ||
104 | + | ||
105 | + def test_create_answer_post (self): | ||
106 | + answer = PostAnswer.objects.create( | ||
107 | + user = self.user_professor, | ||
108 | + post = self.post_student, | ||
109 | + message = 'testing a post answer2', | ||
110 | + modification_date = '2016-10-05', | ||
111 | + answer_date = '2016-10-04', | ||
112 | + ) | ||
113 | + answer.save() | ||
114 | + | ||
115 | + self.assertEquals (answer, PostAnswer.objects.get(user=self.user_professor, post=self.post_student)) | ||
116 | + | ||
117 | + def test_update_answer_post (self): | ||
118 | + self.answer.message = 'updating a answer post' | ||
119 | + self.answer.save() | ||
120 | + | ||
121 | + self.assertEquals(self.answer, PostAnswer.objects.all()[0]) | ||
122 | + | ||
123 | + def test_delete_answer_post (self): | ||
124 | + answer = PostAnswer.objects.get(user=self.user_student, post=self.post_professor) | ||
125 | + self.answer.delete() | ||
126 | + | ||
127 | + try: | ||
128 | + answer = PostAnswer.objects.get(user=self.user_student, post=self.post_professor) | ||
129 | + except: | ||
130 | + pass | ||
0 | \ No newline at end of file | 131 | \ No newline at end of file |