def test_register_update_doc_into_kernel_put_to_kernel_doc(self, mk_hooks): payload = {"data": self.xml_data["xml_url"], "assets": self.xml_data["assets"]} register_update_doc_into_kernel(self.xml_data) mk_hooks.kernel_connect.assert_any_call( "/documents/FX6F3cbyYmmwvtGmMB7WCgr", "PUT", payload )
def test_register_update_doc_into_kernel_put_to_kernel_pdfs(self, mk_hooks): register_update_doc_into_kernel(self.xml_data) for pdf_payload in self.xml_data["pdfs"]: with self.subTest(pdf_payload=pdf_payload): mk_hooks.kernel_connect.assert_any_call( "/documents/FX6F3cbyYmmwvtGmMB7WCgr/renditions", "PATCH", pdf_payload, )
def register_update_documents(sps_package, xmls_to_preserve): """ Registra/atualiza documentos informados e seus respectivos ativos digitais e renditions no Minio e no Kernel. list docs_to_preserve: lista de XMLs para manter no Kernel (Registrar ou atualizar) """ Logger.debug("register_update_documents IN") with ZipFile(sps_package) as zipfile: synchronized_docs_metadata = [] for i, xml_filename in enumerate(xmls_to_preserve): Logger.info( 'Reading XML file "%s" from ZIP file "%s" [%s/%s]', xml_filename, sps_package, i, len(xmls_to_preserve), ) try: xml_data = put_xml_into_object_store(zipfile, xml_filename) except PutXMLInObjectStoreException as exc: Logger.info( 'Could not put document "%s" in object store: %s', xml_filename, str(exc), ) else: assets_and_pdfs_data = put_assets_and_pdfs_in_object_store( zipfile, xml_data) _document_metadata = deepcopy(xml_data) _document_metadata.update(assets_and_pdfs_data) try: register_update_doc_into_kernel(_document_metadata) except RegisterUpdateDocIntoKernelException as exc: Logger.info( 'Could not register or update document "%s" in Kernel: %s', xml_filename, str(exc), ) else: synchronized_docs_metadata.append(xml_data) Logger.debug("register_update_documents OUT") return synchronized_docs_metadata
def test_register_update_doc_into_kernel_put_to_kernel_pdfs_hook_HttpError( self, mk_hooks, MockLogger ): payload = {"data": self.xml_data["xml_url"], "assets": self.xml_data["assets"]} mk_hooks.kernel_connect.side_effect = [ None, None, requests.exceptions.HTTPError("404 Client Error: Not Found"), ] with self.assertRaises(RegisterUpdateDocIntoKernelException): register_update_doc_into_kernel(self.xml_data) MockLogger.info.assert_any_call( 'Putting Rendition "%s" to Kernel', "1806-907X-rba-53-01-1-8.pdf" ) mk_hooks.kernel_connect.assert_any_call( "/documents/FX6F3cbyYmmwvtGmMB7WCgr/renditions", "PATCH", self.xml_data["pdfs"][0], )
def register_update_documents(sps_package, xmls_to_preserve): """ Registra/atualiza documentos informados e seus respectivos ativos digitais e renditions no Minio e no Kernel. list docs_to_preserve: lista de XMLs para manter no Kernel (Registrar ou atualizar) Não deve cadastrar documentos que não tenha ``scielo-id`` """ executions = [] Logger.debug("register_update_documents IN") with ZipFile(sps_package) as zipfile: synchronized_docs_metadata = [] for i, xml_filename in enumerate(xmls_to_preserve): Logger.info( 'Reading XML file "%s" from ZIP file "%s" [%s/%s]', xml_filename, sps_package, i, len(xmls_to_preserve), ) execution = {"file_name": xml_filename} try: xml_data = put_xml_into_object_store(zipfile, xml_filename) except (PutXMLInObjectStoreException, Pidv3Exception) as exc: Logger.error( 'Could not put document "%s" in object store: %s', xml_filename, str(exc), ) execution.update({"failed": True, "error": str(exc)}) else: assets_and_pdfs_data = put_assets_and_pdfs_in_object_store(zipfile, xml_data) _document_metadata = deepcopy(xml_data) _document_metadata.update(assets_and_pdfs_data) try: register_update_doc_into_kernel(_document_metadata) except RegisterUpdateDocIntoKernelException as exc: Logger.error( 'Could not register or update document "%s" in Kernel: %s', xml_filename, str(exc), ) execution.update( { "pid": xml_data.get("scielo_id"), "failed": True, "error": str(exc), } ) else: synchronized_docs_metadata.append(xml_data) execution.update( { "pid": xml_data.get("scielo_id"), "payload": _document_metadata, } ) executions.append(execution) Logger.debug("register_update_documents OUT") return (synchronized_docs_metadata, executions)