Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-ora2
Commits
62f015bb
Commit
62f015bb
authored
May 13, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #330 from edx/will/opaque-keys
Handle opaque keys in a backwards-compatible way
parents
d96edce9
697cc77a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
3 deletions
+58
-3
apps/openassessment/xblock/openassessmentblock.py
+24
-3
apps/openassessment/xblock/test/test_opaque_keys.py
+34
-0
No files found.
apps/openassessment/xblock/openassessmentblock.py
View file @
62f015bb
...
...
@@ -149,13 +149,14 @@ class OpenAssessmentBlock(
(dict): The student item associated with this XBlock instance. This
includes the student id, item id, and course id.
"""
item_id
=
unicode
(
self
.
scope_ids
.
usage_id
)
item_id
=
self
.
_serialize_opaque_key
(
self
.
scope_ids
.
usage_id
)
# This is not the real way course_ids should work, but this is a
# temporary expediency for LMS integration
if
hasattr
(
self
,
"xmodule_runtime"
):
course_id
=
unicode
(
self
.
xmodule_runtime
.
course_id
)
student_id
=
self
.
xmodule_runtime
.
anonymous_student_id
course_id
=
self
.
_serialize_opaque_key
(
self
.
xmodule_runtime
.
course_id
)
# pylint:disable=E1101
student_id
=
self
.
xmodule_runtime
.
anonymous_student_id
# pylint:disable=E1101
else
:
course_id
=
"edX/Enchantment_101/April_1"
if
self
.
scope_ids
.
user_id
is
None
:
...
...
@@ -504,3 +505,23 @@ class OpenAssessmentBlock(
for
assessment
in
self
.
rubric_assessments
:
if
assessment
[
"name"
]
==
mixin_name
:
return
assessment
def
_serialize_opaque_key
(
self
,
key
):
"""
Gracefully handle opaque keys, both before and after the transition.
https://github.com/edx/edx-platform/wiki/Opaque-Keys
Currently uses `to_deprecated_string()` to ensure that new keys
are backwards-compatible with keys we store in ORA2 database models.
Args:
key (unicode or OpaqueKey subclass): The key to serialize.
Returns:
unicode
"""
if
hasattr
(
key
,
'to_deprecated_string'
):
return
key
.
to_deprecated_string
()
else
:
return
unicode
(
key
)
apps/openassessment/xblock/test/test_opaque_keys.py
0 → 100644
View file @
62f015bb
# -*- coding: utf-8 -*-
"""
Tests for opaque key transition in the LMS runtime.
See https://github.com/edx/edx-platform/wiki/Opaque-Keys
"""
import
mock
from
.base
import
XBlockHandlerTestCase
,
scenario
class
TestOpaqueKeys
(
XBlockHandlerTestCase
):
"""
Test that the XBlock handles the opaque key transition gracefully.
"""
@scenario
(
'data/basic_scenario.xml'
,
user_id
=
'Bob'
)
def
test_opaque_key_deprecated_string
(
self
,
xblock
):
# Simulate the opaque key changeover by
# providing a mock `to_deprecated_string()` method.
usage_key
=
mock
.
MagicMock
()
usage_key
.
to_deprecated_string
.
return_value
=
u"เՇє๓ เ๔"
course_key
=
mock
.
MagicMock
()
course_key
.
to_deprecated_string
.
return_value
=
u"¢συяѕє ι∂"
xblock
.
scope_ids
=
mock
.
MagicMock
()
xblock
.
scope_ids
.
usage_id
=
usage_key
xblock
.
xmodule_runtime
=
mock
.
MagicMock
()
xblock
.
xmodule_runtime
.
course_id
=
course_key
student_item
=
xblock
.
get_student_item_dict
()
# Expect that we correctly serialize the opaque keys
self
.
assertEqual
(
student_item
[
'item_id'
],
u"เՇє๓ เ๔"
)
self
.
assertEqual
(
student_item
[
'course_id'
],
u"¢συяѕє ι∂"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment