Skip to content

Commit

Permalink
make critical error raised before warning
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas loubrieu committed Jul 23, 2022
1 parent 3fc15c6 commit f457ac7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/pds_doi_service/core/actions/test/update_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ def test_invalid_update_requests(self):
with self.assertRaises(CriticalDOIException):
self._update_action.run(**update_kwargs)

#@patch.object(
#
#)
#def test_update_doi(self):
# pass

if __name__ == "__main__":
unittest.main()
23 changes: 11 additions & 12 deletions src/pds_doi_service/core/actions/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,23 @@ def _update_dois(self, dois):
for updated_doi in dois:
if updated_doi.doi:
existing_doi = self._get_doi_record_from_doi_identifier(updated_doi.doi)
elif self._force:
else:
try:
# try to get DOI from the local database
# try this command first so that it raises an critical exception whatever the force warning status
existing_doi = self._get_doi_record_from_pds_identifier(updated_doi.pds_identifier)
if not self._force:
raise WarningDOIException(
f"Record provided for identifier {updated_doi.pds_identifier} does not have a DOI assigned.\n"
"Add it in the Citation_Information/doi tag in the label\n"
" if the version of PDS4 information model you are using allows it.\n"
"Otherwise ignore this warning"
)
except UnknownIdentifierException as e:
raise CriticalDOIException(
f"The identifier {updated_doi.pds_identifier} does not have DOI yet"
"use the reserve step to get one"
f"The identifier {updated_doi.pds_identifier} does not have DOI yet."
" Use the reserve step to get one"
)

else:
raise WarningDOIException(
f"Record provided for identifier {updated_doi.pds_identifier} does not have a DOI assigned.\n"
"Add it in the Citation_Information/doi tag in the label\n"
" if the version of PDS4 information model you are using allows it.\n"
"Otherwise ignore this warning"
)

updated_doi = self._meld_dois(existing_doi, updated_doi)

updated_dois.append(updated_doi)
Expand Down

0 comments on commit f457ac7

Please sign in to comment.