diff options
author | adityacp | 2018-01-17 17:23:48 +0530 |
---|---|---|
committer | adityacp | 2018-01-17 17:23:48 +0530 |
commit | ef9b17ffcf89a3ce90930f7ce4e91b481ad2a53a (patch) | |
tree | e55b42d29fb19a83c9c7afe5a71cb6978873a8d1 | |
parent | 8006ffb4a5bd54aa960b24f1508d95844fa579de (diff) | |
download | online_test-ef9b17ffcf89a3ce90930f7ce4e91b481ad2a53a.tar.gz online_test-ef9b17ffcf89a3ce90930f7ce4e91b481ad2a53a.tar.bz2 online_test-ef9b17ffcf89a3ce90930f7ce4e91b481ad2a53a.zip |
Change views.py and test_views.py
- Add a condition to disallow a teacher to become course creator
- Add test to check if a teacher does not become course creator
-rw-r--r-- | yaksh/test_views.py | 49 | ||||
-rw-r--r-- | yaksh/views.py | 4 |
2 files changed, 51 insertions, 2 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 6444465..b4531a6 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1916,6 +1916,25 @@ class TestAddCourse(TestCase): timezone='UTC' ) + # Create a teacher + self.teacher_plaintext_pass = 'demo_teacher' + self.teacher = User.objects.create_user( + username='demo_teacher', + password=self.teacher_plaintext_pass, + first_name='first_name', + last_name='last_name', + email='demo@test.com' + ) + + Profile.objects.create( + user=self.teacher, + roll_number=10, + institute='IIT', + department='Chemical', + position='Moderator', + timezone='UTC' + ) + # Create Student self.student_plaintext_pass = 'demo_student' self.student = User.objects.create_user( @@ -1928,10 +1947,13 @@ class TestAddCourse(TestCase): # Add to moderator group self.mod_group.user_set.add(self.user) + self.mod_group.user_set.add(self.teacher) self.course = Course.objects.create(name="Python Course", enrollment="Enroll Request", creator=self.user) + self.course.teachers.add(self.teacher) + self.pre_req_quiz = Quiz.objects.create( start_date_time=datetime(2014, 2, 1, 5, 8, 15, 0, tzone), end_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzone), @@ -2021,6 +2043,33 @@ class TestAddCourse(TestCase): self.assertRedirects(response, '/exam/manage/courses', target_status_code=301) + def test_add_course_teacher_cannot_be_creator(self): + """ + Teacher editing the course should not become creator + """ + self.client.login( + username=self.teacher.username, + password=self.teacher_plaintext_pass + ) + + response = self.client.post(reverse('yaksh:edit_course', + kwargs={"course_id": self.course.id}), + data={'name': 'Teacher_course', + 'active': True, + 'enrollment': 'open', + 'start_enroll_time': '2016-01-10 09:00:15', + 'end_enroll_time': '2016-01-15 09:00:15', + } + ) + updated_course = Course.objects.get(id=self.course.id) + self.assertEqual(updated_course.name, 'Teacher_course') + self.assertEqual(updated_course.enrollment, 'open') + self.assertEqual(updated_course.active, True) + self.assertEqual(response.status_code, 302) + self.assertEqual(updated_course.creator, self.user) + self.assertRedirects(response, '/exam/manage/courses', + target_status_code=301) + class TestCourseDetail(TestCase): def setUp(self): diff --git a/yaksh/views.py b/yaksh/views.py index 21c79f3..61bca4c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -932,14 +932,14 @@ def add_course(request, course_id=None): raise Http404("You are not allowed to view this course") else: course = None - if not is_moderator(user): raise Http404('You are not allowed to view this page') if request.method == 'POST': form = CourseForm(request.POST, instance=course) if form.is_valid(): new_course = form.save(commit=False) - new_course.creator = user + if course_id is None: + new_course.creator = user new_course.save() return my_redirect('/exam/manage/courses') else: |