Merge pull request #26302 from edx/amnesty-static-replace
Applied pylint-amnesty to static_replace
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
|
||||
# lint-amnesty, pylint: disable=django-not-configured, missing-module-docstring
|
||||
|
||||
import logging
|
||||
import re
|
||||
@@ -38,7 +38,7 @@ def try_staticfiles_lookup(path):
|
||||
"""
|
||||
try:
|
||||
url = staticfiles_storage.url(path)
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
|
||||
path, str(err)))
|
||||
# Just return the original path; don't kill everything.
|
||||
@@ -46,7 +46,7 @@ def try_staticfiles_lookup(path):
|
||||
return url
|
||||
|
||||
|
||||
def replace_jump_to_id_urls(text, course_id, jump_to_id_base_url):
|
||||
def replace_jump_to_id_urls(text, course_id, jump_to_id_base_url): # lint-amnesty, pylint: disable=unused-argument
|
||||
"""
|
||||
This will replace a link to another piece of courseware to a 'jump_to'
|
||||
URL that will redirect to the right place in the courseware
|
||||
@@ -191,7 +191,7 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
|
||||
exists_in_staticfiles_storage = False
|
||||
try:
|
||||
exists_in_staticfiles_storage = staticfiles_storage.exists(rest)
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
|
||||
rest, str(err)))
|
||||
|
||||
@@ -219,7 +219,7 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
|
||||
else:
|
||||
url = staticfiles_storage.url(course_path)
|
||||
# And if that fails, assume that it's course content, and add manually data directory
|
||||
except Exception as err:
|
||||
except Exception as err: # lint-amnesty, pylint: disable=broad-except
|
||||
log.warning("staticfiles_storage couldn't find path {0}: {1}".format(
|
||||
rest, str(err)))
|
||||
url = "".join([prefix, course_path])
|
||||
|
||||
@@ -135,7 +135,7 @@ def test_mongo_filestore(mock_get_excluded_extensions, mock_get_base_url, mock_m
|
||||
@patch('common.djangoapps.static_replace.settings', autospec=True)
|
||||
@patch('xmodule.modulestore.django.modulestore', autospec=True)
|
||||
@patch('common.djangoapps.static_replace.staticfiles_storage', autospec=True)
|
||||
def test_data_dir_fallback(mock_storage, mock_modulestore, mock_settings):
|
||||
def test_data_dir_fallback(mock_storage, mock_modulestore, mock_settings): # lint-amnesty, pylint: disable=unused-argument
|
||||
mock_modulestore.return_value = Mock(XMLModuleStore)
|
||||
mock_storage.url.side_effect = Exception
|
||||
|
||||
@@ -169,8 +169,8 @@ def test_static_url_with_query(mock_modulestore, mock_storage):
|
||||
mock_storage.exists.return_value = False
|
||||
mock_modulestore.return_value = Mock(MongoModuleStore)
|
||||
|
||||
pre_text = 'EMBED src ="/static/LAlec04_controller.swf?csConfigFile=/static/LAlec04_config.xml&name1=value1&name2=value2"'
|
||||
post_text = 'EMBED src ="/c4x/org/course/asset/LAlec04_controller.swf?csConfigFile=%2Fc4x%2Forg%2Fcourse%2Fasset%2FLAlec04_config.xml&name1=value1&name2=value2"'
|
||||
pre_text = 'EMBED src ="/static/LAlec04_controller.swf?csConfigFile=/static/LAlec04_config.xml&name1=value1&name2=value2"' # lint-amnesty, pylint: disable=line-too-long
|
||||
post_text = 'EMBED src ="/c4x/org/course/asset/LAlec04_controller.swf?csConfigFile=%2Fc4x%2Forg%2Fcourse%2Fasset%2FLAlec04_config.xml&name1=value1&name2=value2"' # lint-amnesty, pylint: disable=line-too-long
|
||||
assert replace_static_urls(pre_text, DATA_DIRECTORY, COURSE_KEY) == post_text
|
||||
|
||||
|
||||
@@ -189,13 +189,13 @@ def test_static_paths_out(mock_modulestore, mock_storage):
|
||||
mock_modulestore.return_value = Mock(MongoModuleStore)
|
||||
|
||||
static_url = '/static/LAlec04_controller.swf?csConfigFile=/static/LAlec04_config.xml&name1=value1&name2=value2'
|
||||
static_course_url = '/c4x/org/course/asset/LAlec04_controller.swf?csConfigFile=%2Fc4x%2Forg%2Fcourse%2Fasset%2FLAlec04_config.xml&name1=value1&name2=value2'
|
||||
static_course_url = '/c4x/org/course/asset/LAlec04_controller.swf?csConfigFile=%2Fc4x%2Forg%2Fcourse%2Fasset%2FLAlec04_config.xml&name1=value1&name2=value2' # lint-amnesty, pylint: disable=line-too-long
|
||||
raw_url = '/static/js/capa/protex/protex.nocache.js?raw'
|
||||
xblock_url = '/static/xblock/resources/babys_first.lil_xblock/public/images/pacifier.png'
|
||||
# xss-lint: disable=python-wrap-html
|
||||
pre_text = 'EMBED src ="{}" xblock={} text <tag a="{}"/><div class="'.format(static_url, xblock_url, raw_url)
|
||||
# xss-lint: disable=python-wrap-html
|
||||
post_text = 'EMBED src ="{}" xblock={} text <tag a="{}"/><div class="'.format(static_course_url, xblock_url, raw_url)
|
||||
post_text = 'EMBED src ="{}" xblock={} text <tag a="{}"/><div class="'.format(static_course_url, xblock_url, raw_url) # lint-amnesty, pylint: disable=line-too-long
|
||||
static_paths = []
|
||||
assert replace_static_urls(pre_text, DATA_DIRECTORY, COURSE_KEY, static_paths_out=static_paths) == post_text
|
||||
assert static_paths == [(static_url, static_course_url), (raw_url, raw_url)]
|
||||
|
||||
Reference in New Issue
Block a user