Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lti-xblock-consumer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenJupyter
lti-xblock-consumer
Commits
792940d4
Commit
792940d4
authored
9 years ago
by
Ibrahim
Committed by
Douglas Hall
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix PHX-254 where custom_parameters field is empty by adding field validation
parent
19efe721
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lti_consumer/lti_consumer.py
+22
-16
22 additions, 16 deletions
lti_consumer/lti_consumer.py
lti_consumer/tests/unit/test_lti_consumer.py
+8
-0
8 additions, 0 deletions
lti_consumer/tests/unit/test_lti_consumer.py
with
30 additions
and
16 deletions
lti_consumer/lti_consumer.py
+
22
−
16
View file @
792940d4
...
@@ -64,6 +64,7 @@ from django.utils import timezone
...
@@ -64,6 +64,7 @@ from django.utils import timezone
from
xblock.core
import
String
,
Scope
,
List
,
XBlock
from
xblock.core
import
String
,
Scope
,
List
,
XBlock
from
xblock.fields
import
Boolean
,
Float
,
Integer
from
xblock.fields
import
Boolean
,
Float
,
Integer
from
xblock.fragment
import
Fragment
from
xblock.fragment
import
Fragment
from
xblock.validation
import
ValidationMessage
from
xblockutils.resources
import
ResourceLoader
from
xblockutils.resources
import
ResourceLoader
from
xblockutils.studio_editable
import
StudioEditableXBlockMixin
from
xblockutils.studio_editable
import
StudioEditableXBlockMixin
...
@@ -73,7 +74,6 @@ from .oauth import log_authorization_header
...
@@ -73,7 +74,6 @@ from .oauth import log_authorization_header
from
.lti
import
LtiConsumer
from
.lti
import
LtiConsumer
from
.outcomes
import
OutcomeService
from
.outcomes
import
OutcomeService
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
DOCS_ANCHOR_TAG_OPEN
=
(
DOCS_ANCHOR_TAG_OPEN
=
(
...
@@ -424,6 +424,11 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
...
@@ -424,6 +424,11 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
'
ask_to_send_username
'
,
'
ask_to_send_email
'
'
ask_to_send_username
'
,
'
ask_to_send_email
'
)
)
def
validate_field_data
(
self
,
validation
,
data
):
if
not
isinstance
(
data
.
custom_parameters
,
list
):
_
=
self
.
runtime
.
service
(
self
,
"
i18n
"
).
ugettext
validation
.
add
(
ValidationMessage
(
ValidationMessage
.
ERROR
,
unicode
(
_
(
"
Custom Parameters must be a list
"
))))
@property
@property
def
descriptor
(
self
):
def
descriptor
(
self
):
"""
"""
...
@@ -570,21 +575,22 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
...
@@ -570,21 +575,22 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
# parsing custom parameters to dict
# parsing custom parameters to dict
custom_parameters
=
{}
custom_parameters
=
{}
for
custom_parameter
in
self
.
custom_parameters
:
if
isinstance
(
self
.
custom_parameters
,
list
):
try
:
for
custom_parameter
in
self
.
custom_parameters
:
param_name
,
param_value
=
[
p
.
strip
()
for
p
in
custom_parameter
.
split
(
'
=
'
,
1
)]
try
:
except
ValueError
:
param_name
,
param_value
=
[
p
.
strip
()
for
p
in
custom_parameter
.
split
(
'
=
'
,
1
)]
_
=
self
.
runtime
.
service
(
self
,
"
i18n
"
).
ugettext
except
ValueError
:
msg
=
_
(
'
Could not parse custom parameter: {custom_parameter}. Should be
"
x=y
"
string.
'
).
format
(
_
=
self
.
runtime
.
service
(
self
,
"
i18n
"
).
ugettext
custom_parameter
=
"
{0!r}
"
.
format
(
custom_parameter
)
msg
=
_
(
'
Could not parse custom parameter: {custom_parameter}. Should be
"
x=y
"
string.
'
).
format
(
)
custom_parameter
=
"
{0!r}
"
.
format
(
custom_parameter
)
raise
LtiError
(
msg
)
)
raise
LtiError
(
msg
)
# LTI specs: 'custom_' should be prepended before each custom parameter, as pointed in link above.
if
param_name
not
in
LTI_PARAMETERS
:
# LTI specs: 'custom_' should be prepended before each custom parameter, as pointed in link above.
param_name
=
'
custom_
'
+
param_name
if
param_name
not
in
LTI_PARAMETERS
:
param_name
=
'
custom_
'
+
param_name
custom_parameters
[
unicode
(
param_name
)]
=
unicode
(
param_value
)
custom_parameters
[
unicode
(
param_name
)]
=
unicode
(
param_value
)
return
custom_parameters
return
custom_parameters
...
...
This diff is collapsed.
Click to expand it.
lti_consumer/tests/unit/test_lti_consumer.py
+
8
−
0
View file @
792940d4
...
@@ -52,6 +52,14 @@ class TestProperties(TestLtiConsumerXBlock):
...
@@ -52,6 +52,14 @@ class TestProperties(TestLtiConsumerXBlock):
"""
"""
self
.
assertEqual
(
self
.
xblock
.
context_id
,
unicode
(
self
.
xblock
.
course_id
))
# pylint: disable=no-member
self
.
assertEqual
(
self
.
xblock
.
context_id
,
unicode
(
self
.
xblock
.
course_id
))
# pylint: disable=no-member
def
test_validate
(
self
):
"""
Test that if custom_parameters is empty string, a validation error is added
"""
self
.
xblock
.
custom_parameters
=
''
validation
=
self
.
xblock
.
validate
()
self
.
assertFalse
(
validation
.
empty
)
def
test_role
(
self
):
def
test_role
(
self
):
"""
"""
Test `role` returns the correct LTI role string
Test `role` returns the correct LTI role string
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment