示例#1
0
    def setUp(self):
        super(CohortedTestCase, self).setUp()

        self.course = CourseFactory.create(
            cohort_config={
                "cohorted": True,
                "cohorted_discussions": ["cohorted_topic"]
            }
        )
        self.student_cohort = CohortFactory.create(
            name="student_cohort",
            course_id=self.course.id
        )
        self.moderator_cohort = CohortFactory.create(
            name="moderator_cohort",
            course_id=self.course.id
        )
        self.course.discussion_topics["cohorted topic"] = {"id": "cohorted_topic"}
        self.course.discussion_topics["non-cohorted topic"] = {"id": "non_cohorted_topic"}
        self.store.update_item(self.course, self.user.id)

        seed_permissions_roles(self.course.id)
        self.student = UserFactory.create()
        self.moderator = UserFactory.create()
        CourseEnrollmentFactory(user=self.student, course_id=self.course.id)
        CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id)
        self.moderator.roles.add(Role.objects.get(name="Moderator", course_id=self.course.id))
        self.student_cohort.users.add(self.student)
        self.moderator_cohort.users.add(self.moderator)
示例#2
0
 def setUp(self):
     self.course = CourseFactory.create()
     self.cohort_1 = CohortFactory(course_id=self.course.id, name='Cohort 1')
     self.cohort_2 = CohortFactory(course_id=self.course.id, name='Cohort 2')
     self.student_1 = self.create_student(username=u'student_1\xec', email='*****@*****.**')
     self.student_2 = self.create_student(username='******', email='*****@*****.**')
     self.csv_header_row = ['Cohort Name', 'Exists', 'Students Added', 'Students Not Found']
示例#3
0
    def setUp(self):
        super(CohortedTestCase, self).setUp()

        self.course = CourseFactory.create(
            cohort_config={
                "cohorted": True,
                "cohorted_discussions": ["cohorted_topic"]
            })
        self.student_cohort = CohortFactory.create(name="student_cohort",
                                                   course_id=self.course.id)
        self.moderator_cohort = CohortFactory.create(name="moderator_cohort",
                                                     course_id=self.course.id)
        self.course.discussion_topics["cohorted topic"] = {
            "id": "cohorted_topic"
        }
        self.course.discussion_topics["non-cohorted topic"] = {
            "id": "non_cohorted_topic"
        }
        self.store.update_item(self.course, self.user.id)

        seed_permissions_roles(self.course.id)
        self.student = UserFactory.create()
        self.moderator = UserFactory.create()
        CourseEnrollmentFactory(user=self.student, course_id=self.course.id)
        CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id)
        self.moderator.roles.add(
            Role.objects.get(name="Moderator", course_id=self.course.id))
        self.student_cohort.users.add(self.student)
        self.moderator_cohort.users.add(self.moderator)
示例#4
0
 def test_request_group(self, role_name, course_is_cohorted):
     cohort_course = CourseFactory.create(cohort_config={"cohorted": course_is_cohorted})
     CohortFactory.create(course_id=cohort_course.id, users=[self.user])
     role = Role.objects.create(name=role_name, course_id=cohort_course.id)
     role.users = [self.user]
     self.get_thread_list([], course=cohort_course)
     actual_has_group = "group_id" in httpretty.last_request().querystring
     expected_has_group = (course_is_cohorted and role_name == FORUM_ROLE_STUDENT)
     self.assertEqual(actual_has_group, expected_has_group)
示例#5
0
 def test_request_group(self, role_name, course_is_cohorted):
     cohort_course = CourseFactory.create(cohort_config={"cohorted": course_is_cohorted})
     CourseEnrollmentFactory.create(user=self.user, course_id=cohort_course.id)
     CohortFactory.create(course_id=cohort_course.id, users=[self.user])
     role = Role.objects.create(name=role_name, course_id=cohort_course.id)
     role.users = [self.user]
     self.get_thread_list([], course=cohort_course)
     actual_has_group = "group_id" in httpretty.last_request().querystring
     expected_has_group = (course_is_cohorted and role_name == FORUM_ROLE_STUDENT)
     self.assertEqual(actual_has_group, expected_has_group)
示例#6
0
 def setUp(self):  # pylint: disable=arguments-differ
     super().setUp()
     self.course = CourseOverviewFactory()
     self.user = UserFactory.create(username="******",
                                    first_name="Student",
                                    last_name="Person",
                                    email="*****@*****.**",
                                    is_active=True)
     self.first_cohort = CohortFactory(course_id=self.course.id,
                                       name="FirstCohort")
     self.second_cohort = CohortFactory(course_id=self.course.id,
                                        name="SecondCohort")
