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


Python StaffFactory.create方法代码示例

本文整理汇总了Python中courseware.tests.factories.StaffFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python StaffFactory.create方法的具体用法?Python StaffFactory.create怎么用?Python StaffFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在courseware.tests.factories.StaffFactory的用法示例。


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

示例1: test_access_on_course_with_pre_requisites

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def test_access_on_course_with_pre_requisites(self):
        """
        Test course access when a course has pre-requisite course yet to be completed
        """
        user = UserFactory.create()

        pre_requisite_course = CourseFactory.create(
            org='test_org', number='788', run='test_run'
        )

        pre_requisite_courses = [unicode(pre_requisite_course.id)]
        course = CourseFactory.create(
            org='test_org', number='786', run='test_run', pre_requisite_courses=pre_requisite_courses
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        # user should not be able to load course even if enrolled
        CourseEnrollmentFactory(user=user, course_id=course.id)
        response = access._has_access_course(user, 'load', course)
        self.assertFalse(response)
        self.assertIsInstance(response, access_response.MilestoneAccessError)
        # Staff can always access course
        staff = StaffFactory.create(course_key=course.id)
        self.assertTrue(access._has_access_course(staff, 'load', course))

        # User should be able access after completing required course
        fulfill_course_milestone(pre_requisite_course.id, user)
        self.assertTrue(access._has_access_course(user, 'load', course))
开发者ID:luisvasq,项目名称:edx-platform,代码行数:30,代码来源:test_access.py

示例2: test_access_on_course_with_pre_requisites

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def test_access_on_course_with_pre_requisites(self):
        """
        Test course access when a course has pre-requisite course yet to be completed
        """
        seed_milestone_relationship_types()
        user = UserFactory.create()

        pre_requisite_course = CourseFactory.create(org="test_org", number="788", run="test_run")

        pre_requisite_courses = [unicode(pre_requisite_course.id)]
        course = CourseFactory.create(
            org="test_org", number="786", run="test_run", pre_requisite_courses=pre_requisite_courses
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        # user should not be able to load course even if enrolled
        CourseEnrollmentFactory(user=user, course_id=course.id)
        response = access._has_access_course_desc(user, "view_courseware_with_prerequisites", course)
        self.assertFalse(response)
        self.assertIsInstance(response, access_response.MilestoneError)
        # Staff can always access course
        staff = StaffFactory.create(course_key=course.id)
        self.assertTrue(access._has_access_course_desc(staff, "view_courseware_with_prerequisites", course))

        # User should be able access after completing required course
        fulfill_course_milestone(pre_requisite_course.id, user)
        self.assertTrue(access._has_access_course_desc(user, "view_courseware_with_prerequisites", course))
开发者ID:johnny-nan,项目名称:edx-platform,代码行数:29,代码来源:test_access.py

示例3: test__catalog_visibility

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def test__catalog_visibility(self):
        """
        Tests the catalog visibility tri-states
        """
        user = UserFactory.create()
        course_id = SlashSeparatedCourseKey("edX", "test", "2012_Fall")
        staff = StaffFactory.create(course_key=course_id)

        course = Mock(id=course_id, catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT)
        self.assertTrue(access._has_access_course_desc(user, "see_in_catalog", course))
        self.assertTrue(access._has_access_course_desc(user, "see_about_page", course))
        self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course))
        self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course))

        # Now set visibility to just about page
        course = Mock(
            id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), catalog_visibility=CATALOG_VISIBILITY_ABOUT
        )
        self.assertFalse(access._has_access_course_desc(user, "see_in_catalog", course))
        self.assertTrue(access._has_access_course_desc(user, "see_about_page", course))
        self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course))
        self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course))

        # Now set visibility to none, which means neither in catalog nor about pages
        course = Mock(
            id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"), catalog_visibility=CATALOG_VISIBILITY_NONE
        )
        self.assertFalse(access._has_access_course_desc(user, "see_in_catalog", course))
        self.assertFalse(access._has_access_course_desc(user, "see_about_page", course))
        self.assertTrue(access._has_access_course_desc(staff, "see_in_catalog", course))
        self.assertTrue(access._has_access_course_desc(staff, "see_about_page", course))
开发者ID:johnny-nan,项目名称:edx-platform,代码行数:33,代码来源:test_access.py

