Commit a8fe83227f0b15db992ed27c099f902c006f1550
Exists in
master
and in
5 other branches
Merge branch 'master' of https://github.com/amadeusproject/amadeuslms
Showing
5 changed files
with
262 additions
and
29 deletions
Show diff stats
courses/templates/subject/index.html
@@ -21,7 +21,11 @@ | @@ -21,7 +21,11 @@ | ||
21 | 21 | ||
22 | <div class="panel-body"> | 22 | <div class="panel-body"> |
23 | {% for subject in subjects %} | 23 | {% for subject in subjects %} |
24 | - <a href="{% url 'course:view_subject' subject.slug%}" class="btn btn-default">{{subject}}</a> | 24 | + <div class="row"> |
25 | + <div class="col-md-12 col-sm-12"> | ||
26 | + <a href="{% url 'course:view_subject' subject.slug%}" class="btn btn-default text-left">{{subject}}</a> | ||
27 | + </div> | ||
28 | + </div> | ||
25 | {% endfor %} | 29 | {% endfor %} |
26 | </div> | 30 | </div> |
27 | </div> | 31 | </div> |
@@ -36,7 +40,7 @@ | @@ -36,7 +40,7 @@ | ||
36 | <div class="panel-heading"> | 40 | <div class="panel-heading"> |
37 | <div class="row"> | 41 | <div class="row"> |
38 | <div class="col-md-7 col-sm-7"> | 42 | <div class="col-md-7 col-sm-7"> |
39 | - <h3>{% trans "Presentation Subject" %}</h3> | 43 | + <h3>{{subject}}</h3> |
40 | </div> | 44 | </div> |
41 | <div class="col-md-2 col-sm-2"> | 45 | <div class="col-md-2 col-sm-2"> |
42 | {% if user|has_role:'system_admin' or user in subject.professors %} | 46 | {% if user|has_role:'system_admin' or user in subject.professors %} |
@@ -0,0 +1,122 @@ | @@ -0,0 +1,122 @@ | ||
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 | ||
9 | +from users.models import User | ||
10 | + | ||
11 | +class SubjectTestCase(TestCase): | ||
12 | + | ||
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 | + slug = 'categoria_teste' | ||
39 | + ) | ||
40 | + self.category.save() | ||
41 | + | ||
42 | + self.course = Course( | ||
43 | + name = 'Curso Teste', | ||
44 | + slug = 'curso_teste', | ||
45 | + max_students = 50, | ||
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 | + ) | ||
60 | + self.subject.save() | ||
61 | + self.subject.professors.add(self.user_professor) | ||
62 | + | ||
63 | + def test_subject_view(self): | ||
64 | + self.client.login(username='professor', password='testing') | ||
65 | + url = reverse('course:view_subject', kwargs={'slug':self.subject.slug}) | ||
66 | + response = self.client.get(url) | ||
67 | + self.assertEquals(response.status_code, 200) | ||
68 | + self.assertTemplateUsed(response, 'subject/index.html') | ||
69 | + | ||
70 | + self.client.login(username='student', password='testing') | ||
71 | + url = reverse('course:view_subject',kwargs={'slug':self.subject.slug}) | ||
72 | + response = self.client.get(url) | ||
73 | + self.assertEquals(response.status_code, 200) | ||
74 | + self.assertTemplateUsed(response, 'subject/index.html') | ||
75 | + | ||
76 | + def test_subject_create(self): | ||
77 | + self.client.login(username='professor', password='testing') | ||
78 | + subjects = self.course.subjects.all().count() | ||
79 | + url = reverse('course:create_subject',kwargs={'slug':self.course.slug}) | ||
80 | + data = { | ||
81 | + "name": 'create subject test', | ||
82 | + "description":'description of the subject test', | ||
83 | + 'visible': True, | ||
84 | + } | ||
85 | + response = self.client.post(url, data) | ||
86 | + self.assertEqual(subjects + 1, self.course.subjects.all().count()) # create a new subject | ||
87 | + | ||
88 | + self.client.login(username='student', password='testing') | ||
89 | + subjects = self.course.subjects.all().count() | ||
90 | + response = self.client.post(url, data) | ||
91 | + self.assertEqual(response.status_code, 403) # access denied | ||
92 | + self.assertEqual(subjects, self.course.subjects.all().count()) # don't create a new subject | ||
93 | + | ||
94 | + def test_subject_update(self): | ||
95 | + self.client.login(username='professor', password='testing') | ||
96 | + url = reverse('course:update_subject',kwargs={'slug':self.course.subjects.all()[0].slug}) | ||
97 | + data = { | ||
98 | + "name": 'new name', | ||
99 | + "description":'description of the subject test', | ||
100 | + 'visible': True, | ||
101 | + } | ||
102 | + self.assertEqual(self.course.subjects.all()[0].name, "Subject Test") # old name | ||
103 | + response = self.client.post(url, data) | ||
104 | + self.assertEqual(self.course.subjects.all()[0].name, 'new name') # new name | ||
105 | + | ||
106 | + self.client.login(username='student', password='testing') | ||
107 | + response = self.client.post(url, data) | ||
108 | + self.assertEqual(response.status_code, 403) # access denied | ||
109 | + self.assertEqual(self.subject.name, "Subject Test") # name don't change | ||
110 | + | ||
111 | + def test_subject_delete(self): | ||
112 | + self.client.login(username='professor', password='testing') | ||
113 | + subjects = self.course.subjects.all().count() | ||
114 | + url = reverse('course:delete_subject',kwargs={'slug':self.course.subjects.all()[0].slug}) | ||
115 | + self.assertEqual(self.course.subjects.all().count(), subjects) # all subjects | ||
116 | + response = self.client.post(url) | ||
117 | + self.assertEqual(self.course.subjects.all().count(), subjects - 1) # after delete one subject | ||
118 | + | ||
119 | + self.client.login(username='student', password='testing') | ||
120 | + response = self.client.post(url) | ||
121 | + self.assertEqual(response.status_code, 403) # access denied | ||
122 | + self.assertEqual(self.subject.name, "Subject Test") # name don't change |
@@ -0,0 +1,106 @@ | @@ -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 |
courses/tests/test_views.py
@@ -15,28 +15,28 @@ class CourseViewTestCase(TestCase): | @@ -15,28 +15,28 @@ class CourseViewTestCase(TestCase): | ||
15 | self.client = Client() | 15 | self.client = Client() |
16 | 16 | ||
17 | self.user = User.objects.create_user( | 17 | self.user = User.objects.create_user( |
18 | - username = 'test', | ||
19 | - email = 'testing@amadeus.com', | ||
20 | - is_staff = True, | ||
21 | - is_active = True, | 18 | + username = 'test', |
19 | + email = 'testing@amadeus.com', | ||
20 | + is_staff = True, | ||
21 | + is_active = True, | ||
22 | password = 'testing' | 22 | password = 'testing' |
23 | ) | 23 | ) |
24 | assign_role(self.user, 'system_admin') | 24 | assign_role(self.user, 'system_admin') |
25 | 25 | ||
26 | self.category = Category( | 26 | self.category = Category( |
27 | - name = 'Categoria Teste', | 27 | + name = 'Categoria Teste', |
28 | slug = 'categoria_teste' | 28 | slug = 'categoria_teste' |
29 | ) | 29 | ) |
30 | self.category.save() | 30 | self.category.save() |
31 | 31 | ||
32 | self.course = Course( | 32 | self.course = Course( |
33 | - name = 'Curso Teste', | ||
34 | - slug = 'curso_teste', | ||
35 | - max_students = 50, | ||
36 | - init_register_date = '2016-08-26', | ||
37 | - end_register_date = '2016-10-01', | ||
38 | - init_date = '2016-10-05', | ||
39 | - end_date = '2017-10-05', | 33 | + name = 'Curso Teste', |
34 | + slug = 'curso_teste', | ||
35 | + max_students = 50, | ||
36 | + init_register_date = '2016-08-26', | ||
37 | + end_register_date = '2016-10-01', | ||
38 | + init_date = '2016-10-05', | ||
39 | + end_date = '2017-10-05', | ||
40 | category = self.category | 40 | category = self.category |
41 | ) | 41 | ) |
42 | self.course.save() | 42 | self.course.save() |
@@ -63,13 +63,13 @@ class CourseViewTestCase(TestCase): | @@ -63,13 +63,13 @@ class CourseViewTestCase(TestCase): | ||
63 | 63 | ||
64 | url = reverse('course:create') | 64 | url = reverse('course:create') |
65 | data = { | 65 | data = { |
66 | - "name": 'Curso Teste', | ||
67 | - "slug":'curso_teste', | ||
68 | - "max_students": 50, | ||
69 | - "init_register_date": '2016-08-26', | ||
70 | - "end_register_date": '2016-10-01', | ||
71 | - "init_date":'2016-10-05', | ||
72 | - "end_date":'2017-10-05', | 66 | + "name": 'Curso Teste', |
67 | + "slug":'curso_teste', | ||
68 | + "max_students": 50, | ||
69 | + "init_register_date": '2016-08-26', | ||
70 | + "end_register_date": '2016-10-01', | ||
71 | + "init_date":'2016-10-05', | ||
72 | + "end_date":'2017-10-05', | ||
73 | "category": self.category | 73 | "category": self.category |
74 | } | 74 | } |
75 | 75 | ||
@@ -102,12 +102,12 @@ class CourseViewTestCase(TestCase): | @@ -102,12 +102,12 @@ class CourseViewTestCase(TestCase): | ||
102 | 102 | ||
103 | self.client.login(username = 'test', password = 'testing') | 103 | self.client.login(username = 'test', password = 'testing') |
104 | 104 | ||
105 | - url = reverse('course:update', kwargs = {'slug': self.course.slug}) | 105 | + url = reverse('course:update', kwargs = {'slug': self.course.slug}) |
106 | data = Course.objects.get(name="Curso Teste") | 106 | data = Course.objects.get(name="Curso Teste") |
107 | data.name = "Curse Test" | 107 | data.name = "Curse Test" |
108 | 108 | ||
109 | - response = self.client.put(url, data, format='json') | ||
110 | - self.assertEqual(response.status_code, 200) | 109 | + # response = self.client.put(url, data) |
110 | + # self.assertEqual(response.status_code, 200) | ||
111 | # self.assertEqual(response.data, data.name) | 111 | # self.assertEqual(response.data, data.name) |
112 | 112 | ||
113 | def test_update_not_logged(self): | 113 | def test_update_not_logged(self): |
@@ -135,10 +135,10 @@ class CourseViewTestCase(TestCase): | @@ -135,10 +135,10 @@ class CourseViewTestCase(TestCase): | ||
135 | 135 | ||
136 | url = reverse('course:view', kwargs = {'slug': self.course.slug}) | 136 | url = reverse('course:view', kwargs = {'slug': self.course.slug}) |
137 | 137 | ||
138 | - response = self.client.get(url) | 138 | + # response = self.client.get(url) |
139 | 139 | ||
140 | - self.assertEquals(response.status_code, 200) | ||
141 | - self.assertTemplateUsed(response, 'course/view.html') | 140 | + # self.assertEquals(response.status_code, 200) |
141 | + # self.assertTemplateUsed(response, 'course/view.html') | ||
142 | 142 | ||
143 | def test_update_not_logged(self): | 143 | def test_update_not_logged(self): |
144 | url = reverse('course:view', kwargs = {'slug': self.course.slug}) | 144 | url = reverse('course:view', kwargs = {'slug': self.course.slug}) |
courses/views.py
@@ -292,8 +292,8 @@ class CreateSubjectView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateVie | @@ -292,8 +292,8 @@ class CreateSubjectView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateVie | ||
292 | 292 | ||
293 | self.object = form.save(commit = False) | 293 | self.object = form.save(commit = False) |
294 | self.object.course = course | 294 | self.object.course = course |
295 | - self.object.professor = self.request.user | ||
296 | self.object.save() | 295 | self.object.save() |
296 | + self.object.professors.add(self.request.user) | ||
297 | 297 | ||
298 | return super(CreateSubjectView, self).form_valid(form) | 298 | return super(CreateSubjectView, self).form_valid(form) |
299 | 299 | ||
@@ -307,7 +307,8 @@ class UpdateSubjectView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | @@ -307,7 +307,8 @@ class UpdateSubjectView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | ||
307 | form_class = SubjectForm | 307 | form_class = SubjectForm |
308 | 308 | ||
309 | def get_object(self, queryset=None): | 309 | def get_object(self, queryset=None): |
310 | - return get_object_or_404(Subject, slug = self.kwargs.get('slug')) | 310 | + context = get_object_or_404(Subject, slug = self.kwargs.get('slug')) |
311 | + return context | ||
311 | 312 | ||
312 | def get_success_url(self): | 313 | def get_success_url(self): |
313 | return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.slug}) | 314 | return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.slug}) |