Skip to content

Commit

Permalink
fix: forming Response Files link in the report
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroAlipov committed Jul 3, 2023
1 parent 20626e4 commit 1af28f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
9 changes: 3 additions & 6 deletions openassessment/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 21 additions & 1 deletion openassessment/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit 1af28f0

Please sign in to comment.