示例#7
0
 def test_group_access(self, role_name, course_is_cohorted, thread_group_state):
     cohort_course = CourseFactory.create(cohort_config={"cohorted": course_is_cohorted})
     CourseEnrollmentFactory.create(user=self.user, course_id=cohort_course.id)
     cohort = CohortFactory.create(course_id=cohort_course.id, users=[self.user])
     role = Role.objects.create(name=role_name, course_id=cohort_course.id)
     role.users = [self.user]
     thread = self.make_minimal_cs_thread(
         {
             "course_id": unicode(cohort_course.id),
             "group_id": (
                 None
                 if thread_group_state == "no_group"
                 else cohort.id
                 if thread_group_state == "match_group"
                 else cohort.id + 1
             ),
         }
     )
     expected_error = (
         role_name == FORUM_ROLE_STUDENT and course_is_cohorted and thread_group_state == "different_group"
     )
     try:
         self.get_comment_list(thread)
         self.assertFalse(expected_error)
     except Http404:
         self.assertTrue(expected_error)
    def add_seq_with_content_groups(self, groups=None):
        """
        Adds sequential and two content groups to first course in courses list.
        """
        config_course_cohorts(self.courses[0], is_cohorted=True)

        if groups is None:
            groups = self.groups

        self.user_partition = UserPartition(id=0,
                                            name='Partition 1',
                                            description='This is partition 1',
                                            groups=groups,
                                            scheme=CohortPartitionScheme)

        self.user_partition.scheme.name = "cohort"

        ItemFactory.create(
            parent_location=self.chapter.location,
            category='sequential',
            display_name="Lesson 1",
            publish_item=True,
            metadata={u"user_partitions": [self.user_partition.to_json()]})

        self.first_cohort, self.second_cohort = [
            CohortFactory(course_id=self.courses[0].id) for _ in range(2)
        ]

        self.courses[0].user_partitions = [self.user_partition]
        self.courses[0].save()
        modulestore().update_item(self.courses[0], self.user.id)
示例#9
0
    def setUp(self):
        super(CohortedTestCase, self).setUp()

        seed_permissions_roles(self.course.id)
        self.student = UserFactory.create()
        self.moderator = UserFactory.create()
        CourseEnrollmentFactory(user=self.student, course_id=self.course.id)
        CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id)
        self.moderator.roles.add(
            Role.objects.get(name="Moderator", course_id=self.course.id))
        self.student_cohort = CohortFactory.create(name="student_cohort",
                                                   course_id=self.course.id,
                                                   users=[self.student])
        self.moderator_cohort = CohortFactory.create(name="moderator_cohort",
                                                     course_id=self.course.id,
                                                     users=[self.moderator])
示例#10
0
 def test_group_access(self, role_name, course_is_cohorted,
                       thread_group_state):
     cohort_course = CourseFactory.create(
         cohort_config={"cohorted": course_is_cohorted})
     CourseEnrollmentFactory.create(user=self.user,
                                    course_id=cohort_course.id)
     cohort = CohortFactory.create(course_id=cohort_course.id,
                                   users=[self.user])
     role = Role.objects.create(name=role_name, course_id=cohort_course.id)
     role.users = [self.user]
     thread = self.make_minimal_cs_thread({
         "course_id":
         unicode(cohort_course.id),
         "group_id":
         (None if thread_group_state == "no_group" else
          cohort.id if thread_group_state == "match_group" else cohort.id +
          1),
     })
     expected_error = (role_name == FORUM_ROLE_STUDENT
                       and course_is_cohorted
                       and thread_group_state == "different_group")
     try:
         self.get_comment_list(thread)
         self.assertFalse(expected_error)
     except Http404:
         self.assertTrue(expected_error)
示例#11
0
    def test_enrolled_students_features_keys_cohorted(self):
        course = CourseFactory.create(org="test", course="course1", display_name="run1")
        course.cohort_config = {'cohorted': True, 'auto_cohort': True, 'auto_cohort_groups': ['cohort']}
        self.store.update_item(course, self.instructor.id)
        cohorted_students = [UserFactory.create() for _ in range(10)]
        cohort = CohortFactory.create(name='cohort', course_id=course.id, users=cohorted_students)
        cohorted_usernames = [student.username for student in cohorted_students]
        non_cohorted_student = UserFactory.create()
        for student in cohorted_students:
            cohort.users.add(student)
            CourseEnrollment.enroll(student, course.id)
        CourseEnrollment.enroll(non_cohorted_student, course.id)
        instructor = InstructorFactory(course_key=course.id)
        self.client.login(username=instructor.username, password='******')

        query_features = ('username', 'cohort')
        # There should be a constant of 2 SQL queries when calling
        # enrolled_students_features.  The first query comes from the call to
        # User.objects.filter(...), and the second comes from
        # prefetch_related('course_groups').
        with self.assertNumQueries(2):
            userreports = enrolled_students_features(course.id, query_features)
        self.assertEqual(len([r for r in userreports if r['username'] in cohorted_usernames]), len(cohorted_students))
        self.assertEqual(len([r for r in userreports if r['username'] == non_cohorted_student.username]), 1)
        for report in userreports:
            self.assertEqual(set(report.keys()), set(query_features))
            if report['username'] in cohorted_usernames:
                self.assertEqual(report['cohort'], cohort.name)
            else:
                self.assertEqual(report['cohort'], '[unassigned]')
