Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
539dd0c4
Commit
539dd0c4
authored
10 years ago
by
Waheed Ahmed
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5010 from edx/waheed/refactor-verify-course-id-decorator
Refactor verify course id decorator and fixed tests.
parents
dbe1ba09
2e88e338
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
9 deletions
+10
-9
lms/djangoapps/courseware/tests/test_lti_integration.py
+1
-1
lms/djangoapps/courseware/tests/test_views.py
+5
-5
lms/djangoapps/courseware/views.py
+4
-3
No files found.
lms/djangoapps/courseware/tests/test_lti_integration.py
View file @
539dd0c4
...
...
@@ -188,7 +188,7 @@ class TestLTIModuleListing(ModuleStoreTestCase):
"""tests that the draft lti module is part of the endpoint response"""
request
=
mock
.
Mock
()
request
.
method
=
'GET'
response
=
get_course_lti_endpoints
(
request
,
self
.
course
.
id
.
to_deprecated_string
())
response
=
get_course_lti_endpoints
(
request
,
course_id
=
self
.
course
.
id
.
to_deprecated_string
())
self
.
assertEqual
(
200
,
response
.
status_code
)
self
.
assertEqual
(
'application/json'
,
response
[
'Content-Type'
])
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/courseware/tests/test_views.py
View file @
539dd0c4
...
...
@@ -463,7 +463,7 @@ class TestProgressDueDate(BaseDueDateTests):
""" Returns the HTML for the progress page """
mako_middleware_process_request
(
self
.
request
)
return
views
.
progress
(
self
.
request
,
course
.
id
.
to_deprecated_string
(),
self
.
user
.
id
)
.
content
return
views
.
progress
(
self
.
request
,
course
_id
=
course
.
id
.
to_deprecated_string
(),
student_id
=
self
.
user
.
id
)
.
content
class
TestAccordionDueDate
(
BaseDueDateTests
):
...
...
@@ -560,11 +560,11 @@ class ProgressPageTests(ModuleStoreTestCase):
def
test_pure_ungraded_xblock
(
self
):
ItemFactory
(
category
=
'acid'
,
parent_location
=
self
.
vertical
.
location
)
resp
=
views
.
progress
(
self
.
request
,
self
.
course
.
id
.
to_deprecated_string
())
resp
=
views
.
progress
(
self
.
request
,
course_id
=
self
.
course
.
id
.
to_deprecated_string
())
self
.
assertEqual
(
resp
.
status_code
,
200
)
def
test_non_asci_grade_cutoffs
(
self
):
resp
=
views
.
progress
(
self
.
request
,
self
.
course
.
id
.
to_deprecated_string
())
resp
=
views
.
progress
(
self
.
request
,
course_id
=
self
.
course
.
id
.
to_deprecated_string
())
self
.
assertEqual
(
resp
.
status_code
,
200
)
...
...
@@ -581,11 +581,11 @@ class TestVerifyCourseIdDecorator(TestCase):
def
test_decorator_with_valid_course_id
(
self
):
mocked_view
=
create_autospec
(
views
.
course_about
)
view_function
=
views
.
verify_course_id
(
mocked_view
)
view_function
(
self
.
request
,
self
.
valid_course_id
)
view_function
(
self
.
request
,
course_id
=
self
.
valid_course_id
)
self
.
assertTrue
(
mocked_view
.
called
)
def
test_decorator_with_invalid_course_id
(
self
):
mocked_view
=
create_autospec
(
views
.
course_about
)
view_function
=
views
.
verify_course_id
(
mocked_view
)
self
.
assertRaises
(
Http404
,
view_function
,
self
.
request
,
self
.
invalid_course_id
)
self
.
assertRaises
(
Http404
,
view_function
,
self
.
request
,
course_id
=
self
.
invalid_course_id
)
self
.
assertFalse
(
mocked_view
.
called
)
This diff is collapsed.
Click to expand it.
lms/djangoapps/courseware/views.py
View file @
539dd0c4
...
...
@@ -84,17 +84,18 @@ def user_groups(user):
def
verify_course_id
(
view_func
):
"""
This decorator should only be used with views whose
second argument is
course_id.
This decorator should only be used with views whose
kwargs must contain
course_id.
If course_id is not valid raise 404.
"""
@wraps
(
view_func
)
def
_decorated
(
request
,
course_id
,
*
args
,
**
kwargs
):
def
_decorated
(
request
,
*
args
,
**
kwargs
):
course_id
=
kwargs
.
get
(
"course_id"
)
try
:
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
except
InvalidKeyError
:
raise
Http404
response
=
view_func
(
request
,
course_id
,
*
args
,
**
kwargs
)
response
=
view_func
(
request
,
*
args
,
**
kwargs
)
return
response
return
_decorated
...
...
This diff is collapsed.
Click to expand it.
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