示例4: setUp

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def setUp(self):
        super(TeamAPITestCase, self).setUp()
        self.topics_count = 4
        self.users = {
            "student_unenrolled": UserFactory.create(password=self.test_password),
            "student_enrolled": UserFactory.create(password=self.test_password),
            "student_enrolled_not_on_team": UserFactory.create(password=self.test_password),
            # This student is enrolled in both test courses and is a member of a team in each course, but is not on the
            # same team as student_enrolled.
            "student_enrolled_both_courses_other_team": UserFactory.create(password=self.test_password),
            "staff": AdminFactory.create(password=self.test_password),
            "course_staff": StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password),
        }
        # 'solar team' is intentionally lower case to test case insensitivity in name ordering
        self.test_team_1 = CourseTeamFactory.create(
            name=u"sólar team", course_id=self.test_course_1.id, topic_id="topic_0"
        )
        self.test_team_2 = CourseTeamFactory.create(name="Wind Team", course_id=self.test_course_1.id)
        self.test_team_3 = CourseTeamFactory.create(name="Nuclear Team", course_id=self.test_course_1.id)
        self.test_team_4 = CourseTeamFactory.create(name="Coal Team", course_id=self.test_course_1.id, is_active=False)
        self.test_team_5 = CourseTeamFactory.create(name="Another Team", course_id=self.test_course_2.id)

        for user, course in [
            ("student_enrolled", self.test_course_1),
            ("student_enrolled_not_on_team", self.test_course_1),
            ("student_enrolled_both_courses_other_team", self.test_course_1),
            ("student_enrolled_both_courses_other_team", self.test_course_2),
        ]:
            CourseEnrollment.enroll(self.users[user], course.id, check_access=True)

        self.test_team_1.add_user(self.users["student_enrolled"])
        self.test_team_3.add_user(self.users["student_enrolled_both_courses_other_team"])
        self.test_team_5.add_user(self.users["student_enrolled_both_courses_other_team"])
开发者ID:rimolive,项目名称:edx-platform,代码行数:35,代码来源:test_views.py

示例5: setUp

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def setUp(self):
        super(TeamAPITestCase, self).setUp()

        teams_configuration = {
            'topics':
            [
                {
                    'id': 'topic_{}'.format(i),
                    'name': name,
                    'description': 'Description for topic {}.'.format(i)
                } for i, name in enumerate([u'sólar power', 'Wind Power', 'Nuclear Power', 'Coal Power'])
            ]
        }
        self.topics_count = 4

        self.test_course_1 = CourseFactory.create(
            org='TestX',
            course='TS101',
            display_name='Test Course',
            teams_configuration=teams_configuration
        )
        self.test_course_2 = CourseFactory.create(org='MIT', course='6.002x', display_name='Circuits')

        self.users = {
            'student_unenrolled': UserFactory.create(password=self.test_password),
            'student_enrolled': UserFactory.create(password=self.test_password),
            'student_enrolled_not_on_team': UserFactory.create(password=self.test_password),

            # This student is enrolled in both test courses and is a member of a team in each course, but is not on the
            # same team as student_enrolled.
            'student_enrolled_both_courses_other_team': UserFactory.create(password=self.test_password),

            'staff': AdminFactory.create(password=self.test_password),
            'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password)
        }
        # 'solar team' is intentionally lower case to test case insensitivity in name ordering
        self.test_team_1 = CourseTeamFactory.create(
            name=u'sólar team',
            course_id=self.test_course_1.id,
            topic_id='topic_0'
        )
        self.test_team_2 = CourseTeamFactory.create(name='Wind Team', course_id=self.test_course_1.id)
        self.test_team_3 = CourseTeamFactory.create(name='Nuclear Team', course_id=self.test_course_1.id)
        self.test_team_4 = CourseTeamFactory.create(name='Coal Team', course_id=self.test_course_1.id, is_active=False)
        self.test_team_5 = CourseTeamFactory.create(name='Another Team', course_id=self.test_course_2.id)

        for user, course in [
                ('student_enrolled', self.test_course_1),
                ('student_enrolled_not_on_team', self.test_course_1),
                ('student_enrolled_both_courses_other_team', self.test_course_1),
                ('student_enrolled_both_courses_other_team', self.test_course_2)
        ]:
            CourseEnrollment.enroll(
                self.users[user], course.id, check_access=True
            )

        self.test_team_1.add_user(self.users['student_enrolled'])
        self.test_team_3.add_user(self.users['student_enrolled_both_courses_other_team'])
        self.test_team_5.add_user(self.users['student_enrolled_both_courses_other_team'])
开发者ID:jaags,项目名称:edx-platform,代码行数:61,代码来源:test_views.py