示例#12
0
    def test_enrolled_students_features_keys_cohorted(self):
        course = CourseFactory.create(org="test", course="course1", display_name="run1")
        course.cohort_config = {'cohorted': True, 'auto_cohort': True, 'auto_cohort_groups': ['cohort']}
        self.store.update_item(course, self.instructor.id)
        cohorted_students = [UserFactory.create() for _ in xrange(10)]
        cohort = CohortFactory.create(name='cohort', course_id=course.id, users=cohorted_students)
        cohorted_usernames = [student.username for student in cohorted_students]
        non_cohorted_student = UserFactory.create()
        for student in cohorted_students:
            cohort.users.add(student)
            CourseEnrollment.enroll(student, course.id)
        CourseEnrollment.enroll(non_cohorted_student, course.id)
        instructor = InstructorFactory(course_key=course.id)
        self.client.login(username=instructor.username, password='******')

        query_features = ('username', 'cohort')
        # There should be a constant of 2 SQL queries when calling
        # enrolled_students_features.  The first query comes from the call to
        # User.objects.filter(...), and the second comes from
        # prefetch_related('course_groups').
        with self.assertNumQueries(2):
            userreports = enrolled_students_features(course.id, query_features)
        self.assertEqual(len([r for r in userreports if r['username'] in cohorted_usernames]), len(cohorted_students))
        self.assertEqual(len([r for r in userreports if r['username'] == non_cohorted_student.username]), 1)
        for report in userreports:
            self.assertEqual(set(report.keys()), set(query_features))
            if report['username'] in cohorted_usernames:
                self.assertEqual(report['cohort'], cohort.name)
            else:
                self.assertEqual(report['cohort'], '[unassigned]')
示例#13
0
 def test_group(self):
     self.course.cohort_config = {"cohorted": True}
     modulestore().update_item(self.course, ModuleStoreEnum.UserID.test)
     cohort = CohortFactory.create(course_id=self.course.id)
     serialized = self.serialize(self.make_cs_content({"group_id": cohort.id}))
     self.assertEqual(serialized["group_id"], cohort.id)
     self.assertEqual(serialized["group_name"], cohort.name)
示例#14
0
    def test_unicode_cohort_data_in_grading(self):
        """
        Test that cohorts can contain unicode characters.
        """
        cohort_groups = [u'ÞrÖfessÖr X', u'MàgnëtÖ']
        course = CourseFactory.create(cohort_config={'cohorted': True})

        # Create users and manually assign cohorts
        user1 = UserFactory.create(username='******')
        user2 = UserFactory.create(username='******')
        CourseEnrollment.enroll(user1, course.id)
        CourseEnrollment.enroll(user2, course.id)
        cohort1 = CohortFactory(course_id=course.id, name=u'ÞrÖfessÖr X')
        cohort2 = CohortFactory(course_id=course.id, name=u'MàgnëtÖ')
        cohort1.users.add(user1)
        cohort2.users.add(user2)

        self._verify_cohort_data(course.id, cohort_groups)
示例#15
0
文件: utils.py 项目: edx/edx-platform
    def setUp(self):
        super(CohortedTestCase, self).setUp()

        seed_permissions_roles(self.course.id)
        self.student = UserFactory.create()
        self.moderator = UserFactory.create()
        CourseEnrollmentFactory(user=self.student, course_id=self.course.id)
        CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id)
        self.moderator.roles.add(Role.objects.get(name="Moderator", course_id=self.course.id))
        self.student_cohort = CohortFactory.create(
            name="student_cohort",
            course_id=self.course.id,
            users=[self.student]
        )
        self.moderator_cohort = CohortFactory.create(
            name="moderator_cohort",
            course_id=self.course.id,
            users=[self.moderator]
        )
示例#16
0
    def test_unicode_cohort_data_in_grading(self):
        """
        Test that cohorts can contain unicode characters.
        """
        course = CourseFactory.create(cohort_config={'cohorted': True})

        # Create users and manually assign cohorts
        user1 = UserFactory.create(username='******')
        user2 = UserFactory.create(username='******')
        CourseEnrollment.enroll(user1, course.id)
        CourseEnrollment.enroll(user2, course.id)
        professor_x = u'ÞrÖfessÖr X'
        magneto = u'MàgnëtÖ'
        cohort1 = CohortFactory(course_id=course.id, name=professor_x)
        cohort2 = CohortFactory(course_id=course.id, name=magneto)
        cohort1.users.add(user1)
        cohort2.users.add(user2)

        self._verify_cell_data_for_user(user1.username, course.id, 'Cohort Name', professor_x)
        self._verify_cell_data_for_user(user2.username, course.id, 'Cohort Name', magneto)
