def test_put_xml_into_object_store_calls_get_xml_data(
         self, mk_get_xml_data, mk_put_object_in_object_store):
     MockZipFile = Mock()
     MockZipFile.read.return_value = b"1806-907X-rba-53-01-1-8.xml"
     put_xml_into_object_store(MockZipFile, "1806-907X-rba-53-01-1-8.xml")
     mk_get_xml_data.assert_any_call(b"1806-907X-rba-53-01-1-8.xml",
                                     "1806-907X-rba-53-01-1-8")
 def test_put_xml_into_object_store_puts_xml_in_object_store(
         self, mk_get_xml_data, mk_put_object_in_object_store):
     MockZipFile = Mock()
     MockZipFile.read.return_value = b""
     mk_get_xml_data.return_value = self.xml_data
     put_xml_into_object_store(MockZipFile, "1806-907X-rba-53-01-1-8.xml")
     mk_put_object_in_object_store.assert_any_call(
         MockZipFile.read.return_value,
         self.xml_data["issn"],
         self.xml_data["scielo_id"],
         "1806-907X-rba-53-01-1-8.xml",
     )
 def test_put_xml_into_object_store_error_if_zip_read_error(
         self, mk_get_xml_data, mk_put_object_in_object_store):
     MockZipFile = MagicMock()
     MockZipFile.__str__.return_value = "MockZipFile"
     MockZipFile.read.side_effect = KeyError(
         "File not found in the archive")
     with self.assertRaises(PutXMLInObjectStoreException) as exc_info:
         put_xml_into_object_store(MockZipFile,
                                   "1806-907X-rba-53-01-1-8.xml")
     self.assertEqual(
         str(exc_info.exception),
         'Could not read file "1806-907X-rba-53-01-1-8.xml" from zipfile "MockZipFile": '
         "'File not found in the archive'")
Exemple #4
0
    def test_put_xml_into_object_store_error_if_empty_scielo_id(
            self, mk_get_xml_data, mk_put_object_in_object_store):
        xml = self.xml_data
        del (xml['scielo_id'])

        MockZipFile = Mock()
        MockZipFile.read.return_value = b""
        mk_get_xml_data.return_value = xml

        with self.assertRaises(Pidv3Exception) as exc_info:
            put_xml_into_object_store(MockZipFile,
                                      "1806-907X-rba-53-01-1-8.xml")
        self.assertEqual(
            str(exc_info.exception),
            'Could not get scielo id v3',
        )
    def test_put_xml_into_object_store_return_data_xml(
            self, mk_get_xml_data, mk_put_object_in_object_store):
        MockZipFile = Mock()
        MockZipFile.read.return_value = b""
        mk_get_xml_data.return_value = self.xml_data
        mk_put_object_in_object_store.return_value = \
            "http://minio/documentstore/1806-907X-rba-53-01-1-8.xml"

        result = put_xml_into_object_store(MockZipFile,
                                           "1806-907X-rba-53-01-1-8.xml")
        self.assertEqual(
            "http://minio/documentstore/1806-907X-rba-53-01-1-8.xml",
            result["xml_url"])
Exemple #6
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)
    """
    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 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)
 def test_put_xml_into_object_reads_xml_from_zip(
         self, mk_get_xml_data, mk_put_object_in_object_store):
     MockZipFile = Mock()
     put_xml_into_object_store(MockZipFile, "1806-907X-rba-53-01-1-8.xml")
     MockZipFile.read.assert_any_call("1806-907X-rba-53-01-1-8.xml")