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


Python DjangoXBlockUserStateClient.set方法代码示例

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


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

示例1: test_submission_history_contents

# 需要导入模块: from courseware.user_state_client import DjangoXBlockUserStateClient [as 别名]
# 或者: from courseware.user_state_client.DjangoXBlockUserStateClient import set [as 别名]
    def test_submission_history_contents(self):
        # log into a staff account
        admin = AdminFactory.create()

        self.client.login(username=admin.username, password='test')

        usage_key = self.course_key.make_usage_key('problem', 'test-history')
        state_client = DjangoXBlockUserStateClient(admin)

        # store state via the UserStateClient
        state_client.set(
            username=admin.username,
            block_key=usage_key,
            state={'field_a': 'x', 'field_b': 'y'}
        )

        set_score(admin.id, usage_key, 0, 3)

        state_client.set(
            username=admin.username,
            block_key=usage_key,
            state={'field_a': 'a', 'field_b': 'b'}
        )
        set_score(admin.id, usage_key, 3, 3)

        url = reverse('submission_history', kwargs={
            'course_id': unicode(self.course_key),
            'student_username': admin.username,
            'location': unicode(usage_key),
        })
        response = self.client.get(url)
        response_content = HTMLParser().unescape(response.content)

        # We have update the state 4 times: twice to change content, and twice
        # to set the scores. We'll check that the identifying content from each is
        # displayed (but not the order), and also the indexes assigned in the output
        # #1 - #4

        self.assertIn('#1', response_content)
        self.assertIn(json.dumps({'field_a': 'a', 'field_b': 'b'}, sort_keys=True, indent=2), response_content)
        self.assertIn("Score: 0.0 / 3.0", response_content)
        self.assertIn(json.dumps({'field_a': 'x', 'field_b': 'y'}, sort_keys=True, indent=2), response_content)
        self.assertIn("Score: 3.0 / 3.0", response_content)
        self.assertIn('#4', response_content)
开发者ID:adoosii,项目名称:edx-platform,代码行数:46,代码来源:test_views.py


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