示例#17
0
    def test_filter_cohort_id_does_not_exist(self):
        with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as mock_grade:
            mock_grade.return_value = self.mock_course_grade(self.student, passed=True, letter_grade='A', percent=0.85)

            empty_cohort = CohortFactory(course_id=self.course.id, name="TestCohort", users=[])
            with override_waffle_flag(self.waffle_flag, active=True):
                self.login_staff()
                resp = self.client.get(
                    self.get_url(course_key=self.course.id) + '?cohort_id={}'.format(empty_cohort.id)
                )
                self._assert_empty_response(resp)
示例#18
0
 def setUp(self):
     super(GetThreadListTest, self).setUp()
     httpretty.reset()
     httpretty.enable()
     self.addCleanup(httpretty.disable)
     self.maxDiff = None  # pylint: disable=invalid-name
     self.user = UserFactory.create()
     self.register_get_user_response(self.user)
     self.request = RequestFactory().get("/test_path")
     self.request.user = self.user
     self.course = CourseFactory.create()
     self.author = UserFactory.create()
     self.cohort = CohortFactory.create(course_id=self.course.id)
示例#19
0
 def setUp(self):
     super(GetThreadListTest, self).setUp()
     httpretty.reset()
     httpretty.enable()
     self.addCleanup(httpretty.disable)
     self.maxDiff = None  # pylint: disable=invalid-name
     self.user = UserFactory.create()
     self.register_get_user_response(self.user)
     self.request = RequestFactory().get("/test_path")
     self.request.user = self.user
     self.course = CourseFactory.create()
     CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id)
     self.author = UserFactory.create()
     self.cohort = CohortFactory.create(course_id=self.course.id)
 def setup_cohorts(self, course):
     """
     Sets up a cohort for each previously created user partition.
     """
     config_course_cohorts(course, is_cohorted=True)
     self.partition_cohorts = []
     for user_partition in self.user_partitions:
         partition_cohorts = []
         for group in self.groups:
             cohort = CohortFactory(course_id=course.id)
             partition_cohorts.append(cohort)
             link_cohort_to_partition_group(
                 cohort,
                 user_partition.id,
                 group.id,
             )
         self.partition_cohorts.append(partition_cohorts)
示例#21
0
    def setUp(self):
        super(UniversityIDModelTest, self).setUp()
        self.course = CourseFactory.create(
            org='a',
            number='b',
            run='c',
        )
        self.cohort = CohortFactory.create(course_id=self.course.id, )
        set_course_cohort_settings(course_key=self.course.id, is_cohorted=True)
        self.model = UniversityIDFactory.create(
            user__username='******',
            user__email='*****@*****.**',
            user__profile__name='Mike Wazowski',
            course_key=self.course.id,
            university_id='201711201',
        )

        self.profile = UserProfile.objects.get(user=self.model.user)
示例#22
0
 def _set_up_course(self, is_course_cohorted, is_user_cohorted, is_moderator):
     cohort_config = {"cohorted": True} if is_course_cohorted else {}
     course = CourseFactory(
         number=("TestCourse{}".format(len(self.courses))),
         cohort_config=cohort_config
     )
     self.courses.append(course)
     CourseEnrollmentFactory(user=self.user, course_id=course.id)
     if is_user_cohorted:
         cohort = CohortFactory.create(
             name="Test Cohort",
             course_id=course.id,
             users=[self.user]
         )
         self.cohorts.append(cohort)
     if is_moderator:
         moderator_perm, _ = Permission.objects.get_or_create(name="see_all_cohorts")
         moderator_role = Role.objects.create(name="Moderator", course_id=course.id)
         moderator_role.permissions.add(moderator_perm)
         self.user.roles.add(moderator_role)
示例#23
0
 def _set_up_course(self, is_course_cohorted, is_user_cohorted,
                    is_moderator):
     cohort_config = {"cohorted": True} if is_course_cohorted else {}
     course = CourseFactory(number=("TestCourse{}".format(len(
         self.courses))),
                            cohort_config=cohort_config)
     self.courses.append(course)
     CourseEnrollmentFactory(user=self.user, course_id=course.id)
     if is_user_cohorted:
         cohort = CohortFactory.create(name="Test Cohort",
                                       course_id=course.id,
                                       users=[self.user])
         self.cohorts.append(cohort)
     if is_moderator:
         moderator_perm, _ = Permission.objects.get_or_create(
             name="see_all_cohorts")
         moderator_role = Role.objects.create(name="Moderator",
                                              course_id=course.id)
         moderator_role.permissions.add(moderator_perm)
         self.user.roles.add(moderator_role)
