Skip to content

Commit

Permalink
Merge pull request #35559 from openedx/timmc/course-asset-view-cleanup
Browse files Browse the repository at this point in the history
refactor: Clean up after conversion of contentserver to view
  • Loading branch information
timmc-edx authored Sep 30, 2024
2 parents 06a5560 + 7b1519f commit a100166
Show file tree
Hide file tree
Showing 2 changed files with 253 additions and 270 deletions.
21 changes: 10 additions & 11 deletions openedx/core/djangoapps/contentserver/test/test_contentserver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Tests for StaticContentServer
Tests for content server.
"""


Expand Down Expand Up @@ -27,7 +27,7 @@
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase
from xmodule.modulestore.xml_importer import import_course_from_xml

from ..views import HTTP_DATE_FORMAT, StaticContentServer, parse_range_header
from .. import views

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -246,7 +246,6 @@ def test_range_request_multiple_ranges(self):
"""
first_byte = self.length_unlocked / 4
last_byte = self.length_unlocked / 2
# lint-amnesty, pylint: disable=bad-option-value, unicode-format-string
resp = self.client.get(self.url_unlocked, HTTP_RANGE='bytes={first}-{last}, -100'.format(
first=first_byte, last=last_byte))

Expand Down Expand Up @@ -356,8 +355,8 @@ def test_cache_headers_without_ttl_locked(self, mock_get_cache_ttl):
assert 'private, no-cache, no-store' == resp['Cache-Control']

def test_get_expiration_value(self):
start_dt = datetime.datetime.strptime("Thu, 01 Dec 1983 20:00:00 GMT", HTTP_DATE_FORMAT)
near_expire_dt = StaticContentServer.get_expiration_value(start_dt, 55)
start_dt = datetime.datetime.strptime("Thu, 01 Dec 1983 20:00:00 GMT", views.HTTP_DATE_FORMAT)
near_expire_dt = views.get_expiration_value(start_dt, 55)
assert 'Thu, 01 Dec 1983 20:00:55 GMT' == near_expire_dt

@patch('openedx.core.djangoapps.contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents')
Expand All @@ -371,7 +370,7 @@ def test_cache_is_cdn_with_normal_request(self, mock_get_cdn_user_agents):
request_factory = RequestFactory()
browser_request = request_factory.get('/fake', HTTP_USER_AGENT='Chrome 1234')

is_from_cdn = StaticContentServer.is_cdn_request(browser_request)
is_from_cdn = views.is_cdn_request(browser_request)
assert is_from_cdn is False

@patch('openedx.core.djangoapps.contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents')
Expand All @@ -385,7 +384,7 @@ def test_cache_is_cdn_with_cdn_request(self, mock_get_cdn_user_agents):
request_factory = RequestFactory()
browser_request = request_factory.get('/fake', HTTP_USER_AGENT='Amazon CloudFront')

is_from_cdn = StaticContentServer.is_cdn_request(browser_request)
is_from_cdn = views.is_cdn_request(browser_request)
assert is_from_cdn is True

@patch('openedx.core.djangoapps.contentserver.models.CdnUserAgentsConfig.get_cdn_user_agents')
Expand All @@ -400,7 +399,7 @@ def test_cache_is_cdn_with_cdn_request_multiple_user_agents(self, mock_get_cdn_u
request_factory = RequestFactory()
browser_request = request_factory.get('/fake', HTTP_USER_AGENT='Amazon CloudFront')

is_from_cdn = StaticContentServer.is_cdn_request(browser_request)
is_from_cdn = views.is_cdn_request(browser_request)
assert is_from_cdn is True


Expand All @@ -415,7 +414,7 @@ def setUp(self):
self.content_length = 10000

def test_bytes_unit(self):
unit, __ = parse_range_header('bytes=100-', self.content_length)
unit, __ = views.parse_range_header('bytes=100-', self.content_length)
assert unit == 'bytes'

@ddt.data(
Expand All @@ -428,7 +427,7 @@ def test_bytes_unit(self):
)
@ddt.unpack
def test_valid_syntax(self, header_value, excepted_ranges_length, expected_ranges):
__, ranges = parse_range_header(header_value, self.content_length)
__, ranges = views.parse_range_header(header_value, self.content_length)
assert len(ranges) == excepted_ranges_length
assert ranges == expected_ranges

Expand All @@ -446,5 +445,5 @@ def test_valid_syntax(self, header_value, excepted_ranges_length, expected_range
@ddt.unpack
def test_invalid_syntax(self, header_value, exception_class, exception_message_regex):
self.assertRaisesRegex(
exception_class, exception_message_regex, parse_range_header, header_value, self.content_length
exception_class, exception_message_regex, views.parse_range_header, header_value, self.content_length
)
Loading

0 comments on commit a100166

Please sign in to comment.