Skip to content

Commit

Permalink
chore: handle PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Nov 24, 2023
1 parent 33a0ce5 commit 8512c51
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
14 changes: 7 additions & 7 deletions filesmanager/filesmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,20 +1058,20 @@ def download_content(self, data, suffix=''): # pylint: disable=unused-argument
task_result = create_zip_file_task.delay(contents)
return {
"status": "success",
"task_id": task_result.id
"task_id": task_result.id,
}

@XBlock.json_handler
def download_status(self, data, suffix=''): # pylint: disable=unused-argument
"""
Get the status of the async task.
Get the status of the download zip async task.
Arguments:
task_id: the task ID of the async task.
task_id: the task ID of download zip async task.
Returns:
status: the status of the async task.
result: the result of the async task.
status: the status of the download zip async task.
result: the result of the download zip async task.
"""
task_id = data.get("task_id")
if not task_id:
Expand All @@ -1092,11 +1092,11 @@ def download_status(self, data, suffix=''): # pylint: disable=unused-argument
except TypeError as e:
log.exception(e)
status = "ERROR"
result = "Something went wrong. Please try again the download."
result = "Something went wrong. Please try again later."

return {
"status": status,
"result": result
"result": result,
}

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion filesmanager/static/html/bundle.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion filesmanager/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_xblock_download_content_without_contents(self):

def test_xblock_download_status(self):
"""
Test that the xblock returns the correct status.
Test that the xblock handler used to get tasks status returns the correct information.
"""
data = {
"task_id": 'task_id',
Expand All @@ -152,6 +152,9 @@ def test_xblock_download_status(self):
})

def test_xblock_download_status_not_found(self):
"""
Test that the xblock handler used to get tasks status returns an error when the task is not found.
"""
data = {
"task_id": 'task_id',
}
Expand All @@ -173,6 +176,9 @@ def test_xblock_download_status_not_found(self):
})

def test_xblock_download_status_with_exception(self):
"""
Test that the xblock handler used to get tasks status returns an error when the task fails.
"""
data = {
"task_id": 'task_id',
}
Expand All @@ -195,6 +201,9 @@ def test_xblock_download_status_with_exception(self):
})

def test_xblock_download_status_without_task_id(self):
"""
Test that the xblock handler used to get tasks status returns an error when the task ID is not provided.
"""
data = {}

request = Mock()
Expand Down
12 changes: 6 additions & 6 deletions react-app/components/FileManager/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ const FileManager = (props) => {
};

const downloadFiles = (filesToDownload) => {
downloadFilesTemp(filesToDownload)
downloadFilesZip(filesToDownload)
};

const downloadFilesTemp = async (filesToDownload) => {
const downloadFilesZip = async (filesToDownload) => {
try {
const createContentData = await downloadContent({ contents: filesToDownload });
if (createContentData.status !== StatusCodes.OK) {
throw new Error('Download content has failed: Unexpected status code');
}
let data = createContentData.data;
getStatus(data.task_id)
getStatusFromZipTask(data.task_id)

return Promise.resolve('Download was successful');
} catch (error) {
return Promise.reject('An error has ocurred while downloading assets');
}
};

const getStatus = async (taskID) => {
const getStatusFromZipTask = async (taskID) => {
const createContentData = await downloadStatus(taskID);
if (createContentData.status !== StatusCodes.OK) {
throw new Error('Fetching task status has failed: Unexpected status code');
Expand All @@ -91,10 +91,10 @@ const FileManager = (props) => {
onError()
} else {
setTimeout(() => {
getStatus(taskID)
getStatusFromZipTask(taskID)
}, 1000)
}
return Promise.resolve('Fetching download was successfully');
return Promise.resolve('Fetching download was successful');
}

const {
Expand Down

0 comments on commit 8512c51

Please sign in to comment.