本文整理匯總了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)