Skip to content

Commit

Permalink
fix: BFF peer file URLS (#2128)
Browse files Browse the repository at this point in the history
* fix: get correct download URL for assessments

* test: get correct download URL for assessments

* chore: bump ORA to 6.0.10
  • Loading branch information
nsprenkle authored Nov 30, 2023
1 parent 3e4066d commit 9a30eca
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion openassessment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Initialization Information for Open Assessment Module
"""

__version__ = '6.0.9'
__version__ = '6.0.10'
30 changes: 11 additions & 19 deletions openassessment/xblock/ui_mixins/mfe/assessment_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Serializer,
BooleanField,
)
from openassessment.data import OraSubmissionAnswerFactory
from openassessment.xblock.ui_mixins.mfe.serializer_utils import NullField


Expand Down Expand Up @@ -91,10 +92,10 @@ class UnweightedPeerAssessmentsSerializer(Serializer):


class SubmissionFileSerializer(Serializer):
fileUrl = URLField(source="file_key")
fileDescription = CharField(source="file_description")
fileName = CharField(source="file_name")
fileSize = IntegerField(source="file_size")
fileUrl = URLField(source="file.url")
fileDescription = CharField(source="file.description")
fileName = CharField(source="file.name")
fileSize = IntegerField(source="file.size")
fileIndex = IntegerField(source="file_index")


Expand Down Expand Up @@ -169,28 +170,19 @@ def get_textResponses(self, instance):
return [part["text"] for part in answer_text_parts]

def get_uploadedFiles(self, instance):
# coerce to a similar shape for easier serialization
files = []

if not instance["answer"].get("file_keys"):
return None

for i, file_key in enumerate(instance["answer"]["file_keys"]):
file_data = {
"file_key": file_key,
"file_description": instance["answer"]["files_descriptions"][i],
"file_name": instance["answer"]["files_names"][i],
"file_size": instance["answer"]["files_sizes"][i],
"file_index": i,
}
response = OraSubmissionAnswerFactory.parse_submission_raw_answer(instance['answer'])
uploaded_files = []

for index, uploaded_file in enumerate(response.get_file_uploads(generate_urls=True)):
# Don't serialize deleted / missing files
if not file_data["file_name"] and not file_data["file_description"]:
if uploaded_file.url is None:
continue
uploaded_files.append(SubmissionFileSerializer(({'file': uploaded_file, 'file_index': index})).data)

files.append(file_data)

return [SubmissionFileSerializer(file).data for file in files]
return uploaded_files


class MfeAssessmentCriterionSerializer(Serializer):
Expand Down
16 changes: 12 additions & 4 deletions openassessment/xblock/ui_mixins/mfe/test_assessment_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ def _mock_file(self, xblock, student_item_dict=None, **file_data):
@patch(
"openassessment.xblock.apis.submissions.submissions_api.FileAPI.get_uploads_for_submission"
)
@patch("openassessment.data.ZippedListSubmissionAnswer._safe_get_download_url")
@scenario("data/file_upload_scenario.xml", user_id="Alan")
def test_files(self, xblock, mock_get_files):
def test_files(self, xblock, mock_get_download_url, mock_get_files):
# Given we have a response
submission_text = ["Foo", "Bar"]
submission = None
Expand Down Expand Up @@ -130,23 +131,30 @@ def test_files(self, xblock, mock_get_files):
xblock, submission_text=submission_text
)

mock_urls = [
f"Alan/edX/Enchantment_101/April_1/{xblock.scope_ids.usage_id}",
None,
f"Alan/edX/Enchantment_101/April_1/{xblock.scope_ids.usage_id}/2",
]

mock_get_download_url.side_effect = mock_urls

# When I load my response
data = AssessmentResponseSerializer(submission).data

# I get the appropriate response (test URLs use usage ID)
expected_url = f"Alan/edX/Enchantment_101/April_1/{xblock.scope_ids.usage_id}"
expected_response = {
"textResponses": submission_text,
"uploadedFiles": [
{
"fileUrl": expected_url,
"fileUrl": mock_urls[0],
"fileDescription": "bar",
"fileName": "foo",
"fileSize": 1337,
"fileIndex": 0,
},
{
"fileUrl": f"{expected_url}/2",
"fileUrl": mock_urls[2],
"fileDescription": "buzz",
"fileName": "baz",
"fileSize": 2049,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edx-ora2",
"version": "6.0.9",
"version": "6.0.10",
"repository": "https://github.com/openedx/edx-ora2.git",
"dependencies": {
"@edx/frontend-build": "^6.1.1",
Expand Down

0 comments on commit 9a30eca

Please sign in to comment.