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


Python SlashSeparatedCourseKey.replace方法代码示例

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


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

示例1: test_invalid_chars_ssck

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import replace [as 别名]
 def test_invalid_chars_ssck(self):
     """
     Test that the ssck constructor fails if given invalid chars
     """
     valid_base = SlashSeparatedCourseKey(u'org.dept-1%2', u'course.sub-2%3', u'run.faster-4%5')
     for key in SlashSeparatedCourseKey.KEY_FIELDS:
         with self.assertRaises(InvalidKeyError):
             # this ends up calling the constructor where the legality check should occur
             valid_base.replace(**{key: u'funny thing'})
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:11,代码来源:test_location.py

示例2: TestUsersDefaultRole

# 需要导入模块: from xmodule.modulestore.locations import SlashSeparatedCourseKey [as 别名]
# 或者: from xmodule.modulestore.locations.SlashSeparatedCourseKey import replace [as 别名]
class TestUsersDefaultRole(ModuleStoreTestCase):
    """
    Unit tests for checking enrollment and default forum role "Student" of a logged in user
    """
    def setUp(self):
        """
        Add a user and a course
        """
        super(TestUsersDefaultRole, self).setUp()
        # create and log in a staff user.
        self.user = UserFactory(is_staff=True)  # pylint: disable=no-member
        self.client = AjaxEnabledTestClient()
        self.client.login(username=self.user.username, password='test')

        # create a course via the view handler to create course
        self.course_key = SlashSeparatedCourseKey('Org_1', 'Course_1', 'Run_1')
        self._create_course_with_given_location(self.course_key)

    def _create_course_with_given_location(self, course_key):
        """
        Create course at provided location
        """
        resp = self.client.ajax_post(
            reverse_url('course_handler'),
            {
                'org': course_key.org,
                'number': course_key.course,
                'display_name': 'test course',
                'run': course_key.run,
            }
        )
        return resp

    def tearDown(self):
        """
        Reverse the setup
        """
        self.client.logout()
        super(TestUsersDefaultRole, self).tearDown()

    def test_user_forum_default_role_on_course_deletion(self):
        """
        Test that a user enrolls and gets "Student" forum role for that course which he creates and remains
        enrolled even the course is deleted and keeps its "Student" forum role for that course
        """
        # check that user has enrollment for this course
        self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key))

        # check that user has his default "Student" forum role for this course
        self.assertTrue(self.user.roles.filter(name="Student", course_id=self.course_key))  # pylint: disable=no-member

        delete_course_and_groups(self.course_key, commit=True)

        # check that user's enrollment for this course is not deleted
        self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key))

        # check that user has forum role for this course even after deleting it
        self.assertTrue(self.user.roles.filter(name="Student", course_id=self.course_key))  # pylint: disable=no-member

    def test_user_role_on_course_recreate(self):
        """
        Test that creating same course again after deleting it gives user his default
        forum role "Student" for that course
        """
        # check that user has enrollment and his default "Student" forum role for this course
        self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key))
        self.assertTrue(self.user.roles.filter(name="Student", course_id=self.course_key))  # pylint: disable=no-member

        # delete this course and recreate this course with same user
        delete_course_and_groups(self.course_key, commit=True)
        resp = self._create_course_with_given_location(self.course_key)
        self.assertEqual(resp.status_code, 200)

        # check that user has his enrollment for this course
        self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key))

        # check that user has his default "Student" forum role for this course
        self.assertTrue(self.user.roles.filter(name="Student", course_id=self.course_key))  # pylint: disable=no-member

    def test_user_role_on_course_recreate_with_change_name_case(self):
        """
        Test that creating same course again with different name case after deleting it gives user
        his default forum role "Student" for that course
        """
        # check that user has enrollment and his default "Student" forum role for this course
        self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key))
        # delete this course and recreate this course with same user
        delete_course_and_groups(self.course_key, commit=True)

        # now create same course with different name case ('uppercase')
        new_course_key = self.course_key.replace(course=self.course_key.course.upper())
        resp = self._create_course_with_given_location(new_course_key)
        self.assertEqual(resp.status_code, 200)

        # check that user has his default "Student" forum role again for this course (with changed name case)
        self.assertTrue(
            self.user.roles.filter(name="Student", course_id=new_course_key)  # pylint: disable=no-member
        )
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:100,代码来源:test_users_default_role.py


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