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
OpenEdx
edx-platform
Commits
cb4098f0
Commit
cb4098f0
authored
Sep 12, 2017
by
Michael Roytman
Committed by
Dillon Dumesnil
Oct 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor and add multiple filter functionality
parent
91acbba0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
9 deletions
+59
-9
cms/djangoapps/contentstore/views/assets.py
+0
-0
cms/djangoapps/contentstore/views/tests/test_assets.py
+39
-8
cms/envs/common.py
+20
-1
No files found.
cms/djangoapps/contentstore/views/assets.py
View file @
cb4098f0
This diff is collapsed.
Click to expand it.
cms/djangoapps/contentstore/views/tests/test_assets.py
View file @
cb4098f0
...
...
@@ -174,6 +174,15 @@ class PaginationTestCase(AssetsTestCase):
self
.
assert_correct_filter_response
(
self
.
url
,
'asset_type'
,
'OTHER'
)
self
.
assert_correct_filter_response
(
self
.
url
,
'asset_type'
,
'Documents'
)
self
.
assert_correct_filter_response
(
self
.
url
,
'asset_type'
,
'Documents,Images'
)
self
.
assert_correct_filter_response
(
self
.
url
,
'asset_type'
,
'Documents,OTHER'
)
#Verify invalid request parameters
self
.
assert_invalid_parameters_error
(
self
.
url
,
'asset_type'
,
'edX'
)
self
.
assert_invalid_parameters_error
(
self
.
url
,
'asset_type'
,
'edX, OTHER'
)
self
.
assert_invalid_parameters_error
(
self
.
url
,
'asset_type'
,
'edX, Images'
)
# Verify querying outside the range of valid pages
self
.
assert_correct_asset_response
(
...
...
@@ -247,24 +256,46 @@ class PaginationTestCase(AssetsTestCase):
"""
Get from the url w/ a filter option and ensure items honor that filter
"""
requested_file_types
=
settings
.
FILES_AND_UPLOAD_TYPE_FILTERS
.
get
(
filter_value
,
None
)
filter_value_split
=
filter_value
.
split
(
','
)
requested_file_extensions
=
[]
all_file_extensions
=
[]
for
requested_filter
in
filter_value_split
:
if
requested_filter
==
'OTHER'
:
for
file_type
in
settings
.
FILES_AND_UPLOAD_TYPE_FILTERS
:
all_file_extensions
.
extend
(
file_type
)
else
:
file_extensions
=
settings
.
FILES_AND_UPLOAD_TYPE_FILTERS
.
get
(
requested_filter
,
None
)
if
file_extensions
is
not
None
:
requested_file_extensions
.
extend
(
file_extensions
)
resp
=
self
.
client
.
get
(
url
+
'?'
+
filter_type
+
'='
+
filter_value
,
HTTP_ACCEPT
=
'application/json'
)
json_response
=
json
.
loads
(
resp
.
content
)
assets_response
=
json_response
[
'assets'
]
if
filter_value
is
not
''
:
content_types
=
[
asset
[
'content_type'
]
.
lower
()
for
asset
in
assets_response
]
if
filter_value
is
'OTHER'
:
all_file_type_extensions
=
[]
for
file_type
in
settings
.
FILES_AND_UPLOAD_TYPE_FILTERS
:
all_file_type_extensions
.
extend
(
file_type
)
if
'OTHER'
in
filter_value_split
:
for
content_type
in
content_types
:
self
.
assertNotIn
(
content_type
,
all_file_type_extensions
)
# content_type is either not any defined type (i.e. OTHER) or is a defined type (if multiple
# parameters including OTHER are used)
self
.
assertTrue
(
content_type
in
requested_file_extensions
or
content_type
not
in
all_file_extensions
)
else
:
for
content_type
in
content_types
:
self
.
assertIn
(
content_type
,
requested_file_types
)
self
.
assertIn
(
content_type
,
requested_file_extensions
)
def
assert_invalid_parameters_error
(
self
,
url
,
filter_type
,
filter_value
):
"""
Get from the url w/ invalid filter option(s) and ensure error is received
"""
resp
=
self
.
client
.
get
(
url
+
'?'
+
filter_type
+
'='
+
filter_value
,
HTTP_ACCEPT
=
'application/json'
)
self
.
assertEquals
(
resp
.
status_code
,
400
)
@ddt
...
...
cms/envs/common.py
View file @
cb4098f0
...
...
@@ -1257,7 +1257,8 @@ ADVANCED_PROBLEM_TYPES = [
# Files and Uploads type filter values
FILES_AND_UPLOAD_TYPE_FILTERS
=
{
"Images"
:
[
'image/png'
,
'image/jpeg'
,
'image/jpg'
,
'image/gif'
,
'image/tiff'
,
'image/tif'
,
'image/x-icon'
],
"Images"
:
[
'image/png'
,
'image/jpeg'
,
'image/jpg'
,
'image/gif'
,
'image/tiff'
,
'image/tif'
,
'image/x-icon'
,
'image/svg+xml'
,
'image/bmp'
,
'image/x-ms-bmp'
,
],
"Documents"
:
[
'application/pdf'
,
'text/plain'
,
...
...
@@ -1271,7 +1272,25 @@ FILES_AND_UPLOAD_TYPE_FILTERS = {
'application/msword'
,
'application/vnd.ms-excel'
,
'application/vnd.ms-powerpoint'
,
'application/csv'
,
'application/vnd.ms-excel.sheet.macroEnabled.12'
,
'text/x-tex'
,
'application/x-pdf'
,
'application/vnd.ms-excel.sheet.macroenabled.12'
,
'file/pdf'
,
'image/pdf'
,
'text/csv'
,
'text/pdf'
,
'text/x-sh'
,
'
\a
pplication/pdf
\"
"'
,
],
"Audio"
:
[
'audio/mpeg'
,
'audio/mp3'
,
'audio/x-wav'
,
'audio/ogg'
,
'audio/wav'
,
'audio/aac'
,
'audio/x-m4a'
,
'audio/mp4'
,
'audio/x-ms-wma'
,
],
"Code"
:
[
'application/json'
,
'text/html'
,
'text/javascript'
,
'application/javascript'
,
'text/css'
,
'text/x-python'
,
'application/x-java-jnlp-file'
,
'application/xml'
,
'application/postscript'
,
'application/x-javascript'
,
'application/java-vm'
,
'text/x-c++src'
,
'text/xml'
,
'text/x-scss'
,
'application/x-python-code'
,
'application/java-archive'
,
'text/x-python-script'
,
'application/x-ruby'
,
'application/mathematica'
,
'text/coffeescript'
,
'text/x-matlab'
,
'application/sql'
,
'text/php'
,
]
}
# Default to no Search Engine
...
...
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