def document_to_delete(zipfile, sps_xml_file):
    parser = etree.XMLParser(remove_blank_text=True, no_network=True)
    try:
        metadata = SPS_Package(etree.XML(zipfile.read(sps_xml_file), parser),
                               sps_xml_file)
    except (etree.XMLSyntaxError, TypeError, KeyError) as exc:
        raise DocumentToDeleteException(str(exc)) from None
    else:
        if metadata.is_document_deletion:
            if metadata.scielo_id is None:
                raise DocumentToDeleteException("Missing element in XML")
            return metadata.scielo_id
 def test_delete_documents_logs_error_if_document_to_delete_error(
         self, MockZipFile, mk_document_to_delete, MockLogger,
         mk_delete_doc_from_kernel):
     mk_document_to_delete.side_effect = DocumentToDeleteException(
         "XML Error")
     delete_documents(**self.kwargs)
     mk_delete_doc_from_kernel.assert_not_called()
     for xml_filename in self.kwargs["xmls_filenames"]:
         with self.subTest(xml_filename=xml_filename):
             MockLogger.error.assert_any_call(
                 'Error reading document "%s": %s', xml_filename,
                 "XML Error")