示例6: test_courseware_page_access_with_staff_user_after_passing_entrance_exam

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
 def test_courseware_page_access_with_staff_user_after_passing_entrance_exam(self):
     """
     Test courseware access page after passing entrance exam but with staff user
     """
     self.logout()
     staff_user = StaffFactory.create(course_key=self.course.id)
     self.login(staff_user.email, 'test')
     CourseEnrollmentFactory(user=staff_user, course_id=self.course.id)
     self._assert_chapter_loaded(self.course, self.chapter)
开发者ID:10clouds,项目名称:edx-platform,代码行数:11,代码来源:test_entrance_exam.py

示例7: test__has_access_course_desc_can_enroll

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def test__has_access_course_desc_can_enroll(self):
        yesterday = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1)
        tomorrow = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1)

        # Non-staff can enroll if authenticated and specifically allowed for that course
        # even outside the open enrollment period
        user = UserFactory.create()
        course = Mock(
            enrollment_start=tomorrow,
            enrollment_end=tomorrow,
            id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"),
            enrollment_domain="",
        )
        CourseEnrollmentAllowedFactory(email=user.email, course_id=course.id)
        self.assertTrue(access._has_access_course_desc(user, "enroll", course))

        # Staff can always enroll even outside the open enrollment period
        user = StaffFactory.create(course_key=course.id)
        self.assertTrue(access._has_access_course_desc(user, "enroll", course))

        # Non-staff cannot enroll if it is between the start and end dates and invitation only
        # and not specifically allowed
        course = Mock(
            enrollment_start=yesterday,
            enrollment_end=tomorrow,
            id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"),
            enrollment_domain="",
            invitation_only=True,
        )
        user = UserFactory.create()
        self.assertFalse(access._has_access_course_desc(user, "enroll", course))

        # Non-staff can enroll if it is between the start and end dates and not invitation only
        course = Mock(
            enrollment_start=yesterday,
            enrollment_end=tomorrow,
            id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"),
            enrollment_domain="",
            invitation_only=False,
        )
        self.assertTrue(access._has_access_course_desc(user, "enroll", course))

        # Non-staff cannot enroll outside the open enrollment period if not specifically allowed
        course = Mock(
            enrollment_start=tomorrow,
            enrollment_end=tomorrow,
            id=SlashSeparatedCourseKey("edX", "test", "2012_Fall"),
            enrollment_domain="",
            invitation_only=False,
        )
        self.assertFalse(access._has_access_course_desc(user, "enroll", course))
开发者ID:johnny-nan,项目名称:edx-platform,代码行数:53,代码来源:test_access.py

示例8: setUp

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
 def setUp(self):
     """
     Creates a test course ID, mocks the runtime, and creates a fake storage
     engine for use in all tests
     """
     super(StaffGradedAssignmentXblockTests, self).setUp()
     self.course = CourseFactory.create(org='foo', number='bar', display_name='baz')
     self.descriptor = ItemFactory(category="pure", parent=self.course)
     self.course_id = self.course.id
     self.instructor = StaffFactory.create(course_key=self.course_id)
     self.student_data = mock.Mock()
     self.staff = AdminFactory.create(password="test")
     self.runtime = self.make_runtime()
     self.scope_ids = self.make_scope_ids(self.runtime)
开发者ID:doctoryes,项目名称:edx-sga,代码行数:16,代码来源:integration_tests.py

示例9: setUp

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def setUp(self):
        super(TeamAPITestCase, self).setUp()
        self.topics_count = 4
        self.users = {
            'staff': AdminFactory.create(password=self.test_password),
            'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password)
        }
        self.create_and_enroll_student(username='student_enrolled')
        self.create_and_enroll_student(username='student_enrolled_not_on_team')
        self.create_and_enroll_student(username='student_unenrolled', courses=[])

        # Make this student a community TA.
        self.create_and_enroll_student(username='community_ta')
        seed_permissions_roles(self.test_course_1.id)
        community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id)
        community_ta_role.users.add(self.users['community_ta'])

        # This student is enrolled in both test courses and is a member of a team in each course, but is not on the
        # same team as student_enrolled.
        self.create_and_enroll_student(
            courses=[self.test_course_1, self.test_course_2],
            username='student_enrolled_both_courses_other_team'
        )

        # 'solar team' is intentionally lower case to test case insensitivity in name ordering
        self.test_team_1 = CourseTeamFactory.create(
            name=u'sólar team',
            course_id=self.test_course_1.id,
            topic_id='topic_0'
        )
        self.test_team_2 = CourseTeamFactory.create(name='Wind Team', course_id=self.test_course_1.id)
        self.test_team_3 = CourseTeamFactory.create(name='Nuclear Team', course_id=self.test_course_1.id)
        self.test_team_4 = CourseTeamFactory.create(name='Coal Team', course_id=self.test_course_1.id, is_active=False)
        self.test_team_5 = CourseTeamFactory.create(name='Another Team', course_id=self.test_course_2.id)

        for user, course in [
                ('staff', self.test_course_1),
                ('course_staff', self.test_course_1),
        ]:
            CourseEnrollment.enroll(
                self.users[user], course.id, check_access=True
            )

        self.test_team_1.add_user(self.users['student_enrolled'])
        self.test_team_3.add_user(self.users['student_enrolled_both_courses_other_team'])
        self.test_team_5.add_user(self.users['student_enrolled_both_courses_other_team'])
