diff --git a/cms/djangoapps/contentstore/tests/test_core_caching.py b/cms/djangoapps/contentstore/tests/test_core_caching.py index ae90df002e..853aff077e 100644 --- a/cms/djangoapps/contentstore/tests/test_core_caching.py +++ b/cms/djangoapps/contentstore/tests/test_core_caching.py @@ -1,10 +1,12 @@ """ Tests core caching facilities. """ -from contentserver.caching import get_cached_content, set_cached_content, del_cached_content -from opaque_keys.edx.locations import Location + from django.test import TestCase +from opaque_keys.edx.locations import Location +from openedx.core.djangoapps.contentserver.caching import get_cached_content, set_cached_content, del_cached_content + class Content(object): """ diff --git a/cms/djangoapps/contentstore/views/assets.py b/cms/djangoapps/contentstore/views/assets.py index 8ddc9a32af..0d00d3129d 100644 --- a/cms/djangoapps/contentstore/views/assets.py +++ b/cms/djangoapps/contentstore/views/assets.py @@ -2,31 +2,28 @@ import logging from functools import partial import math import json +from pymongo import ASCENDING, DESCENDING -from django.http import HttpResponseBadRequest +from django.conf import settings from django.contrib.auth.decorators import login_required +from django.core.exceptions import PermissionDenied +from django.http import HttpResponseBadRequest, HttpResponseNotFound +from django.utils.translation import ugettext as _ from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods, require_POST -from django.conf import settings from edxmako.shortcuts import render_to_response -from contentserver.caching import del_cached_content - from contentstore.utils import reverse_course_url -from xmodule.contentstore.django import contentstore -from xmodule.modulestore.django import modulestore -from xmodule.contentstore.content import StaticContent -from xmodule.exceptions import NotFoundError from contentstore.views.exception import AssetNotFoundException -from django.core.exceptions import PermissionDenied from opaque_keys.edx.keys import CourseKey, AssetKey - +from openedx.core.djangoapps.contentserver.caching import del_cached_content +from student.auth import has_course_author_access from util.date_utils import get_default_time_display from util.json_request import JsonResponse -from django.http import HttpResponseNotFound -from django.utils.translation import ugettext as _ -from pymongo import ASCENDING, DESCENDING -from student.auth import has_course_author_access +from xmodule.contentstore.content import StaticContent +from xmodule.contentstore.django import contentstore +from xmodule.exceptions import NotFoundError +from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError __all__ = ['assets_handler'] diff --git a/cms/djangoapps/contentstore/views/tests/test_transcripts.py b/cms/djangoapps/contentstore/views/tests/test_transcripts.py index 7bd526721f..5b9b406ecc 100644 --- a/cms/djangoapps/contentstore/views/tests/test_transcripts.py +++ b/cms/djangoapps/contentstore/views/tests/test_transcripts.py @@ -13,12 +13,12 @@ from django.test.utils import override_settings from django.conf import settings from contentstore.tests.utils import CourseTestCase, mock_requests_get -from contentserver.caching import del_cached_content +from opaque_keys.edx.keys import UsageKey +from openedx.core.djangoapps.contentserver.caching import del_cached_content from xmodule.modulestore.django import modulestore from xmodule.contentstore.django import contentstore from xmodule.contentstore.content import StaticContent from xmodule.exceptions import NotFoundError -from opaque_keys.edx.keys import UsageKey from xmodule.video_module import transcripts_utils TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) diff --git a/cms/envs/common.py b/cms/envs/common.py index 9c54fac20d..d18d6d1a4f 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -354,7 +354,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'student.middleware.UserStandingMiddleware', - 'contentserver.middleware.StaticContentServer', + 'openedx.core.djangoapps.contentserver.middleware.StaticContentServer', 'django.contrib.messages.middleware.MessageMiddleware', 'track.middleware.TrackMiddleware', @@ -816,7 +816,7 @@ INSTALLED_APPS = ( # For CMS 'contentstore', - 'contentserver', + 'openedx.core.djangoapps.contentserver', 'course_creators', 'openedx.core.djangoapps.external_auth', 'student', # misleading name due to sharing with lms diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index 33ae6d9d69..63eb6ab23c 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -8,26 +8,25 @@ import textwrap import json import ddt -from nose.plugins.attrib import attr from datetime import timedelta, datetime -from webob import Request from mock import MagicMock, Mock, patch +from nose.plugins.attrib import attr +from webob import Request +from openedx.core.djangoapps.contentserver.caching import del_cached_content from xmodule.contentstore.content import StaticContent from xmodule.contentstore.django import contentstore from xmodule.modulestore.django import modulestore from xmodule.modulestore import ModuleStoreEnum from xmodule.x_module import STUDENT_VIEW -from . import BaseTestXmodule -from .test_video_xml import SOURCE_XML -from contentserver.caching import del_cached_content from xmodule.exceptions import NotFoundError - from xmodule.video_module.transcripts_utils import ( TranscriptException, TranscriptsGenerationException, ) +from . import BaseTestXmodule +from .test_video_xml import SOURCE_XML TRANSCRIPT = {"start": [10], "end": [100], "text": ["Hi, welcome to Edx."]} BUMPER_TRANSCRIPT = {"start": [1], "end": [10], "text": ["A bumper"]} diff --git a/lms/envs/common.py b/lms/envs/common.py index bc95c7abec..325f8bf498 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1109,7 +1109,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'student.middleware.UserStandingMiddleware', - 'contentserver.middleware.StaticContentServer', + 'openedx.core.djangoapps.contentserver.middleware.StaticContentServer', # Adds user tags to tracking events # Must go before TrackMiddleware, to get the context set up @@ -1892,7 +1892,7 @@ INSTALLED_APPS = ( 'static_replace', # For content serving - 'contentserver', + 'openedx.core.djangoapps.contentserver', # Theming 'openedx.core.djangoapps.theming', diff --git a/common/djangoapps/contentserver/__init__.py b/openedx/core/djangoapps/contentserver/__init__.py similarity index 100% rename from common/djangoapps/contentserver/__init__.py rename to openedx/core/djangoapps/contentserver/__init__.py diff --git a/common/djangoapps/contentserver/admin.py b/openedx/core/djangoapps/contentserver/admin.py similarity index 100% rename from common/djangoapps/contentserver/admin.py rename to openedx/core/djangoapps/contentserver/admin.py diff --git a/common/djangoapps/contentserver/caching.py b/openedx/core/djangoapps/contentserver/caching.py similarity index 100% rename from common/djangoapps/contentserver/caching.py rename to openedx/core/djangoapps/contentserver/caching.py diff --git a/common/djangoapps/contentserver/middleware.py b/openedx/core/djangoapps/contentserver/middleware.py similarity index 98% rename from common/djangoapps/contentserver/middleware.py rename to openedx/core/djangoapps/contentserver/middleware.py index 28416582a7..369639702d 100644 --- a/common/djangoapps/contentserver/middleware.py +++ b/openedx/core/djangoapps/contentserver/middleware.py @@ -9,7 +9,6 @@ from django.http import ( HttpResponse, HttpResponseNotModified, HttpResponseForbidden, HttpResponseBadRequest, HttpResponseNotFound, HttpResponsePermanentRedirect) from student.models import CourseEnrollment -from contentserver.models import CourseAssetCacheTtlConfig, CdnUserAgentsConfig from header_control import force_header_for_response from xmodule.assetstore.assetmgr import AssetManager @@ -21,6 +20,8 @@ from .caching import get_cached_content, set_cached_content from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.exceptions import NotFoundError +from .models import CourseAssetCacheTtlConfig, CdnUserAgentsConfig + # TODO: Soon as we have a reasonable way to serialize/deserialize AssetKeys, we need # to change this file so instead of using course_id_partial, we're just using asset keys @@ -42,6 +43,7 @@ class StaticContentServer(object): StaticContent.is_versioned_asset_path(request.path) ) + # pylint: disable=too-many-statements def process_request(self, request): """Process the given request""" asset_path = request.path @@ -117,7 +119,7 @@ class StaticContentServer(object): response = None if request.META.get('HTTP_RANGE'): # If we have a StaticContent, get a StaticContentStream. Can't manipulate the bytes otherwise. - if type(content) == StaticContent: + if isinstance(content, StaticContent): content = AssetManager.find(loc, as_stream=True) header_value = request.META['HTTP_RANGE'] diff --git a/common/djangoapps/contentserver/migrations/0001_initial.py b/openedx/core/djangoapps/contentserver/migrations/0001_initial.py similarity index 100% rename from common/djangoapps/contentserver/migrations/0001_initial.py rename to openedx/core/djangoapps/contentserver/migrations/0001_initial.py diff --git a/common/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py b/openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py similarity index 100% rename from common/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py rename to openedx/core/djangoapps/contentserver/migrations/0002_cdnuseragentsconfig.py diff --git a/common/djangoapps/contentserver/migrations/__init__.py b/openedx/core/djangoapps/contentserver/migrations/__init__.py similarity index 100% rename from common/djangoapps/contentserver/migrations/__init__.py rename to openedx/core/djangoapps/contentserver/migrations/__init__.py diff --git a/common/djangoapps/contentserver/models.py b/openedx/core/djangoapps/contentserver/models.py similarity index 100% rename from common/djangoapps/contentserver/models.py rename to openedx/core/djangoapps/contentserver/models.py diff --git a/common/djangoapps/contentserver/test/__init__.py b/openedx/core/djangoapps/contentserver/test/__init__.py similarity index 100% rename from common/djangoapps/contentserver/test/__init__.py rename to openedx/core/djangoapps/contentserver/test/__init__.py diff --git a/common/djangoapps/contentserver/test/test_contentserver.py b/openedx/core/djangoapps/contentserver/test/test_contentserver.py similarity index 95% rename from common/djangoapps/contentserver/test/test_contentserver.py rename to openedx/core/djangoapps/contentserver/test/test_contentserver.py index 10d0c7a421..56c8a269fb 100644 --- a/common/djangoapps/contentserver/test/test_contentserver.py +++ b/openedx/core/djangoapps/contentserver/test/test_contentserver.py @@ -24,10 +24,11 @@ from xmodule.assetstore.assetmgr import AssetManager from opaque_keys import InvalidKeyError from xmodule.modulestore.exceptions import ItemNotFoundError -from contentserver.middleware import parse_range_header, HTTP_DATE_FORMAT, StaticContentServer from student.models import CourseEnrollment from student.tests.factories import UserFactory, AdminFactory +from ..middleware import parse_range_header, HTTP_DATE_FORMAT, StaticContentServer + log = logging.getLogger(__name__) TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE) @@ -293,7 +294,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): self.assertEqual(resp.status_code, 200) self.assertEquals('Origin', resp['Vary']) - @patch('contentserver.models.CourseAssetCacheTtlConfig.get_cache_ttl') + @patch('openedx.core.djangoapps.contentserver.models.CourseAssetCacheTtlConfig.get_cache_ttl') def test_cache_headers_with_ttl_unlocked(self, mock_get_cache_ttl): """ Tests that when a cache TTL is set, an unlocked asset will be sent back with @@ -306,7 +307,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): self.assertIn('Expires', resp) self.assertEquals('public, max-age=10, s-maxage=10', resp['Cache-Control']) - @patch('contentserver.models.CourseAssetCacheTtlConfig.get_cache_ttl') + @patch('openedx.core.djangoapps.contentserver.models.CourseAssetCacheTtlConfig.get_cache_ttl') def test_cache_headers_with_ttl_locked(self, mock_get_cache_ttl): """ Tests that when a cache TTL is set, a locked asset will be sent back without @@ -323,7 +324,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): self.assertNotIn('Expires', resp) self.assertEquals('private, no-cache, no-store', resp['Cache-Control']) - @patch('contentserver.models.CourseAssetCacheTtlConfig.get_cache_ttl') + @patch('openedx.core.djangoapps.contentserver.models.CourseAssetCacheTtlConfig.get_cache_ttl') def test_cache_headers_without_ttl_unlocked(self, mock_get_cache_ttl): """ Tests that when a cache TTL is not set, an unlocked asset will be sent back without @@ -336,7 +337,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): self.assertNotIn('Expires', resp) self.assertNotIn('Cache-Control', resp) - @patch('contentserver.models.CourseAssetCacheTtlConfig.get_cache_ttl') + @patch('openedx.core.djangoapps.contentserver.models.CourseAssetCacheTtlConfig.get_cache_ttl') def test_cache_headers_without_ttl_locked(self, mock_get_cache_ttl): """ Tests that when a cache TTL is not set, a locked asset will be sent back with a @@ -358,7 +359,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): near_expire_dt = StaticContentServer.get_expiration_value(start_dt, 55) self.assertEqual("Thu, 01 Dec 1983 20:00:55 GMT", near_expire_dt) - @patch('contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents') + @patch('openedx.core.djangoapps.contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents') def test_cache_is_cdn_with_normal_request(self, mock_get_cdn_user_agents): """ Tests that when a normal request is made -- i.e. from an end user with their @@ -372,7 +373,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): is_from_cdn = StaticContentServer.is_cdn_request(browser_request) self.assertEqual(is_from_cdn, False) - @patch('contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents') + @patch('openedx.core.djangoapps.contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents') def test_cache_is_cdn_with_cdn_request(self, mock_get_cdn_user_agents): """ Tests that when a CDN request is made -- i.e. from an edge node back to the @@ -386,7 +387,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): is_from_cdn = StaticContentServer.is_cdn_request(browser_request) self.assertEqual(is_from_cdn, True) - @patch('contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents') + @patch('openedx.core.djangoapps.contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents') def test_cache_is_cdn_with_cdn_request_multiple_user_agents(self, mock_get_cdn_user_agents): """ Tests that when a CDN request is made -- i.e. from an edge node back to the