Skip to content

Commit

Permalink
fix: don't urljoin empty string (openedx#34516)
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenk authored Apr 16, 2024
1 parent 1244a9f commit 8d8ff29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lms/djangoapps/ora_staff_grader/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def get_download_url(self, obj):
"""
Get the representation for SerializerMethodField `downloadUrl`
"""
if not obj.get("download_url"):
return ""

return urljoin(settings.LMS_ROOT_URL, obj.get("download_url"))


Expand Down
18 changes: 18 additions & 0 deletions lms/djangoapps/ora_staff_grader/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,24 @@ def test_uploaded_file_serializer_with_full_url(self):
}
assert data == expected_value

def test_no_download_url(self):
"""Test UploadedFileSerializer in the case where a URL was not found"""
input_data = {
"download_url": "",
"description": "Test description",
"name": "Test name",
"size": 78222,
}

data = UploadedFileSerializer(input_data).data
expected_value = {
"downloadUrl": "",
"description": input_data["description"],
"name": input_data["name"],
"size": input_data["size"],
}
assert data == expected_value


@ddt.ddt
class TestResponseSerializer(TestCase):
Expand Down

0 comments on commit 8d8ff29

Please sign in to comment.