def test_add_users_doesnt_add_duplicate_entry(self): """ Tests that calling add_users multiple times before a single call to remove_users does not result in the user remaining in the group. """ role = CourseStaffRole(self.course_key) role.add_users(self.student) assert role.has_user(self.student) # Call add_users a second time, then remove just once. role.add_users(self.student) role.remove_users(self.student) assert not role.has_user(self.student)
def assign_staff_role_to_ccx(ccx_locator, user, master_course_id): """ Check if user has ccx_coach role on master course then assign them staff role on ccx only if role is not already assigned. Because of this coach can open dashboard from master course as well as ccx. :param ccx_locator: CCX key :param user: User to whom we want to assign role. :param master_course_id: Master course key """ coach_role_on_master_course = CourseCcxCoachRole(master_course_id) # check if user has coach role on master course if coach_role_on_master_course.has_user(user): # Check if user has staff role on ccx. role = CourseStaffRole(ccx_locator) if not role.has_user(user): # assign user the staff role on ccx with ccx_course(ccx_locator) as course: allow_access(course, user, "staff", send_email=False)
def test_create_ccx(self, ccx_name='New CCX'): """ Create CCX. Follow redirect to coach dashboard, confirm we see the coach dashboard for the new CCX. """ self.make_coach() url = reverse( 'create_ccx', kwargs={'course_id': str(self.course.id)}) response = self.client.post(url, {'name': ccx_name}) assert response.status_code == 302 url = response.get('location') response = self.client.get(url) assert response.status_code == 200 # Get the ccx_key path = six.moves.urllib.parse.urlparse(url).path resolver = resolve(path) ccx_key = resolver.kwargs['course_id'] course_key = CourseKey.from_string(ccx_key) assert CourseEnrollment.is_enrolled(self.coach, course_key) assert re.search('id="ccx-schedule"', response.content.decode('utf-8')) # check if the max amount of student that can be enrolled has been overridden ccx = CustomCourseForEdX.objects.get() course_enrollments = get_override_for_ccx(ccx, self.course, 'max_student_enrollments_allowed') assert course_enrollments == settings.CCX_MAX_STUDENTS_ALLOWED # check if the course display name is properly set course_display_name = get_override_for_ccx(ccx, self.course, 'display_name') assert course_display_name == ccx_name # check if the course display name is properly set in modulestore course_display_name = self.mstore.get_course(ccx.locator).display_name assert course_display_name == ccx_name # assert ccx creator has role=staff role = CourseStaffRole(course_key) assert role.has_user(self.coach) # assert that staff and instructors of master course has staff and instructor roles on ccx list_staff_master_course = list_with_level(self.course, 'staff') list_instructor_master_course = list_with_level(self.course, 'instructor') # assert that forum roles are seeded assert are_permissions_roles_seeded(course_key) assert has_forum_access(self.coach.username, course_key, FORUM_ROLE_ADMINISTRATOR) with ccx_course(course_key) as course_ccx: list_staff_ccx_course = list_with_level(course_ccx, 'staff') # The "Coach" in the parent course becomes "Staff" on the CCX, so the CCX should have 1 "Staff" # user more than the parent course assert (len(list_staff_master_course) + 1) == len(list_staff_ccx_course) assert list_staff_master_course[0].email in [ccx_staff.email for ccx_staff in list_staff_ccx_course] # Make sure the "Coach" on the parent course is "Staff" on the CCX assert self.coach in list_staff_ccx_course list_instructor_ccx_course = list_with_level(course_ccx, 'instructor') assert len(list_instructor_ccx_course) == len(list_instructor_master_course) assert list_instructor_ccx_course[0].email == list_instructor_master_course[0].email