Commit 85bd5885fb988dbc62b19f6786660a42095edc14
1 parent
ce05fc88
Exists in
master
and in
5 other branches
Create course category unit test [Issue #137]
Showing
3 changed files
with
111 additions
and
3 deletions
Show diff stats
courses/templates/topic/update.html
| ... | ... | @@ -17,7 +17,7 @@ |
| 17 | 17 | </div> |
| 18 | 18 | {% endfor %} |
| 19 | 19 | <div class="col-lg-offset-4 col-lg-4"> |
| 20 | - <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Update' %}</button> | |
| 20 | + <button type="submit" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Update' %}</button> | |
| 21 | 21 | |
| 22 | 22 | </div> |
| 23 | 23 | </form> | ... | ... |
| ... | ... | @@ -0,0 +1,108 @@ |
| 1 | +from django.test import TestCase, Client | |
| 2 | + | |
| 3 | +from django.core.urlresolvers import reverse | |
| 4 | +from rolepermissions.shortcuts import assign_role | |
| 5 | + | |
| 6 | +from users.models import User | |
| 7 | +from courses.models import CourseCategory | |
| 8 | + | |
| 9 | +class ForumViewTestCase (TestCase): | |
| 10 | + | |
| 11 | + def setUp(self): | |
| 12 | + | |
| 13 | + self.user = User.objects.create_user( | |
| 14 | + username = 'test', | |
| 15 | + email = 'testing@amadeus.com', | |
| 16 | + is_staff = True, | |
| 17 | + is_active = True, | |
| 18 | + password = 'testing' | |
| 19 | + ) | |
| 20 | + assign_role(self.user, 'system_admin') | |
| 21 | + | |
| 22 | + self.user_professor = User.objects.create_user( | |
| 23 | + username = 'professor', | |
| 24 | + email = 'professor@amadeus.com', | |
| 25 | + is_staff = False, | |
| 26 | + is_active = True, | |
| 27 | + password = 'testing', | |
| 28 | + type_profile = 1 | |
| 29 | + ) | |
| 30 | + assign_role(self.user_professor, 'professor') | |
| 31 | + | |
| 32 | + self.user_student = User.objects.create_user( | |
| 33 | + username = 'student', | |
| 34 | + email = 'student@amadeus.com', | |
| 35 | + is_staff = False, | |
| 36 | + is_active = True, | |
| 37 | + password = 'testing', | |
| 38 | + type_profile = 2 | |
| 39 | + ) | |
| 40 | + assign_role(self.user_student, 'student') | |
| 41 | + | |
| 42 | + self.category = CourseCategory.objects.create( | |
| 43 | + name = 'Test Category' | |
| 44 | + ) | |
| 45 | + self.category.save() | |
| 46 | + | |
| 47 | + | |
| 48 | + self.client = Client() | |
| 49 | + self.client.login(username='test', password='testing') | |
| 50 | + | |
| 51 | + self.client_professor = Client() | |
| 52 | + self.client_professor.login (username='professor', password='testing') | |
| 53 | + | |
| 54 | + self.client_student = Client() | |
| 55 | + self.client_student.login (username='student', password='testing') | |
| 56 | + | |
| 57 | + | |
| 58 | +######################### CreateCatView ######################### | |
| 59 | + | |
| 60 | + def test_CreateCatView_ok (self): | |
| 61 | + url = reverse('course:create_cat') | |
| 62 | + | |
| 63 | + response = self.client.get(url) | |
| 64 | + self.assertEquals(response.status_code, 200) | |
| 65 | + | |
| 66 | + response = self.client_professor.get(url) | |
| 67 | + self.assertEquals(response.status_code, 200) | |
| 68 | + | |
| 69 | + response = self.client_student.get(url) | |
| 70 | + self.assertEquals(response.status_code, 403) | |
| 71 | + | |
| 72 | + def test_CreateCatView_context (self): | |
| 73 | + url = reverse('course:create_cat') | |
| 74 | + | |
| 75 | + response = self.client.get(url) | |
| 76 | + self.assertTrue('form' in response.context) | |
| 77 | + | |
| 78 | + response = self.client_professor.get(url) | |
| 79 | + self.assertTrue('form' in response.context) | |
| 80 | + | |
| 81 | + def test_CreateCatView_form_error (self): | |
| 82 | + url = reverse('course:create_cat') | |
| 83 | + data = {'name':''} | |
| 84 | + list_categories = CourseCategory.objects.all().count() | |
| 85 | + | |
| 86 | + response = self.client.post(url, data) | |
| 87 | + self.assertEquals(list_categories, CourseCategory.objects.all().count()) | |
| 88 | + | |
| 89 | + response = self.client_professor.post(url, data) | |
| 90 | + self.assertEquals(list_categories, CourseCategory.objects.all().count()) | |
| 91 | + | |
| 92 | + def test_CreateCatView_form_ok (self): | |
| 93 | + url = reverse('course:create_cat') | |
| 94 | + data = { | |
| 95 | + 'name':'Second Category', | |
| 96 | + } | |
| 97 | + list_categories = CourseCategory.objects.all().count() | |
| 98 | + | |
| 99 | + response = self.client.post(url, data) | |
| 100 | + self.assertEquals (response.status_code, 302) | |
| 101 | + self.assertEquals(list_categories+1, CourseCategory.objects.all().count()) | |
| 102 | + | |
| 103 | + data = { | |
| 104 | + 'name' : 'Third Category', | |
| 105 | + } | |
| 106 | + response = self.client_professor.post(url, data) | |
| 107 | + self.assertEquals (response.status_code, 302) | |
| 108 | + self.assertEquals(list_categories+2, CourseCategory.objects.all().count()) | |
| 0 | 109 | \ No newline at end of file | ... | ... |
courses/tests/test_views.py
| ... | ... | @@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse |
| 5 | 5 | |
| 6 | 6 | from rolepermissions.shortcuts import assign_role |
| 7 | 7 | |
| 8 | -from courses.models import Course, Category | |
| 8 | +from courses.models import Course, CourseCategory | |
| 9 | 9 | from courses.forms import CourseForm |
| 10 | 10 | from users.models import User |
| 11 | 11 | |
| ... | ... | @@ -23,7 +23,7 @@ class CourseViewTestCase(TestCase): |
| 23 | 23 | ) |
| 24 | 24 | assign_role(self.user, 'system_admin') |
| 25 | 25 | |
| 26 | - self.category = Category( | |
| 26 | + self.category = CourseCategory( | |
| 27 | 27 | name = 'Categoria Teste', |
| 28 | 28 | slug = 'categoria_teste' |
| 29 | 29 | ) | ... | ... |