开发者ID:nagyistoce,项目名称:edx-platform,代码行数:48,代码来源:test_views.py

示例10: test_runtime_user_is_staff

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def test_runtime_user_is_staff(self, is_staff):
        course = CourseFactory.create(org='org', number='bar', display_name='baz')
        descriptor = ItemFactory(category="pure", parent=course)

        staff = StaffFactory.create(course_key=course.id)
        self.runtime, _ = render.get_module_system_for_user(
            staff if is_staff else User.objects.create(),
            self.student_data,
            descriptor,
            course.id,
            mock.Mock(),
            mock.Mock(),
            mock.Mock(),
            course=course
        )
        block = self.make_one()
        assert block.runtime_user_is_staff() is is_staff
开发者ID:doctoryes,项目名称:edx-sga,代码行数:19,代码来源:integration_tests.py

示例11: test__catalog_visibility

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def test__catalog_visibility(self):
        """
        Tests the catalog visibility tri-states
        """
        user = UserFactory.create()
        course_id = CourseLocator('edX', 'test', '2012_Fall')
        staff = StaffFactory.create(course_key=course_id)

        course = Mock(
            id=course_id,
            catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT
        )
        self.assertTrue(access._has_access_course(user, 'see_in_catalog', course))
        self.assertTrue(access._has_access_course(user, 'see_about_page', course))
        self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course))
        self.assertTrue(access._has_access_course(staff, 'see_about_page', course))

        # Now set visibility to just about page
        course = Mock(
            id=CourseLocator('edX', 'test', '2012_Fall'),
            catalog_visibility=CATALOG_VISIBILITY_ABOUT
        )
        self.assertFalse(access._has_access_course(user, 'see_in_catalog', course))
        self.assertTrue(access._has_access_course(user, 'see_about_page', course))
        self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course))
        self.assertTrue(access._has_access_course(staff, 'see_about_page', course))

        # Now set visibility to none, which means neither in catalog nor about pages
        course = Mock(
            id=CourseLocator('edX', 'test', '2012_Fall'),
            catalog_visibility=CATALOG_VISIBILITY_NONE
        )
        self.assertFalse(access._has_access_course(user, 'see_in_catalog', course))
        self.assertFalse(access._has_access_course(user, 'see_about_page', course))
        self.assertTrue(access._has_access_course(staff, 'see_in_catalog', course))
        self.assertTrue(access._has_access_course(staff, 'see_about_page', course))
开发者ID:luisvasq,项目名称:edx-platform,代码行数:38,代码来源:test_access.py

