Skip to content

Commit

Permalink
fix: Fix matching of /c4x/ in course asset view urlpatterns
Browse files Browse the repository at this point in the history
This was failing to capture /c4x/ URLs when the `content_server.use_view`
waffle flag was enabled, so we were returning 404s for those during our
rollout test.

Part of #34702
  • Loading branch information
timmc-edx committed Aug 7, 2024
1 parent 35651da commit b402c40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions openedx/core/djangoapps/contentserver/test/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Tests for the view version of course asset serving.
"""

import ddt
from django.test import TestCase
from django.urls import resolve


@ddt.ddt
class UrlsTest(TestCase):
"""
Tests for ensuring that the urlpatterns registered to the view are
appropriate for the URLs that the middleware historically handled.
"""

@ddt.data(
'/c4x/edX/Open_DemoX/asset/images_course_image.jpg',
'/asset-v1:edX+DemoX.1+2T2019+type@asset+block/DemoX-poster.jpg',
'/assets/courseware/v1/0123456789abcdef0123456789abcdef/asset-v1:edX+FAKE101+2024+type@asset+block/HW1.png',
)
def test_sample_urls(self, sample_url):
"""
Regression test -- c4x URL was previously incorrect in urls.py.
"""
assert resolve(sample_url).view_name == 'openedx.core.djangoapps.contentserver.views.course_assets_view'
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/contentserver/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
URL patterns for course asset serving.
"""

from django.urls import path, re_path
from django.urls import re_path

from . import views

# These patterns are incomplete and do not capture the variable
# components of the URLs. That's because the view itself is separately
# parsing the paths, for historical reasons. See docstring on views.py.
urlpatterns = [
path("c4x/", views.course_assets_view),
re_path("^c4x/", views.course_assets_view),
re_path("^asset-v1:", views.course_assets_view),
re_path("^assets/courseware/", views.course_assets_view),
]

0 comments on commit b402c40

Please sign in to comment.