diff --git a/lms/djangoapps/ora_staff_grader/serializers.py b/lms/djangoapps/ora_staff_grader/serializers.py index 525fe7cc393e..5ba77d5fef65 100644 --- a/lms/djangoapps/ora_staff_grader/serializers.py +++ b/lms/djangoapps/ora_staff_grader/serializers.py @@ -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")) diff --git a/lms/djangoapps/ora_staff_grader/tests/test_serializers.py b/lms/djangoapps/ora_staff_grader/tests/test_serializers.py index d6f4abcd5b83..e03fd81dec6d 100644 --- a/lms/djangoapps/ora_staff_grader/tests/test_serializers.py +++ b/lms/djangoapps/ora_staff_grader/tests/test_serializers.py @@ -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):