示例12: setUp

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def setUp(self):
        super(TeamAPITestCase, self).setUp()
        self.topics_count = 4
        self.users = {
            "staff": AdminFactory.create(password=self.test_password),
            "course_staff": StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password),
        }
        self.create_and_enroll_student(username="student_enrolled")
        self.create_and_enroll_student(username="student_enrolled_not_on_team")
        self.create_and_enroll_student(username="student_unenrolled", courses=[])

        # Make this student a community TA.
        self.create_and_enroll_student(username="community_ta")
        seed_permissions_roles(self.test_course_1.id)
        community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id)
        community_ta_role.users.add(self.users["community_ta"])

        # This student is enrolled in both test courses and is a member of a team in each course, but is not on the
        # same team as student_enrolled.
        self.create_and_enroll_student(
            courses=[self.test_course_1, self.test_course_2], username="student_enrolled_both_courses_other_team"
        )

        # Make this student have a public profile
        self.create_and_enroll_student(courses=[self.test_course_2], username="student_enrolled_public_profile")
        profile = self.users["student_enrolled_public_profile"].profile
        profile.year_of_birth = 1970
        profile.save()

        # This student is enrolled in the other course, but not yet a member of a team. This is to allow
        # course_2 to use a max_team_size of 1 without breaking other tests on course_1
        self.create_and_enroll_student(
            courses=[self.test_course_2], username="student_enrolled_other_course_not_on_team"
        )

        with skip_signal(
            post_save,
            receiver=course_team_post_save_callback,
            sender=CourseTeam,
            dispatch_uid="teams.signals.course_team_post_save_callback",
        ):
            # 'solar team' is intentionally lower case to test case insensitivity in name ordering
            self.test_team_1 = CourseTeamFactory.create(
                name=u"sólar team", course_id=self.test_course_1.id, topic_id="topic_0"
            )
            self.test_team_2 = CourseTeamFactory.create(name="Wind Team", course_id=self.test_course_1.id)
            self.test_team_3 = CourseTeamFactory.create(name="Nuclear Team", course_id=self.test_course_1.id)
            self.test_team_4 = CourseTeamFactory.create(
                name="Coal Team", course_id=self.test_course_1.id, is_active=False
            )
            self.test_team_5 = CourseTeamFactory.create(name="Another Team", course_id=self.test_course_2.id)
            self.test_team_6 = CourseTeamFactory.create(
                name="Public Profile Team", course_id=self.test_course_2.id, topic_id="topic_6"
            )
            self.test_team_7 = CourseTeamFactory.create(
                name="Search",
                description="queryable text",
                country="GS",
                language="to",
                course_id=self.test_course_2.id,
                topic_id="topic_7",
            )

        self.test_team_name_id_map = {
            team.name: team
            for team in (
                self.test_team_1,
                self.test_team_2,
                self.test_team_3,
                self.test_team_4,
                self.test_team_5,
                self.test_team_6,
                self.test_team_7,
            )
        }

        for user, course in [("staff", self.test_course_1), ("course_staff", self.test_course_1)]:
            CourseEnrollment.enroll(self.users[user], course.id, check_access=True)

        self.test_team_1.add_user(self.users["student_enrolled"])
        self.test_team_3.add_user(self.users["student_enrolled_both_courses_other_team"])
        self.test_team_5.add_user(self.users["student_enrolled_both_courses_other_team"])
        self.test_team_6.add_user(self.users["student_enrolled_public_profile"])
开发者ID:J861449197,项目名称:edx-platform,代码行数:85,代码来源:test_views.py

示例13: test_access_control

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    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,代码行数:103,代码来源:test_api.py

示例14: setUp

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def setUp(self):
        super(TeamAPITestCase, self).setUp()
        self.topics_count = 4
        self.users = {
            'staff': AdminFactory.create(password=self.test_password),
            'course_staff': StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password)
        }
        self.create_and_enroll_student(username='student_enrolled')
        self.create_and_enroll_student(username='student_enrolled_not_on_team')
        self.create_and_enroll_student(username='student_unenrolled', courses=[])

        # Make this student a community TA.
        self.create_and_enroll_student(username='community_ta')
        seed_permissions_roles(self.test_course_1.id)
        community_ta_role = Role.objects.get(name=FORUM_ROLE_COMMUNITY_TA, course_id=self.test_course_1.id)
        community_ta_role.users.add(self.users['community_ta'])

        # This student is enrolled in both test courses and is a member of a team in each course, but is not on the
        # same team as student_enrolled.
        self.create_and_enroll_student(
            courses=[self.test_course_1, self.test_course_2],
            username='student_enrolled_both_courses_other_team'
        )

        # Make this student have a public profile
        self.create_and_enroll_student(
            courses=[self.test_course_2],
            username='student_enrolled_public_profile'
        )
        profile = self.users['student_enrolled_public_profile'].profile
        profile.year_of_birth = 1970
        profile.save()

        # This student is enrolled in the other course, but not yet a member of a team. This is to allow
        # course_2 to use a max_team_size of 1 without breaking other tests on course_1
        self.create_and_enroll_student(
            courses=[self.test_course_2],
            username='student_enrolled_other_course_not_on_team'
        )

        # 'solar team' is intentionally lower case to test case insensitivity in name ordering
        self.test_team_1 = CourseTeamFactory.create(
            name=u'sólar team',
            course_id=self.test_course_1.id,
            topic_id='topic_0'
        )
        self.test_team_2 = CourseTeamFactory.create(name='Wind Team', course_id=self.test_course_1.id)
        self.test_team_3 = CourseTeamFactory.create(name='Nuclear Team', course_id=self.test_course_1.id)
        self.test_team_4 = CourseTeamFactory.create(name='Coal Team', course_id=self.test_course_1.id, is_active=False)
        self.test_team_5 = CourseTeamFactory.create(name='Another Team', course_id=self.test_course_2.id)
        self.test_team_6 = CourseTeamFactory.create(
            name='Public Profile Team',
            course_id=self.test_course_2.id,
            topic_id='topic_6'
        )

        self.test_team_name_id_map = {team.name: team for team in (
            self.test_team_1,
            self.test_team_2,
            self.test_team_3,
            self.test_team_4,
            self.test_team_5,
        )}

        for user, course in [('staff', self.test_course_1), ('course_staff', self.test_course_1)]:
            CourseEnrollment.enroll(
                self.users[user], course.id, check_access=True
            )

        self.test_team_1.add_user(self.users['student_enrolled'])
        self.test_team_3.add_user(self.users['student_enrolled_both_courses_other_team'])
        self.test_team_5.add_user(self.users['student_enrolled_both_courses_other_team'])
        self.test_team_6.add_user(self.users['student_enrolled_public_profile'])
