Remove unused imports. Push model imports down into relevant methods.

Mock out the static_replace modules in the proper location.
This commit is contained in:
John Eskew
2017-09-19 17:55:14 -04:00
parent 8b5b1eba86
commit 02f26f55ce
10 changed files with 45 additions and 24 deletions

View File

@@ -5,9 +5,6 @@ from django.contrib.staticfiles.storage import staticfiles_storage
from django.contrib.staticfiles import finders
from django.conf import settings
from static_replace.models import AssetBaseUrlConfig, AssetExcludedExtensionsConfig
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
from xmodule.contentstore.content import StaticContent
from opaque_keys.edx.locator import AssetLocator
@@ -191,6 +188,8 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
else:
# if not, then assume it's courseware specific content and then look in the
# Mongo-backed database
# Import is placed here to avoid model import at project startup.
from static_replace.models import AssetBaseUrlConfig, AssetExcludedExtensionsConfig
base_url = AssetBaseUrlConfig.get_base_url()
excluded_exts = AssetExcludedExtensionsConfig.get_excluded_extensions()
url = StaticContent.get_canonicalized_asset_path(course_id, rest, base_url, excluded_exts)

View File

@@ -116,9 +116,9 @@ def test_storage_url_not_exists(mock_storage):
@patch('static_replace.StaticContent', autospec=True)
@patch('static_replace.modulestore', autospec=True)
@patch('static_replace.AssetBaseUrlConfig.get_base_url')
@patch('static_replace.AssetExcludedExtensionsConfig.get_excluded_extensions')
@patch('xmodule.modulestore.django.modulestore', autospec=True)
@patch('static_replace.models.AssetBaseUrlConfig.get_base_url')
@patch('static_replace.models.AssetExcludedExtensionsConfig.get_excluded_extensions')
def test_mongo_filestore(mock_get_excluded_extensions, mock_get_base_url, mock_modulestore, mock_static_content):
mock_modulestore.return_value = Mock(MongoModuleStore)
@@ -139,7 +139,7 @@ def test_mongo_filestore(mock_get_excluded_extensions, mock_get_base_url, mock_m
@patch('static_replace.settings', autospec=True)
@patch('static_replace.modulestore', autospec=True)
@patch('xmodule.modulestore.django.modulestore', autospec=True)
@patch('static_replace.staticfiles_storage', autospec=True)
def test_data_dir_fallback(mock_storage, mock_modulestore, mock_settings):
mock_modulestore.return_value = Mock(XMLModuleStore)
@@ -165,7 +165,7 @@ def test_raw_static_check():
@pytest.mark.django_db
@patch('static_replace.staticfiles_storage', autospec=True)
@patch('static_replace.modulestore', autospec=True)
@patch('xmodule.modulestore.django.modulestore', autospec=True)
def test_static_url_with_query(mock_modulestore, mock_storage):
"""
Make sure that for urls with query params:
@@ -201,7 +201,7 @@ def test_regex():
@patch('static_replace.staticfiles_storage', autospec=True)
@patch('static_replace.modulestore', autospec=True)
@patch('xmodule.modulestore.django.modulestore', autospec=True)
def test_static_url_with_xblock_resource(mock_modulestore, mock_storage):
"""
Make sure that for URLs with XBlock resource URL, which start with /static/,
@@ -216,7 +216,7 @@ def test_static_url_with_xblock_resource(mock_modulestore, mock_storage):
@patch('static_replace.staticfiles_storage', autospec=True)
@patch('static_replace.modulestore', autospec=True)
@patch('xmodule.modulestore.django.modulestore', autospec=True)
@override_settings(STATIC_URL='https://example.com/static/')
def test_static_url_with_xblock_resource_on_cdn(mock_modulestore, mock_storage):
"""

View File

@@ -29,7 +29,6 @@ from xmodule.contentstore.django import contentstore
from xmodule.modulestore.draft_and_published import BranchSettingMixin
from xmodule.modulestore.mixed import MixedModuleStore
from xmodule.util.django import get_current_request_hostname
import xblock.reference.plugins
try:
# We may not always have the request_cache module available
@@ -245,6 +244,9 @@ def create_modulestore_instance(
"""
This will return a new instance of a modulestore given an engine and options
"""
# Import is placed here to avoid model import at project startup.
import xblock.reference.plugins
class_ = load_function(engine)
_options = {}