示例#24
0
    def test_with_cohorted_content(self, content_creator_method_name,
                                   api_version):
        self.login_and_enroll()
        self._setup_course_partitions(scheme_id='cohort', is_cohorted=True)

        cohorts = []
        for group_id in [0, 1]:
            getattr(self, content_creator_method_name)(group_id)

            cohorts.append(
                CohortFactory(course_id=self.course.id,
                              name=u"Cohort " + unicode(group_id)))
            link = CourseUserGroupPartitionGroup(
                course_user_group=cohorts[group_id],
                partition_id=self.partition_id,
                group_id=group_id,
            )
            link.save()

        for cohort_index in range(len(cohorts)):
            # add user to this cohort
            add_user_to_cohort(cohorts[cohort_index], self.user.username)

            # should only see video for this cohort
            video_outline = self.api_response(api_version=api_version).data
            self.assertEqual(len(video_outline), 1)
            self.assertEquals(u"video for group " + unicode(cohort_index),
                              video_outline[0]["summary"]["name"])

            # remove user from this cohort
            remove_user_from_cohort(cohorts[cohort_index], self.user.username)

        # un-cohorted user should see no videos
        video_outline = self.api_response(api_version=api_version).data
        self.assertEqual(len(video_outline), 0)

        # staff user sees all videos
        self.user.is_staff = True
        self.user.save()
        video_outline = self.api_response(api_version=api_version).data
        self.assertEqual(len(video_outline), 2)
示例#25
0
    def test_filter_cohort_id_and_enrollment_mode(self):
        with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as mock_grade:
            mock_grade.return_value = self.mock_course_grade(self.student, passed=True, letter_grade='A', percent=0.85)

            cohort = CohortFactory(course_id=self.course.id, name="TestCohort", users=[self.student])
            with override_waffle_flag(self.waffle_flag, active=True):
                self.login_staff()
                # both of our test users are in the audit track, so this is functionally equivalent
                # to just `?cohort_id=cohort.id`.
                query = '?cohort_id={}&enrollment_mode={}'.format(cohort.id, CourseMode.AUDIT)
                resp = self.client.get(
                    self.get_url(course_key=self.course.id) + query
                )

                expected_results = [
                    OrderedDict([
                        ('course_id', text_type(self.course.id)),
                        ('email', self.student.email),
                        ('user_id', self.student.id),
                        ('username', self.student.username),
                        ('full_name', self.student.get_full_name()),
                        ('passed', True),
                        ('percent', 0.85),
                        ('letter_grade', 'A'),
                        ('progress_page_url', reverse(
                            'student_progress',
                            kwargs=dict(course_id=text_type(self.course.id), student_id=self.student.id)
                        )),
                        ('section_breakdown', self.expected_subsection_grades(letter_grade='A')),
                    ]),
                ]

                self.assertEqual(status.HTTP_200_OK, resp.status_code)
                actual_data = dict(resp.data)
                self.assertIsNone(actual_data['next'])
                self.assertIsNone(actual_data['previous'])
                self.assertEqual(expected_results, actual_data['results'])
示例#26
0
    def test_access_control(self):
        """
        Test that only topics that a user has access to are returned. The
        ways in which a user may not have access are:

        * Module is visible to staff only
        * Module has a start date in the future
        * Module is accessible only to a group the user is not in

        Also, there is a case that ensures that a category with no accessible
        subcategories does not appear in the result.
        """
        beta_tester = BetaTesterFactory.create(course_key=self.course.id)
        staff = StaffFactory.create(course_key=self.course.id)
        for user, group_idx in [(self.user, 0), (beta_tester, 1)]:
            cohort = CohortFactory.create(
                course_id=self.course.id,
                name=self.partition.groups[group_idx].name,
                users=[user]
            )
            CourseUserGroupPartitionGroup.objects.create(
                course_user_group=cohort,
                partition_id=self.partition.id,
                group_id=self.partition.groups[group_idx].id
            )

        self.make_discussion_module("courseware-1", "First", "Everybody")
        self.make_discussion_module(
            "courseware-2",
            "First",
            "Cohort A",
            group_access={self.partition.id: [self.partition.groups[0].id]}
        )
        self.make_discussion_module(
            "courseware-3",
            "First",
            "Cohort B",
            group_access={self.partition.id: [self.partition.groups[1].id]}
        )
        self.make_discussion_module("courseware-4", "Second", "Staff Only", visible_to_staff_only=True)
        self.make_discussion_module(
            "courseware-5",
            "Second",
            "Future Start Date",
            start=datetime.now(UTC) + timedelta(days=1)
        )

        student_actual = self.get_course_topics()
        student_expected = {
            "courseware_topics": [
                self.make_expected_tree(
                    None,
                    "First",
                    [
                        self.make_expected_tree("courseware-2", "Cohort A"),
                        self.make_expected_tree("courseware-1", "Everybody"),
                    ]
                ),
            ],
            "non_courseware_topics": [],
        }
        self.assertEqual(student_actual, student_expected)

        beta_actual = self.get_course_topics(beta_tester)
        beta_expected = {
            "courseware_topics": [
                self.make_expected_tree(
                    None,
                    "First",
                    [
                        self.make_expected_tree("courseware-3", "Cohort B"),
                        self.make_expected_tree("courseware-1", "Everybody"),
                    ]
                ),
                self.make_expected_tree(
                    None,
                    "Second",
                    [self.make_expected_tree("courseware-5", "Future Start Date")]
                ),
            ],
            "non_courseware_topics": [],
        }
        self.assertEqual(beta_actual, beta_expected)

        staff_actual = self.get_course_topics(staff)
        staff_expected = {
            "courseware_topics": [
                self.make_expected_tree(
                    None,
                    "First",
                    [
                        self.make_expected_tree("courseware-2", "Cohort A"),
                        self.make_expected_tree("courseware-3", "Cohort B"),
                        self.make_expected_tree("courseware-1", "Everybody"),
                    ]
                ),
                self.make_expected_tree(
                    None,
                    "Second",
                    [
                        self.make_expected_tree("courseware-5", "Future Start Date"),
                        self.make_expected_tree("courseware-4", "Staff Only"),
                    ]
                ),
            ],
            "non_courseware_topics": [],
        }
        self.assertEqual(staff_actual, staff_expected)