开发者ID:vehery,项目名称:edx-platform,代码行数:75,代码来源:test_views.py

示例15: setUp

# 需要导入模块: from courseware.tests.factories import StaffFactory [as 别名]
# 或者: from courseware.tests.factories.StaffFactory import create [as 别名]
    def setUp(self):
        super(GroupAccessTestCase, self).setUp()

        UserPartition.scheme_extensions = ExtensionManager.make_test_instance(
            [
                Extension(
                    "memory",
                    USER_PARTITION_SCHEME_NAMESPACE,
                    MemoryUserPartitionScheme(),
                    None
                ),
                Extension(
                    "random",
                    USER_PARTITION_SCHEME_NAMESPACE,
                    MemoryUserPartitionScheme(),
                    None
                )
            ],
            namespace=USER_PARTITION_SCHEME_NAMESPACE
        )

        self.cat_group = Group(10, 'cats')
        self.dog_group = Group(20, 'dogs')
        self.worm_group = Group(30, 'worms')
        self.animal_partition = UserPartition(
            0,
            'Pet Partition',
            'which animal are you?',
            [self.cat_group, self.dog_group, self.worm_group],
            scheme=UserPartition.get_scheme("memory"),
        )

        self.red_group = Group(1000, 'red')
        self.blue_group = Group(2000, 'blue')
        self.gray_group = Group(3000, 'gray')
        self.color_partition = UserPartition(
            100,
            'Color Partition',
            'what color are you?',
            [self.red_group, self.blue_group, self.gray_group],
            scheme=UserPartition.get_scheme("memory"),
        )

        self.course = CourseFactory.create(
            user_partitions=[self.animal_partition, self.color_partition],
        )
        with self.store.bulk_operations(self.course.id, emit_signals=False):
            chapter = ItemFactory.create(category='chapter', parent=self.course)
            section = ItemFactory.create(category='sequential', parent=chapter)
            vertical = ItemFactory.create(category='vertical', parent=section)
            component = ItemFactory.create(category='problem', parent=vertical)

            self.chapter_location = chapter.location
            self.section_location = section.location
            self.vertical_location = vertical.location
            self.component_location = component.location

        self.red_cat = UserFactory()  # student in red and cat groups
        self.set_user_group(self.red_cat, self.animal_partition, self.cat_group)
        self.set_user_group(self.red_cat, self.color_partition, self.red_group)

        self.blue_dog = UserFactory()  # student in blue and dog groups
        self.set_user_group(self.blue_dog, self.animal_partition, self.dog_group)
        self.set_user_group(self.blue_dog, self.color_partition, self.blue_group)

        self.white_mouse = UserFactory()  # student in no group

        self.gray_worm = UserFactory()  # student in deleted group
        self.set_user_group(self.gray_worm, self.animal_partition, self.worm_group)
        self.set_user_group(self.gray_worm, self.color_partition, self.gray_group)
        # delete the gray/worm groups from the partitions now so we can test scenarios
        # for user whose group is missing.
        self.animal_partition.groups.pop()
        self.color_partition.groups.pop()

        # add a staff user, whose access will be unconditional in spite of group access.
        self.staff = StaffFactory.create(course_key=self.course.id)
开发者ID:10clouds,项目名称:edx-platform,代码行数:79,代码来源:test_group_access.py


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