当前位置: 首页>>代码示例>>Python>>正文


Python helpers.CohortFactory类代码示例

本文整理汇总了Python中openedx.core.djangoapps.course_groups.tests.helpers.CohortFactory的典型用法代码示例。如果您正苦于以下问题:Python CohortFactory类的具体用法?Python CohortFactory怎么用?Python CohortFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CohortFactory类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

    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)
开发者ID:kotky,项目名称:edx-platform,代码行数:29,代码来源:utils.py

示例2: test_request_group

 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)
开发者ID:unicri,项目名称:edx-platform,代码行数:9,代码来源:test_api.py

示例3: test_enrolled_students_features_keys_cohorted

    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='test')

        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]')
开发者ID:luisvasq,项目名称:edx-platform,代码行数:30,代码来源:test_basic.py

示例4: test_group

 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)
开发者ID:jolyonb,项目名称:edx-platform,代码行数:7,代码来源:test_serializers.py

示例5: test_group_access

 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)
开发者ID:fjardon,项目名称:edx-platform,代码行数:26,代码来源:test_api.py

示例6: setUp

    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]
        )
开发者ID:edx,项目名称:edx-platform,代码行数:19,代码来源:utils.py

示例7: setUp

 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)
开发者ID:happymark001,项目名称:edx-platform,代码行数:13,代码来源:test_api.py

示例8: _set_up_course

 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)
开发者ID:10clouds,项目名称:edx-platform,代码行数:20,代码来源:tests.py

示例9: test_access_control

    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",
                    [
#.........这里部分代码省略.........
开发者ID:unicri,项目名称:edx-platform,代码行数:101,代码来源:test_api.py

示例10: test_group

 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)
开发者ID:HowestX,项目名称:edx-platform,代码行数:5,代码来源:test_serializers.py

示例11: test_cohort_scheme_partition

    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_a')
        user_b = UserFactory.create(username='user_b')
        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,
            ''
        )
开发者ID:alexmerser,项目名称:lms,代码行数:93,代码来源:test_tasks_helper.py


注:本文中的openedx.core.djangoapps.course_groups.tests.helpers.CohortFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。