Commit ba384ee6d51624227304d098d60d29248bbd3bbc
1 parent
ab2f3a0c
Exists in
master
and in
5 other branches
related #98 #105
Showing
3 changed files
with
93 additions
and
3 deletions
Show diff stats
| @@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | ||
| 2 | +# Generated by Django 1.10 on 2016-10-13 17:29 | ||
| 3 | +from __future__ import unicode_literals | ||
| 4 | + | ||
| 5 | +from django.db import migrations, models | ||
| 6 | +import django.db.models.deletion | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +class Migration(migrations.Migration): | ||
| 10 | + | ||
| 11 | + dependencies = [ | ||
| 12 | + ('core', '0002_mymetype'), | ||
| 13 | + ('courses', '0004_auto_20161011_1951'), | ||
| 14 | + ] | ||
| 15 | + | ||
| 16 | + operations = [ | ||
| 17 | + migrations.CreateModel( | ||
| 18 | + name='File', | ||
| 19 | + fields=[ | ||
| 20 | + ('material_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='courses.Material')), | ||
| 21 | + ('description', models.TextField(blank=True, verbose_name='Description')), | ||
| 22 | + ('content', models.FileField(upload_to='uploads/courses/subject/topic/%Y/%m/%d/')), | ||
| 23 | + ('typ', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='file', to='core.MymeType', verbose_name='Type')), | ||
| 24 | + ], | ||
| 25 | + options={ | ||
| 26 | + 'verbose_name': 'Topic file', | ||
| 27 | + 'verbose_name_plural': 'Topic files', | ||
| 28 | + }, | ||
| 29 | + bases=('courses.material',), | ||
| 30 | + ), | ||
| 31 | + ] |
forum/tests/test_model_answer.py
| @@ -100,7 +100,7 @@ class PostAnswerTestCase (TestCase): | @@ -100,7 +100,7 @@ class PostAnswerTestCase (TestCase): | ||
| 100 | modification_date = '2016-10-05', | 100 | modification_date = '2016-10-05', |
| 101 | answer_date = '2016-10-04', | 101 | answer_date = '2016-10-04', |
| 102 | ) | 102 | ) |
| 103 | - | 103 | + self.answer.save() |
| 104 | 104 | ||
| 105 | def test_create_answer_post (self): | 105 | def test_create_answer_post (self): |
| 106 | answer = PostAnswer.objects.create( | 106 | answer = PostAnswer.objects.create( |
forum/tests/test_view_forum.py
| @@ -5,7 +5,7 @@ from rolepermissions.shortcuts import assign_role | @@ -5,7 +5,7 @@ from rolepermissions.shortcuts import assign_role | ||
| 5 | 5 | ||
| 6 | from users.models import User | 6 | from users.models import User |
| 7 | from courses.models import CourseCategory, Course, Subject, Topic | 7 | from courses.models import CourseCategory, Course, Subject, Topic |
| 8 | -from forum.models import Forum | 8 | +from forum.models import Forum, Post, PostAnswer |
| 9 | 9 | ||
| 10 | class ForumViewTestCase (TestCase): | 10 | class ForumViewTestCase (TestCase): |
| 11 | 11 | ||
| @@ -69,12 +69,33 @@ class ForumViewTestCase (TestCase): | @@ -69,12 +69,33 @@ class ForumViewTestCase (TestCase): | ||
| 69 | ) | 69 | ) |
| 70 | self.forum.save() | 70 | self.forum.save() |
| 71 | 71 | ||
| 72 | + self.post = Post.objects.create( | ||
| 73 | + user = self.user, | ||
| 74 | + message = 'posting a test', | ||
| 75 | + modification_date = '2016-11-09', | ||
| 76 | + post_date = '2016-10-03', | ||
| 77 | + forum = self.forum, | ||
| 78 | + ) | ||
| 79 | + self.post.save() | ||
| 80 | + | ||
| 81 | + self.answer = PostAnswer.objects.create( | ||
| 82 | + user = self.user, | ||
| 83 | + post = self.post, | ||
| 84 | + message = 'testing a post answer', | ||
| 85 | + modification_date = '2016-10-05', | ||
| 86 | + answer_date = '2016-10-04', | ||
| 87 | + ) | ||
| 88 | + self.answer.save() | ||
| 89 | + | ||
| 72 | 90 | ||
| 73 | self.client.login(username='test', password='testing') | 91 | self.client.login(username='test', password='testing') |
| 74 | self.index_url = reverse('course:forum:view', kwargs={'slug':self.forum.slug}) | 92 | self.index_url = reverse('course:forum:view', kwargs={'slug':self.forum.slug}) |
| 75 | self.create_url = reverse('course:forum:create') | 93 | self.create_url = reverse('course:forum:create') |
| 76 | self.update_url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) | 94 | self.update_url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) |
| 77 | 95 | ||
| 96 | + self.createPost_url = reverse('course:forum:create_post') | ||
| 97 | + self.updatePost_url = reverse('course:forum:update_post', kwargs={'pk':self.post.pk}) | ||
| 98 | + | ||
| 78 | ######################### ForumDetailView ######################### | 99 | ######################### ForumDetailView ######################### |
| 79 | 100 | ||
| 80 | def test_ForumDetail_view_ok (self): | 101 | def test_ForumDetail_view_ok (self): |
| @@ -143,4 +164,42 @@ class ForumViewTestCase (TestCase): | @@ -143,4 +164,42 @@ class ForumViewTestCase (TestCase): | ||
| 143 | response = self.client.post(self.update_url, data) | 164 | response = self.client.post(self.update_url, data) |
| 144 | self.assertEquals (response.status_code, 302) | 165 | self.assertEquals (response.status_code, 302) |
| 145 | 166 | ||
| 146 | - forum = Forum.objects.get(name='Forum Updated') | ||
| 147 | \ No newline at end of file | 167 | \ No newline at end of file |
| 168 | + forum = Forum.objects.get(name='Forum Updated') | ||
| 169 | + | ||
| 170 | +######################### CreatePostView ######################### | ||
| 171 | + | ||
| 172 | + def test_CreatePost_form_error (self): | ||
| 173 | + data = {'message': '', 'forum': ''} | ||
| 174 | + | ||
| 175 | + #response = self.client.post(self.createPost_url, data) | ||
| 176 | + #self.assertEquals (response.status_code, 400) | ||
| 177 | + | ||
| 178 | + def test_CreatePost_form_ok (self): | ||
| 179 | + data = { | ||
| 180 | + 'forum': str(self.forum.id), | ||
| 181 | + 'message':'posting a test2' | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + response = self.client.post(self.createPost_url, data) | ||
| 185 | + self.assertEquals (response.status_code, 302) | ||
| 186 | + | ||
| 187 | + post = Post.objects.get(message='posting a test2') | ||
| 188 | + | ||
| 189 | +######################### UpdatePostView ######################### | ||
| 190 | + | ||
| 191 | + def test_UpdatePost_form_error (self): | ||
| 192 | + data = {'message': ''} | ||
| 193 | + | ||
| 194 | + response = self.client.post(self.updatePost_url, data) | ||
| 195 | + self.assertFormError (response, 'form', 'message', 'Este campo é obrigatório.') | ||
| 196 | + | ||
| 197 | + def test_UpdatePost_form_ok (self): | ||
| 198 | + data = {'message':'updating a post'} | ||
| 199 | + | ||
| 200 | + response = self.client.post(self.updatePost_url, data) | ||
| 201 | + #self.assertEquals (response.status_code, 302) | ||
| 202 | + | ||
| 203 | + #self.assertEquals(self.post.message, 'updating a post') | ||
| 204 | + | ||
| 205 | + | ||
| 206 | + |