diff options
-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: |