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
0a75f8ec
Commit
0a75f8ec
authored
Apr 16, 2017
by
Omar Al-Ithawi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unicode support for request_cached decorator and commentable_id
parent
a26560de
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
5 deletions
+31
-5
common/djangoapps/request_cache/middleware.py
+4
-3
common/djangoapps/request_cache/tests.py
+23
-0
lms/djangoapps/django_comment_client/base/tests.py
+3
-1
lms/djangoapps/django_comment_client/permissions.py
+1
-1
No files found.
common/djangoapps/request_cache/middleware.py
View file @
0a75f8ec
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
An implementation of a RequestCache. This cache is reset at the beginning
An implementation of a RequestCache. This cache is reset at the beginning
and end of every request.
and end of every request.
"""
"""
from
django.utils.encoding
import
force_text
import
crum
import
crum
import
threading
import
threading
...
@@ -108,7 +109,7 @@ def func_call_cache_key(func, *args, **kwargs):
...
@@ -108,7 +109,7 @@ def func_call_cache_key(func, *args, **kwargs):
the function's name, and a stringified list of arguments
the function's name, and a stringified list of arguments
and a query string-style stringified list of keyword arguments.
and a query string-style stringified list of keyword arguments.
"""
"""
converted_args
=
map
(
str
,
args
)
converted_args
=
map
(
force_text
,
args
)
converted_kwargs
=
map
(
str
,
reduce
(
list
.
__add__
,
map
(
list
,
sorted
(
kwargs
.
iteritems
())),
[]))
converted_kwargs
=
map
(
force_text
,
reduce
(
list
.
__add__
,
map
(
list
,
sorted
(
kwargs
.
iteritems
())),
[]))
cache_keys
=
[
func
.
__module__
,
func
.
func_name
]
+
converted_args
+
converted_kwargs
cache_keys
=
[
func
.
__module__
,
func
.
func_name
]
+
converted_args
+
converted_kwargs
return
'.'
.
join
(
cache_keys
)
return
u
'.'
.
join
(
cache_keys
)
common/djangoapps/request_cache/tests.py
View file @
0a75f8ec
# -*- coding: utf-8 -*-
"""
"""
Tests for the request cache.
Tests for the request cache.
"""
"""
...
@@ -183,6 +184,28 @@ class TestRequestCache(TestCase):
...
@@ -183,6 +184,28 @@ class TestRequestCache(TestCase):
self
.
assertEqual
(
result
,
4
)
self
.
assertEqual
(
result
,
4
)
self
.
assertEqual
(
to_be_wrapped
.
call_count
,
4
)
self
.
assertEqual
(
to_be_wrapped
.
call_count
,
4
)
def
test_request_cached_mixed_unicode_str_args
(
self
):
"""
Ensure that request_cached can work with mixed str and Unicode parameters.
"""
RequestCache
.
clear_request_cache
()
def
dummy_function
(
arg1
,
arg2
):
"""
A dummy function that expects an str and unicode arguments.
"""
assert
isinstance
(
arg1
,
str
),
'First parameter has to be of type `str`'
assert
isinstance
(
arg2
,
unicode
),
'Second parameter has to be of type `unicode`'
return
True
self
.
assertTrue
(
dummy_function
(
'Hello'
,
u'World'
),
'Should be callable with ASCII chars'
)
self
.
assertTrue
(
dummy_function
(
'H∂llå'
,
u'Wørld'
),
'Should be callable with non-ASCII chars'
)
wrapped
=
request_cached
(
dummy_function
)
self
.
assertTrue
(
wrapped
(
'Hello'
,
u'World'
),
'Wrapper should handle ASCII only chars'
)
self
.
assertTrue
(
wrapped
(
'H∂llå'
,
u'Wørld'
),
'Wrapper should handle non-ASCII chars'
)
def
test_request_cached_with_none_result
(
self
):
def
test_request_cached_with_none_result
(
self
):
"""
"""
Ensure that calling a decorated function that returns None
Ensure that calling a decorated function that returns None
...
...
lms/djangoapps/django_comment_client/base/tests.py
View file @
0a75f8ec
# -*- coding: utf-8 -*-
"""Tests for django comment client views."""
"""Tests for django comment client views."""
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
import
logging
import
logging
...
@@ -1168,7 +1169,8 @@ class CreateThreadUnicodeTestCase(
...
@@ -1168,7 +1169,8 @@ class CreateThreadUnicodeTestCase(
request
.
user
=
self
.
student
request
.
user
=
self
.
student
request
.
view_name
=
"create_thread"
request
.
view_name
=
"create_thread"
response
=
views
.
create_thread
(
response
=
views
.
create_thread
(
request
,
course_id
=
unicode
(
self
.
course
.
id
),
commentable_id
=
"non_team_dummy_id"
# The commentable ID contains a username, the Unicode char below ensures it works fine
request
,
course_id
=
unicode
(
self
.
course
.
id
),
commentable_id
=
u"non_tåem_dummy_id"
)
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
...
...
lms/djangoapps/django_comment_client/permissions.py
View file @
0a75f8ec
...
@@ -81,7 +81,7 @@ def _check_condition(user, condition, content):
...
@@ -81,7 +81,7 @@ def _check_condition(user, condition, content):
try
:
try
:
commentable_id
=
content
[
'commentable_id'
]
commentable_id
=
content
[
'commentable_id'
]
request_cache_dict
=
RequestCache
.
get_request_cache
()
.
data
request_cache_dict
=
RequestCache
.
get_request_cache
()
.
data
cache_key
=
"django_comment_client.check_team_member.{}.{}"
.
format
(
user
.
id
,
commentable_id
)
cache_key
=
u
"django_comment_client.check_team_member.{}.{}"
.
format
(
user
.
id
,
commentable_id
)
if
cache_key
in
request_cache_dict
:
if
cache_key
in
request_cache_dict
:
return
request_cache_dict
[
cache_key
]
return
request_cache_dict
[
cache_key
]
team
=
get_team
(
commentable_id
)
team
=
get_team
(
commentable_id
)
...
...
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