Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
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
Hsin-Yu Chien
edx-platform-release
Commits
1537f040
Commit
1537f040
authored
8 years ago
by
Calen Pennington
Browse files
Options
Downloads
Patches
Plain Diff
Mock SignatureValidator.verify using patch so that the mock is unset at the end of the test
parent
95054e1a
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lms/djangoapps/lti_provider/tests/test_views.py
+10
-5
10 additions, 5 deletions
lms/djangoapps/lti_provider/tests/test_views.py
with
10 additions
and
5 deletions
lms/djangoapps/lti_provider/tests/test_views.py
+
10
−
5
View file @
1537f040
...
...
@@ -10,7 +10,6 @@ from nose.plugins.attrib import attr
from
courseware.testutils
import
RenderXBlockTestMixin
from
lti_provider
import
views
,
models
from
lti_provider.signature_validator
import
SignatureValidator
from
opaque_keys.edx.locator
import
CourseLocator
,
BlockUsageLocator
from
student.tests.factories
import
UserFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
...
...
@@ -66,7 +65,11 @@ class LtiTestMixin(object):
def
setUp
(
self
):
super
(
LtiTestMixin
,
self
).
setUp
()
# Always accept the OAuth signature
SignatureValidator
.
verify
=
MagicMock
(
return_value
=
True
)
self
.
mock_verify
=
MagicMock
(
return_value
=
True
)
patcher
=
patch
(
'
lti_provider.signature_validator.SignatureValidator.verify
'
,
self
.
mock_verify
)
patcher
.
start
()
self
.
addCleanup
(
patcher
.
stop
)
self
.
consumer
=
models
.
LtiConsumer
(
consumer_name
=
'
consumer
'
,
consumer_key
=
LTI_DEFAULT_PARAMS
[
'
oauth_consumer_key
'
],
...
...
@@ -139,7 +142,8 @@ class LtiLaunchTest(LtiTestMixin, TestCase):
Verifies that the view returns Forbidden if the LTI OAuth signature is
incorrect.
"""
SignatureValidator
.
verify
=
MagicMock
(
return_value
=
False
)
self
.
mock_verify
.
return_value
=
False
request
=
build_launch_request
()
response
=
views
.
lti_launch
(
request
,
None
,
None
)
self
.
assertEqual
(
response
.
status_code
,
403
)
...
...
@@ -147,7 +151,8 @@ class LtiLaunchTest(LtiTestMixin, TestCase):
@patch
(
'
lti_provider.views.render_courseware
'
)
def
test_lti_consumer_record_supplemented_with_guid
(
self
,
_render
):
SignatureValidator
.
verify
=
MagicMock
(
return_value
=
False
)
self
.
mock_verify
.
return_value
=
False
request
=
build_launch_request
()
request
.
POST
.
update
(
LTI_OPTIONAL_PARAMS
)
with
self
.
assertNumQueries
(
3
):
...
...
@@ -178,7 +183,7 @@ class LtiLaunchTestRender(LtiTestMixin, RenderXBlockTestMixin, ModuleStoreTestCa
)
if
url_encoded_params
:
lti_launch_url
+=
'
?
'
+
url_encoded_params
SignatureValidator
.
verify
=
MagicMock
(
return_value
=
True
)
return
self
.
client
.
post
(
lti_launch_url
,
data
=
LTI_DEFAULT_PARAMS
)
# The following test methods override the base tests for verifying access
...
...
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