示例#27
0
 def test_group(self):
     cohort = CohortFactory.create(course_id=self.course.id)
     serialized = self.serialize(self.make_cs_content({"group_id": cohort.id}))
     self.assertEqual(serialized["group_id"], cohort.id)
     self.assertEqual(serialized["group_name"], cohort.name)
示例#28
0
    def test_cohort_scheme_partition(self):
        """
        Test that cohort-schemed user partitions are ignored in the
        grades export.
        """
        # Set up a course with 'cohort' and 'random' user partitions.
        cohort_scheme_partition = UserPartition(
            0,
            'Cohort-schemed Group Configuration',
            'Group Configuration based on Cohorts',
            [Group(0, 'Group A'), Group(1, 'Group B')],
            scheme_id='cohort'
        )
        experiment_group_a = Group(2, u'Expériment Group A')
        experiment_group_b = Group(3, u'Expériment Group B')
        experiment_partition = UserPartition(
            1,
            u'Content Expériment Configuration',
            u'Group Configuration for Content Expériments',
            [experiment_group_a, experiment_group_b],
            scheme_id='random'
        )
        course = CourseFactory.create(
            cohort_config={'cohorted': True},
            user_partitions=[cohort_scheme_partition, experiment_partition]
        )

        # Create user_a and user_b which are enrolled in the course
        # and assigned to experiment_group_a and experiment_group_b,
        # respectively.
        user_a = UserFactory.create(username='******')
        user_b = UserFactory.create(username='******')
        CourseEnrollment.enroll(user_a, course.id)
        CourseEnrollment.enroll(user_b, course.id)
        course_tag_api.set_course_tag(
            user_a,
            course.id,
            RandomUserPartitionScheme.key_for_partition(experiment_partition),
            experiment_group_a.id
        )
        course_tag_api.set_course_tag(
            user_b,
            course.id,
            RandomUserPartitionScheme.key_for_partition(experiment_partition),
            experiment_group_b.id
        )

        # Assign user_a to a group in the 'cohort'-schemed user
        # partition (by way of a cohort) to verify that the user
        # partition group does not show up in the "Experiment Group"
        # cell.
        cohort_a = CohortFactory.create(course_id=course.id, name=u'Cohørt A', users=[user_a])
        CourseUserGroupPartitionGroup(
            course_user_group=cohort_a,
            partition_id=cohort_scheme_partition.id,
            group_id=cohort_scheme_partition.groups[0].id
        ).save()

        # Verify that we see user_a and user_b in their respective
        # content experiment groups, and that we do not see any
        # content groups.
        experiment_group_message = u'Experiment Group ({content_experiment})'
        self._verify_cell_data_for_user(
            user_a.username,
            course.id,
            experiment_group_message.format(
                content_experiment=experiment_partition.name
            ),
            experiment_group_a.name
        )
        self._verify_cell_data_for_user(
            user_b.username,
            course.id,
            experiment_group_message.format(
                content_experiment=experiment_partition.name
            ),
            experiment_group_b.name
        )

        # Make sure cohort info is correct.
        cohort_name_header = 'Cohort Name'
        self._verify_cell_data_for_user(
            user_a.username,
            course.id,
            cohort_name_header,
            cohort_a.name
        )
        self._verify_cell_data_for_user(
            user_b.username,
            course.id,
            cohort_name_header,
            ''
        )
示例#29
0
    def setUp(self):
        super(ContentGroupTestCase, self).setUp()

        self.course = CourseFactory.create(
            org='org',
            number='number',
            run='run',
            # This test needs to use a course that has already started --
            # discussion topics only show up if the course has already started,
            # and the default start date for courses is Jan 1, 2030.
            start=datetime(2012, 2, 3, tzinfo=UTC),
            user_partitions=[
                UserPartition(
                    0,
                    'Content Group Configuration',
                    '',
                    [Group(1, 'Alpha'), Group(2, 'Beta')],
                    scheme_id='cohort')
            ],
            grading_policy={
                "GRADER": [{
                    "type": "Homework",
                    "min_count": 1,
                    "drop_count": 0,
                    "short_label": "HW",
                    "weight": 1.0
                }]
            },
            cohort_config={'cohorted': True},
            discussion_topics={})

        self.staff_user = UserFactory.create(is_staff=True)
        self.alpha_user = UserFactory.create()
        self.beta_user = UserFactory.create()
        self.non_cohorted_user = UserFactory.create()
        for user in [
                self.staff_user, self.alpha_user, self.beta_user,
                self.non_cohorted_user
        ]:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)

        alpha_cohort = CohortFactory(course_id=self.course.id,
                                     name='Cohort Alpha',
                                     users=[self.alpha_user])
        beta_cohort = CohortFactory(course_id=self.course.id,
                                    name='Cohort Beta',
                                    users=[self.beta_user])
        CourseUserGroupPartitionGroup.objects.create(
            course_user_group=alpha_cohort,
            partition_id=self.course.user_partitions[0].id,
            group_id=self.course.user_partitions[0].groups[0].id)
        CourseUserGroupPartitionGroup.objects.create(
            course_user_group=beta_cohort,
            partition_id=self.course.user_partitions[0].id,
            group_id=self.course.user_partitions[0].groups[1].id)
        self.alpha_module = ItemFactory.create(
            parent_location=self.course.location,
            category='discussion',
            discussion_id='alpha_group_discussion',
            discussion_target='Visible to Alpha',
            group_access={
                self.course.user_partitions[0].id:
                [self.course.user_partitions[0].groups[0].id]
            })
        self.beta_module = ItemFactory.create(
            parent_location=self.course.location,
            category='discussion',
            discussion_id='beta_group_discussion',
            discussion_target='Visible to Beta',
            group_access={
                self.course.user_partitions[0].id:
                [self.course.user_partitions[0].groups[1].id]
            })
        self.global_module = ItemFactory.create(
            parent_location=self.course.location,
            category='discussion',
            discussion_id='global_group_discussion',
            discussion_target='Visible to Everyone')
        self.course = self.store.get_item(self.course.location)
示例#30
0
 def test_group(self):
     cohort = CohortFactory.create(course_id=self.course.id)
     serialized = self.serialize(
         self.make_cs_content({"group_id": cohort.id}))
     self.assertEqual(serialized["group_id"], cohort.id)
     self.assertEqual(serialized["group_name"], cohort.name)
示例#31
0
 def create_cohort(self, users):
     cohort = CohortFactory.create(
         course_id=self.course.id,
         users=users,
     )
     return cohort
示例#32
0
 def setUp(self):
     super(UniversityIDViewStudentTestCase, self).setUp()
     set_course_cohorted(self.course.id, cohorted=True)
     self.cohort = CohortFactory.create(course_id=self.course.id)
     self.url = reverse('edraak_university:id',
                        args=[unicode(self.course.id)])
