diff --git a/openassessment/data.py b/openassessment/data.py index 261c92ae1d..76336edc8b 100644 --- a/openassessment/data.py +++ b/openassessment/data.py @@ -578,16 +578,13 @@ def _build_response_file_links(cls, submission): string that contains newline-separated URLs to each of the files uploaded for this submission. """ file_links = '' - sep = "\n" + sep = "\n" # pylint: disable=unused-variable base_url = getattr(settings, 'LMS_ROOT_URL', '') from openassessment.xblock.openassessmentblock import OpenAssessmentBlock file_downloads = OpenAssessmentBlock.get_download_urls_from_submission(submission) - for url, _description, _filename, _size, _show_delete in file_downloads: - if file_links: - file_links += sep - file_links += urljoin(base_url, url) - return file_links + file_links = [urljoin(base_url, file_download.get('download_url')) for file_download in file_downloads] + return "\n".join(file_links) @classmethod def collect_ora2_data(cls, course_id): diff --git a/openassessment/tests/test_data.py b/openassessment/tests/test_data.py index ad95ee1110..92b37251c4 100644 --- a/openassessment/tests/test_data.py +++ b/openassessment/tests/test_data.py @@ -15,7 +15,7 @@ from freezegun import freeze_time from django.core.management import call_command -from django.test import TestCase +from django.test import TestCase, override_settings from submissions import api as sub_api, team_api as team_sub_api import openassessment.assessment.api.peer as peer_api @@ -532,6 +532,26 @@ def test_build_feedback_cell(self): self.assertEqual(feedback_cell, "") + @override_settings(LMS_ROOT_URL="https://example.com") + @patch('openassessment.xblock.openassessmentblock.OpenAssessmentBlock.get_download_urls_from_submission') + def test_build_response_file_links(self, mock_method): + """ + Test _build_response_file_links method. + + Ensures that the method returns the expected file links based on the given submission. + """ + expected_result = "https://example.com/file1.pdf\nhttps://example.com/file2.png\nhttps://example.com/file3.jpeg" + file_downloads = [ + {'download_url': '/file1.pdf'}, + {'download_url': '/file2.png'}, + {'download_url': '/file3.jpeg'}, + ] + mock_method.return_value = file_downloads + # pylint: disable=protected-access + result = OraAggregateData._build_response_file_links('test submission') + + self.assertEqual(result, expected_result) + @ddt.ddt @patch.dict('django.conf.settings.FEATURES', {'ENABLE_ORA_USERNAMES_ON_DATA_EXPORT': True})