Commit 3689d8390e17d5147777784eae2e24b78923508d
1 parent
c7027107
Exists in
master
and in
5 other branches
Teste de criar e editar enquete #79, #112, #113
Showing
4 changed files
with
124 additions
and
4 deletions
Show diff stats
courses/models.py
... | ... | @@ -91,7 +91,7 @@ Activity is something that has a deadline and has to be delivered by the student |
91 | 91 | """ |
92 | 92 | class Activity(Resource): |
93 | 93 | topic = models.ForeignKey(Topic, verbose_name = _('Topic'), related_name='activities') |
94 | - limit_date = models.DateTimeField(_('Deliver Date')) | |
94 | + limit_date = models.DateField(_('Deliver Date')) | |
95 | 95 | students = models.ManyToManyField(User, verbose_name = _('Students'), related_name='activities') |
96 | 96 | all_students = models.BooleanField(_('All Students'), default=False) |
97 | 97 | |
... | ... | @@ -100,7 +100,7 @@ class ActivityFile(models.Model): |
100 | 100 | diet = models.ForeignKey('Activity', related_name='files') |
101 | 101 | name = models.CharField(max_length=100) |
102 | 102 | |
103 | - def __str__(self): | |
103 | + def __str__(self): | |
104 | 104 | return self.name |
105 | 105 | |
106 | 106 | class Meta: | ... | ... |
... | ... | @@ -0,0 +1,118 @@ |
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 poll.models import Poll | |
10 | +from users.models import User | |
11 | + | |
12 | +class PollTestCase(TestCase): | |
13 | + def setUp(self): | |
14 | + self.client = Client() | |
15 | + | |
16 | + self.user_professor = User.objects.create_user( | |
17 | + username = 'professor', | |
18 | + email = 'professor@amadeus.com', | |
19 | + is_staff = False, | |
20 | + is_active = True, | |
21 | + password = 'testing', | |
22 | + type_profile = 1 | |
23 | + ) | |
24 | + assign_role(self.user_professor, 'professor') | |
25 | + | |
26 | + self.user_student = User.objects.create_user( | |
27 | + username = 'student', | |
28 | + email = 'student@amadeus.com', | |
29 | + is_staff = False, | |
30 | + is_active = True, | |
31 | + password = 'testing', | |
32 | + type_profile = 2 | |
33 | + ) | |
34 | + assign_role(self.user_student, 'student') | |
35 | + | |
36 | + self.category = Category( | |
37 | + name = 'Categoria Teste', | |
38 | + ) | |
39 | + self.category.save() | |
40 | + | |
41 | + self.course = Course( | |
42 | + name = 'Curso Teste', | |
43 | + max_students = 50, | |
44 | + objectivies = "", | |
45 | + content = "", | |
46 | + init_register_date = '2016-08-26', | |
47 | + end_register_date = '2016-10-01', | |
48 | + init_date = '2016-10-05', | |
49 | + end_date = '2017-10-05', | |
50 | + category = self.category | |
51 | + ) | |
52 | + self.course.save() | |
53 | + | |
54 | + self.subject = Subject( | |
55 | + name = 'Subject Test', | |
56 | + description = "description of the subject test", | |
57 | + visible = True, | |
58 | + course = self.course, | |
59 | + init_date = '2016-10-05', | |
60 | + end_date = '2017-10-05', | |
61 | + ) | |
62 | + self.subject.save() | |
63 | + | |
64 | + self.subject.professors.add(self.user_professor) | |
65 | + | |
66 | + self.topic = Topic( | |
67 | + name = 'Topic Test', | |
68 | + description = "description of the topic test", | |
69 | + subject = self.subject, | |
70 | + owner = self.user_professor, | |
71 | + visible = True, | |
72 | + ) | |
73 | + self.topic.save() | |
74 | + | |
75 | + self.poll = Poll( | |
76 | + name = 'Poll Test', | |
77 | + limit_date = '2016-10-05', | |
78 | + topic = self.topic, | |
79 | + ) | |
80 | + self.poll.save() | |
81 | + | |
82 | + def test_poll_create(self): | |
83 | + self.client.login(username='professor', password='testing') | |
84 | + poll = self.topic.activities.all().count() | |
85 | + url = reverse('course:poll:create_poll',kwargs={'slug':self.topic.slug}) | |
86 | + data = { | |
87 | + "name": 'create poll test', | |
88 | + "limit_date":'2016-10-06', | |
89 | + "all_students":True, | |
90 | + } | |
91 | + response = self.client.post(url, data) | |
92 | + self.assertEqual(poll + 1, self.topic.activities.all().count()) # create a new poll | |
93 | + self.client.login(username='student', password='testing') | |
94 | + poll = self.topic.activities.all().count() | |
95 | + response = self.client.post(url, data) | |
96 | + self.assertEqual(poll, self.topic.activities.all().count()) # don't create a new poll | |
97 | + | |
98 | + def test_poll_update(self): | |
99 | + self.client.login(username='professor', password='testing') | |
100 | + url = reverse('course:poll:update_poll',kwargs={'slug':self.poll.slug}) | |
101 | + title_poll = 'new poll name' | |
102 | + data = { | |
103 | + "name": title_poll, | |
104 | + "limit_date":'2016-11-06', | |
105 | + "all_students":True, | |
106 | + } | |
107 | + self.assertNotEqual(title_poll, self.topic.activities.all()[self.topic.activities.all().count() - 1].name) # old name | |
108 | + response = self.client.post(url, data) | |
109 | + self.assertEqual(title_poll,self.topic.activities.all()[self.topic.activities.all().count() - 1].name) # new name | |
110 | + poll_student = 'new poll name student' | |
111 | + data = { | |
112 | + "name": poll_student, | |
113 | + "limit_date":'2016-11-06', | |
114 | + "all_students":True, | |
115 | + } | |
116 | + self.assertNotEqual(poll_student, self.topic.activities.all()[self.topic.activities.all().count() - 1].name) # old name | |
117 | + response = self.client.post(url, data) | |
118 | + self.assertEqual(poll_student, self.topic.activities.all()[self.topic.activities.all().count() - 1].name) # new name | ... | ... |
poll/views.py
... | ... | @@ -17,8 +17,9 @@ from core.mixins import NotificationMixin |
17 | 17 | from users.models import User |
18 | 18 | from courses.models import Course, Topic |
19 | 19 | |
20 | -class CreatePoll(LoginRequiredMixin,generic.CreateView): | |
20 | +class CreatePoll(LoginRequiredMixin,HasRoleMixin,generic.CreateView): | |
21 | 21 | |
22 | + allowed_roles = ['professor', 'system_admin'] | |
22 | 23 | login_url = reverse_lazy("core:home") |
23 | 24 | redirect_field_name = 'next' |
24 | 25 | model = Poll |
... | ... | @@ -60,8 +61,9 @@ class CreatePoll(LoginRequiredMixin,generic.CreateView): |
60 | 61 | context['subjects'] = topic.subject.course.subjects.all() |
61 | 62 | return context |
62 | 63 | |
63 | -class UpdatePoll(LoginRequiredMixin,generic.UpdateView): | |
64 | +class UpdatePoll(LoginRequiredMixin,HasRoleMixin,generic.UpdateView): | |
64 | 65 | |
66 | + allowed_roles = ['professor', 'system_admin'] | |
65 | 67 | login_url = reverse_lazy("core:home") |
66 | 68 | redirect_field_name = 'next' |
67 | 69 | model = Poll | ... | ... |