示例#33
0
    def test_access_control(self):
        """
        Test that only topics that a user has access to are returned. The
        ways in which a user may not have access are:

        * Module is visible to staff only
        * Module has a start date in the future
        * Module is accessible only to a group the user is not in

        Also, there is a case that ensures that a category with no accessible
        subcategories does not appear in the result.
        """
        beta_tester = BetaTesterFactory.create(course_key=self.course.id)
        CourseEnrollmentFactory.create(user=beta_tester, course_id=self.course.id)
        staff = StaffFactory.create(course_key=self.course.id)
        for user, group_idx in [(self.user, 0), (beta_tester, 1)]:
            cohort = CohortFactory.create(
                course_id=self.course.id,
                name=self.partition.groups[group_idx].name,
                users=[user]
            )
            CourseUserGroupPartitionGroup.objects.create(
                course_user_group=cohort,
                partition_id=self.partition.id,
                group_id=self.partition.groups[group_idx].id
            )

        self.make_discussion_module("courseware-1", "First", "Everybody")
        self.make_discussion_module(
            "courseware-2",
            "First",
            "Cohort A",
            group_access={self.partition.id: [self.partition.groups[0].id]}
        )
        self.make_discussion_module(
            "courseware-3",
            "First",
            "Cohort B",
            group_access={self.partition.id: [self.partition.groups[1].id]}
        )
        self.make_discussion_module("courseware-4", "Second", "Staff Only", visible_to_staff_only=True)
        self.make_discussion_module(
            "courseware-5",
            "Second",
            "Future Start Date",
            start=datetime.now(UTC) + timedelta(days=1)
        )

        student_actual = self.get_course_topics()
        student_expected = {
            "courseware_topics": [
                self.make_expected_tree(
                    None,
                    "First",
                    [
                        self.make_expected_tree("courseware-2", "Cohort A"),
                        self.make_expected_tree("courseware-1", "Everybody"),
                    ]
                ),
            ],
            "non_courseware_topics": [
                self.make_expected_tree("non-courseware-topic-id", "Test Topic"),
            ],
        }
        self.assertEqual(student_actual, student_expected)

        beta_actual = self.get_course_topics(beta_tester)
        beta_expected = {
            "courseware_topics": [
                self.make_expected_tree(
                    None,
                    "First",
                    [
                        self.make_expected_tree("courseware-3", "Cohort B"),
                        self.make_expected_tree("courseware-1", "Everybody"),
                    ]
                ),
                self.make_expected_tree(
                    None,
                    "Second",
                    [self.make_expected_tree("courseware-5", "Future Start Date")]
                ),
            ],
            "non_courseware_topics": [
                self.make_expected_tree("non-courseware-topic-id", "Test Topic"),
            ],
        }
        self.assertEqual(beta_actual, beta_expected)

        staff_actual = self.get_course_topics(staff)
        staff_expected = {
            "courseware_topics": [
                self.make_expected_tree(
                    None,
                    "First",
                    [
                        self.make_expected_tree("courseware-2", "Cohort A"),
                        self.make_expected_tree("courseware-3", "Cohort B"),
                        self.make_expected_tree("courseware-1", "Everybody"),
                    ]
                ),
                self.make_expected_tree(
                    None,
                    "Second",
                    [
                        self.make_expected_tree("courseware-5", "Future Start Date"),
                        self.make_expected_tree("courseware-4", "Staff Only"),
                    ]
                ),
            ],
            "non_courseware_topics": [
                self.make_expected_tree("non-courseware-topic-id", "Test Topic"),
            ],
        }
        self.assertEqual(staff_actual, staff_expected)
示例#34
0
    def test_cohort_scheme_partition(self):
        """
        Test that cohort-schemed user partitions are ignored in the
        grades export.
        """
        # Set up a course with 'cohort' and 'random' user partitions.
        cohort_scheme_partition = UserPartition(
            0,
            'Cohort-schemed Group Configuration',
            'Group Configuration based on Cohorts',
            [Group(0, 'Group A'), Group(1, 'Group B')],
            scheme_id='cohort'
        )
        experiment_group_a = Group(2, u'Expériment Group A')
        experiment_group_b = Group(3, u'Expériment Group B')
        experiment_partition = UserPartition(
            1,
            u'Content Expériment Configuration',
            u'Group Configuration for Content Expériments',
            [experiment_group_a, experiment_group_b],
            scheme_id='random'
        )
        course = CourseFactory.create(
            cohort_config={'cohorted': True},
            user_partitions=[cohort_scheme_partition, experiment_partition]
        )

        # Create user_a and user_b which are enrolled in the course
        # and assigned to experiment_group_a and experiment_group_b,
        # respectively.
        user_a = UserFactory.create(username='******')
        user_b = UserFactory.create(username='******')
        CourseEnrollment.enroll(user_a, course.id)
        CourseEnrollment.enroll(user_b, course.id)
        course_tag_api.set_course_tag(
            user_a,
            course.id,
            RandomUserPartitionScheme.key_for_partition(experiment_partition),
            experiment_group_a.id
        )
        course_tag_api.set_course_tag(
            user_b,
            course.id,
            RandomUserPartitionScheme.key_for_partition(experiment_partition),
            experiment_group_b.id
        )

        # Assign user_a to a group in the 'cohort'-schemed user
        # partition (by way of a cohort) to verify that the user
        # partition group does not show up in the "Experiment Group"
        # cell.
        cohort_a = CohortFactory.create(course_id=course.id, name=u'Cohørt A', users=[user_a])
        CourseUserGroupPartitionGroup(
            course_user_group=cohort_a,
            partition_id=cohort_scheme_partition.id,
            group_id=cohort_scheme_partition.groups[0].id
        ).save()

        # Verify that we see user_a and user_b in their respective
        # content experiment groups, and that we do not see any
        # content groups.
        experiment_group_message = u'Experiment Group ({content_experiment})'
        self._verify_cell_data_for_user(
            user_a.username,
            course.id,
            experiment_group_message.format(
                content_experiment=experiment_partition.name
            ),
            experiment_group_a.name
        )
        self._verify_cell_data_for_user(
            user_b.username,
            course.id,
            experiment_group_message.format(
                content_experiment=experiment_partition.name
            ),
            experiment_group_b.name
        )

        # Make sure cohort info is correct.
        cohort_name_header = 'Cohort Name'
        self._verify_cell_data_for_user(
            user_a.username,
            course.id,
            cohort_name_header,
            cohort_a.name
        )
        self._verify_cell_data_for_user(
            user_b.username,
            course.id,
            cohort_name_header,
            ''
        )