Skip to content

Commit

Permalink
Added test for when resetting status fails in process_saved_file
Browse files Browse the repository at this point in the history
Fixed bug found by test.
  • Loading branch information
alisonrclarke committed Feb 25, 2021
1 parent 43b8090 commit d051b0c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hepdata/modules/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def process_saved_file(file_path, recid, userid, redirect_url, previous_status):
db.session.commit()

except Exception as ex:
log.error("Exception while cleaning up: " % ex)
log.error("Exception while cleaning up: %s" % ex)

else:
log.debug("Celery will retry task, attempt %s" % process_saved_file.request.retries)
Expand Down
33 changes: 33 additions & 0 deletions tests/submission_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

import logging
import os
import shutil
import time
Expand Down Expand Up @@ -330,3 +331,35 @@ def test_status_reset(app, mocker):

# After initial failure, overall_status should be reset to 'todo'
assert(hepsubmission.overall_status == 'todo')


def test_status_reset_error(app, mocker, caplog):
"""
Test that an error is logged if something goes wrong in the status reset
:return:
"""
caplog.set_level(logging.ERROR)
base_dir = os.path.dirname(os.path.realpath(__file__))
hepsubmission = HEPSubmission(publication_recid=12345,
overall_status='processing',
version=1)
db.session.add(hepsubmission)
db.session.commit()

assert(hepsubmission.overall_status == 'processing')

mocker.patch('hepdata.modules.records.api.process_zip_archive',
side_effect=Exception("Something went wrong"))
mocker.patch('hepdata.modules.records.api.cleanup_submission',
side_effect=Exception("Could not clean up the submission"))

zip_file = os.path.join(base_dir, 'test_data/TestHEPSubmission.zip')
process_saved_file(zip_file, 12345, 1, '', 'todo')

# After initial failure, overall_status has not been able to be reset
assert(hepsubmission.overall_status == 'processing')
assert(len(caplog.records) == 1)

assert(caplog.records[0].levelname == "ERROR")
assert(caplog.records[0].msg
== "Exception while cleaning up: Could not clean up the submission")

0 comments on commit d051b0c

Please sign in to comment.