Esempio n. 1
0
def test_make_robotupload_marcxml():
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri(
            'POST', 'http://localhost:5000/batchuploader/robotupload/insert')

        make_robotupload_marcxml('http://localhost:5000', '<record></record>',
                                 'insert')
def test_make_robotupload_marcxml():
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri(
            'POST', 'http://localhost:5000/batchuploader/robotupload/insert'
        )

        make_robotupload_marcxml(
            'http://localhost:5000', '<record></record>', 'insert')
Esempio n. 3
0
def test_make_robotupload_marcxml():
    httpretty.HTTPretty.allow_net_connect = False
    httpretty.register_uri(
        httpretty.POST, 'http://localhost:5000/batchuploader/robotupload/insert')

    make_robotupload_marcxml(
        'http://localhost:5000', '<record></record>', 'insert')

    httpretty.HTTPretty.allow_net_connect = True
def test_make_robotupload_marcxml():
    httpretty.HTTPretty.allow_net_connect = False
    httpretty.register_uri(
        httpretty.POST, 'http://localhost:5000/batchuploader/robotupload/insert')

    make_robotupload_marcxml(
        'http://localhost:5000', '<record></record>', 'insert')

    httpretty.HTTPretty.allow_net_connect = True
Esempio n. 5
0
def test_make_robotupload_marcxml_falls_back_to_config_when_url_is_none():
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri(
            'POST', 'http://inspirehep.net/batchuploader/robotupload/insert')

        config = {'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net'}

        with patch.dict(current_app.config, config):
            make_robotupload_marcxml(None, '<record></record>', 'insert')
def test_make_robotupload_marcxml_raises_when_url_is_none_and_config_is_empty():
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri(
            'POST', 'http://localhost:5000/batchuploader/robotupload/insert'
        )

        with pytest.raises(ValueError) as excinfo:
            make_robotupload_marcxml(None, '<record></record>', 'insert')
        assert 'LEGACY_ROBOTUPLOAD_URL' in str(excinfo.value)
Esempio n. 7
0
def test_make_robotupload_marcxml_raises_when_url_is_none_and_config_is_empty(
):
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri(
            'POST', 'http://localhost:5000/batchuploader/robotupload/insert')

        with pytest.raises(ValueError) as excinfo:
            make_robotupload_marcxml(None, '<record></record>', 'insert')
        assert 'LEGACY_ROBOTUPLOAD_URL' in str(excinfo.value)
def test_make_robotupload_marcxml_raises_when_url_is_none_and_config_is_empty():
    httpretty.HTTPretty.allow_net_connect = False
    httpretty.register_uri(
        httpretty.POST, 'http://localhost:5000/batchuploader/robotupload/insert')

    with pytest.raises(ValueError) as excinfo:
        make_robotupload_marcxml(None, '<record></record>', 'insert')
    assert 'LEGACY_ROBOTUPLOAD_URL' in str(excinfo.value)

    httpretty.HTTPretty.allow_net_connect = True
def test_make_robotupload_marcxml_falls_back_to_config_when_url_is_none():
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri(
            'POST', 'http://inspirehep.net/batchuploader/robotupload/insert'
        )

        config = {'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net'}

        with patch.dict(current_app.config, config):
            make_robotupload_marcxml(None, '<record></record>', 'insert')
Esempio n. 10
0
def test_make_robotupload_marcxml_raises_when_url_is_none_and_config_is_empty():
    httpretty.HTTPretty.allow_net_connect = False
    httpretty.register_uri(
        httpretty.POST, 'http://localhost:5000/batchuploader/robotupload/insert')

    with pytest.raises(ValueError) as excinfo:
        make_robotupload_marcxml(None, '<record></record>', 'insert')
    assert 'LEGACY_ROBOTUPLOAD_URL' in str(excinfo.value)

    httpretty.HTTPretty.allow_net_connect = True
def test_make_robotupload_marcxml_falls_back_to_config_when_url_is_none():
    httpretty.HTTPretty.allow_net_connect = False
    httpretty.register_uri(
        httpretty.POST, 'http://inspirehep.net/batchuploader/robotupload/insert')

    config = {'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net'}

    with patch.dict(current_app.config, config):
        make_robotupload_marcxml(None, '<record></record>', 'insert')

    httpretty.HTTPretty.allow_net_connect = True
Esempio n. 12
0
def test_make_robotupload_marcxml_falls_back_to_config_when_url_is_none():
    httpretty.HTTPretty.allow_net_connect = False
    httpretty.register_uri(
        httpretty.POST, 'http://inspirehep.net/batchuploader/robotupload/insert')

    config = {'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net'}

    with patch.dict(current_app.config, config):
        make_robotupload_marcxml(None, '<record></record>', 'insert')

    httpretty.HTTPretty.allow_net_connect = True
Esempio n. 13
0
def test_make_robotupload_marcxml_handles_unicode():
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri(
            'POST', 'http://localhost:5000/batchuploader/robotupload/insert')

        snippet = (u'<record>'
                   u'  <datafield tag="700" ind1=" " ind2=" ">'
                   u'    <subfield code="a">André, M.</subfield>'
                   u'  </datafield>'
                   u'</record>')  # record/1503367

        make_robotupload_marcxml('http://localhost:5000', snippet, 'insert')
def test_make_robotupload_marcxml_handles_non_unicode():
    with requests_mock.Mocker() as requests_mocker:
        requests_mocker.register_uri(
            'POST', 'http://localhost:5000/batchuploader/robotupload/insert'
        )

        snippet = (
            u'<record>'
            u'  <datafield tag="700" ind1=" " ind2=" ">'
            u'    <subfield code="a">André, M.</subfield>'
            u'  </datafield>'
            u'</record>'
        ).encode('utf-8')  # record/1503367

        make_robotupload_marcxml('http://localhost:5000', snippet, 'insert')
Esempio n. 15
0
def test_make_robotupload_marcxml_handles_utf8():
    httpretty.HTTPretty.allow_net_connect = False
    httpretty.register_uri(
        httpretty.POST,
        'http://localhost:5000/batchuploader/robotupload/insert')

    snippet = ('<record>'
               '  <datafield tag="700" ind1=" " ind2=" ">'
               '    <subfield code="a">André, M.</subfield>'
               '  </datafield>'
               '</record>')  # record/1503367

    make_robotupload_marcxml('http://localhost:5000', snippet, 'insert')

    httpretty.HTTPretty.allow_net_connect = True
Esempio n. 16
0
    def _send_robotupload(obj, eng):
        from invenio_workflows.errors import WorkflowError
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        combined_callback_url = os.path.join(cfg["CFG_SITE_URL"], callback_url)
        model = eng.workflow_definition.model(obj)
        sip = model.get_latest_sip()
        marcxml = sip.package
        result = make_robotupload_marcxml(
            url=url,
            marcxml=marcxml,
            callback_url=combined_callback_url,
            mode=mode,
            nonce=obj.id
        )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error("Your IP is not in "
                              "CFG_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                              "on host")
                obj.log.error(result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise WorkflowError(txt, eng.uuid, obj.id)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            eng.halt("Waiting for robotupload: {0}".format(result.text))
        obj.log.info("end of upload")
def test_make_robotupload_marcxml_handles_utf8():
    httpretty.HTTPretty.allow_net_connect = False
    httpretty.register_uri(
        httpretty.POST, 'http://localhost:5000/batchuploader/robotupload/insert')

    snippet = (
        '<record>'
        '  <datafield tag="700" ind1=" " ind2=" ">'
        '    <subfield code="a">André, M.</subfield>'
        '  </datafield>'
        '</record>'
    )  # record/1503367

    make_robotupload_marcxml('http://localhost:5000', snippet, 'insert')

    httpretty.HTTPretty.allow_net_connect = True
Esempio n. 18
0
    def _send_robotupload(obj, eng):
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        callback_url = os.path.join(current_app.config["SERVER_NAME"],
                                    "callback/workflows/robotupload")

        marcxml = obj.get_extra_data().get("marcxml")

        if not marcxml:
            obj.log.error("No MARCXML found in extra data.")

        result = make_robotupload_marcxml(
            url=None,
            marcxml=marcxml,
            callback_url=callback_url,
            mode=mode,
            nonce=obj.id
        )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error("Your IP is not in "
                              "CFG_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                              "on host")
                obj.log.error(result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise WorkflowError(txt, eng.uuid, obj.id)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            if mode != "holdingpen":
                eng.halt("Waiting for robotupload: {0}".format(result.text))
        obj.log.info("end of upload")
Esempio n. 19
0
    def _send_robotupload(obj, eng):
        from inspirehep.dojson.utils import legacy_export_as_marc
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        combined_callback_url = os.path.join(
            current_app.config["SERVER_NAME"],
            callback_url
        )
        marc_json = marcxml_processor.do(obj.data)
        marcxml = legacy_export_as_marc(marc_json)
        result = make_robotupload_marcxml(
            url=url,
            marcxml=marcxml,
            callback_url=combined_callback_url,
            mode=mode,
            nonce=obj.id,
            priority=5,
        )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error("Your IP is not in "
                              "app.config_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                              "on host")
                obj.log.error(result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise Exception(txt)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            eng.halt("Waiting for robotupload: {0}".format(result.text))
        obj.log.info("end of upload")
Esempio n. 20
0
    def _send_robotupload(obj, eng):
        from invenio_base.globals import cfg
        from invenio_workflows.errors import WorkflowError
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        callback_url = os.path.join(cfg["CFG_SITE_URL"],
                                    "callback/workflows/robotupload")

        marcxml = obj.get_extra_data().get("marcxml")

        if not marcxml:
            obj.log.error("No MARCXML found in extra data.")

        result = make_robotupload_marcxml(
            url=None,
            marcxml=marcxml,
            callback_url=callback_url,
            mode=mode,
            nonce=obj.id
        )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error("Your IP is not in "
                              "CFG_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                              "on host")
                obj.log.error(result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise WorkflowError(txt, eng.uuid, obj.id)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            if mode != "holdingpen":
                eng.halt("Waiting for robotupload: {0}".format(result.text))
        obj.log.info("end of upload")
Esempio n. 21
0
    def _send_robotupload(obj, eng):
        combined_callback_url = ''
        if callback_url:
            combined_callback_url = os.path.join(
                current_app.config["SERVER_NAME"], callback_url)
            if not combined_callback_url.startswith('http'):
                combined_callback_url = "https://{0}".format(
                    combined_callback_url)

        if extra_data_key is not None:
            data = obj.extra_data.get(extra_data_key) or {}
        else:
            data = obj.data
        marc_json = marcxml_processor.do(data)
        marcxml = legacy_export_as_marc(marc_json)

        if current_app.debug:
            # Log what we are sending
            LOGGER.debug(
                "Going to robotupload mode:%s to url:%s:\n%s\n",
                mode,
                url,
                marcxml,
            )

        if not in_production_mode():
            obj.log.debug(
                "Going to robotupload %s to %s:\n%s\n",
                mode,
                url,
                marcxml,
            )
            obj.log.debug("Base object data:\n%s", pformat(data))
            return

        result = make_robotupload_marcxml(
            url=url,
            marcxml=marcxml,
            callback_url=combined_callback_url,
            mode=mode,
            nonce=obj.id,
            priority=5,
        )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error(
                    "Your IP is not in "
                    "app.config_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                    "on host: %s", result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise Exception(txt)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            if callback_url:
                eng.halt("Waiting for robotupload: {0}".format(result.text))

        obj.log.info("end of upload")
Esempio n. 22
0
    def _send_robotupload(obj, eng):
        from inspirehep.dojson.utils import legacy_export_as_marc
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        combined_callback_url = os.path.join(
            current_app.config["SERVER_NAME"],
            callback_url
        )
        if not combined_callback_url.startswith('http'):
            combined_callback_url = "http://{0}".format(combined_callback_url)

        if extra_data_key is not None:
            data = obj.extra_data.get(extra_data_key) or {}
        else:
            data = obj.data
        marc_json = marcxml_processor.do(data)
        marcxml = legacy_export_as_marc(marc_json)

        if not url and current_app.debug:
            # Log what we would send
            current_app.logger.debug(
                "Going to robotupload {mode} to {url}:\n{marcxml}\n".format(
                    url=url,
                    marcxml=marcxml,
                    callback_url=combined_callback_url,
                    mode=mode,
                    nonce=obj.id,
                    priority=5,
                )
            )
            return
        else:
            result = make_robotupload_marcxml(
                url=url,
                marcxml=marcxml,
                callback_url=combined_callback_url,
                mode=mode,
                nonce=obj.id,
                priority=5,
            )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error("Your IP is not in "
                              "app.config_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                              "on host")
                obj.log.error(result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise Exception(txt)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            eng.halt("Waiting for robotupload: {0}".format(result.text))
        obj.log.info("end of upload")
Esempio n. 23
0
    def _send_robotupload(obj, eng):
        from inspirehep.dojson.utils import legacy_export_as_marc
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        combined_callback_url = os.path.join(current_app.config["SERVER_NAME"],
                                             callback_url)
        if not combined_callback_url.startswith('http'):
            combined_callback_url = "http://{0}".format(combined_callback_url)

        if extra_data_key is not None:
            data = obj.extra_data.get(extra_data_key) or {}
        else:
            data = obj.data
        marc_json = marcxml_processor.do(data)
        marcxml = legacy_export_as_marc(marc_json)

        if not url and current_app.debug:
            # Log what we would send
            current_app.logger.debug(
                "Going to robotupload {mode} to {url}:\n{marcxml}\n".format(
                    url=url,
                    marcxml=marcxml,
                    callback_url=combined_callback_url,
                    mode=mode,
                    nonce=obj.id,
                    priority=5,
                ))
            return
        else:
            result = make_robotupload_marcxml(
                url=url,
                marcxml=marcxml,
                callback_url=combined_callback_url,
                mode=mode,
                nonce=obj.id,
                priority=5,
            )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error("Your IP is not in "
                              "app.config_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                              "on host")
                obj.log.error(result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise Exception(txt)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            eng.halt("Waiting for robotupload: {0}".format(result.text))
        obj.log.info("end of upload")
def test_robotupload_bad_xml():
    """Test proper handling when bad MARCXML is sent."""
    httpretty.register_uri(
        httpretty.POST,
        "http://localhost:4000/batchuploader/robotupload/insert",
        body="[ERROR] MARCXML is not valid.\n",
        status=400)
    invalid_marcxml = "record></record>"
    response = make_robotupload_marcxml(
        "http://localhost:4000",
        invalid_marcxml,
        mode="insert",
    )
    assert response.status_code == 400
    assert "not valid" in response.text
def test_robotupload_success_append():
    """Test proper handling when good MARCXML is sent."""
    httpretty.register_uri(
        httpretty.POST,
        "http://localhost:4000/batchuploader/robotupload/append",
        body="[INFO] bibupload batchupload --append /dummy/file/path\n",
        status=200)
    valid_marcxml = "<record></record>"
    response = make_robotupload_marcxml(
        "http://localhost:4000",
        valid_marcxml,
        mode="append",
    )
    assert response.status_code == 200
    assert "[INFO] bibupload batchupload" in response.text
def test_robotupload_success_append():
    """Test proper handling when good MARCXML is sent."""
    httpretty.register_uri(
        httpretty.POST,
        "http://localhost:4000/batchuploader/robotupload/append",
        body="[INFO] bibupload batchupload --append /dummy/file/path\n",
        status=200
    )
    valid_marcxml = "<record></record>"
    response = make_robotupload_marcxml(
        "http://localhost:4000",
        valid_marcxml,
        mode="append",
    )
    assert response.status_code == 200
    assert "[INFO] bibupload batchupload" in response.text
def test_robotupload_bad_xml():
    """Test proper handling when bad MARCXML is sent."""
    httpretty.register_uri(
        httpretty.POST,
        "http://localhost:4000/batchuploader/robotupload/insert",
        body="[ERROR] MARCXML is not valid.\n",
        status=400
    )
    invalid_marcxml = "record></record>"
    response = make_robotupload_marcxml(
        "http://localhost:4000",
        invalid_marcxml,
        mode="insert",
    )
    assert response.status_code == 400
    assert "not valid" in response.text
 def test_robotupload_bad_xml(self):
     """Test proper handling when bad MARCXML is sent."""
     from inspirehep.utils.robotupload import make_robotupload_marcxml
     httpretty.register_uri(
         httpretty.POST,
         "http://localhost:4000/batchuploader/robotupload/insert",
         body="[ERROR] MARCXML is not valid.\n",
         status=400
     )
     invalid_marcxml = "record></record>"
     response = make_robotupload_marcxml(
         "http://localhost:4000",
         invalid_marcxml,
         mode="insert",
     )
     self.assertEqual(response.status_code, 400)
     self.assertTrue("not valid" in response.text)
 def test_robotupload_success_append(self):
     """Test proper handling when good MARCXML is sent."""
     from inspirehep.utils.robotupload import make_robotupload_marcxml
     httpretty.register_uri(
         httpretty.POST,
         "http://localhost:4000/batchuploader/robotupload/append",
         body="[INFO] bibupload batchupload --append /dummy/file/path\n",
         status=200
     )
     valid_marcxml = "<record></record>"
     response = make_robotupload_marcxml(
         "http://localhost:4000",
         valid_marcxml,
         mode="append",
     )
     self.assertEqual(response.status_code, 200)
     self.assertTrue("[INFO] bibupload batchupload" in response.text)
def test_robotupload_callback_url():
    """Test passing of a callback URL."""
    body = ("[INFO] bibupload batchupload --insert /some/path"
            "--callback-url http://localhost")
    httpretty.register_uri(
        httpretty.POST,
        "http://localhost:4000/batchuploader/robotupload/insert",
        body=body,
        status=200)
    valid_marcxml = "<record></record>"
    response = make_robotupload_marcxml(
        "http://localhost:4000",
        valid_marcxml,
        mode="insert",
        callback_url="http://localhost",
    )
    assert response.status_code == 200
    assert "--callback-url http://localhost" in response.text
def test_robotupload_callback_url():
    """Test passing of a callback URL."""
    body = (
        "[INFO] bibupload batchupload --insert /some/path"
        "--callback-url http://localhost"
    )
    httpretty.register_uri(
        httpretty.POST,
        "http://localhost:4000/batchuploader/robotupload/insert",
        body=body,
        status=200
    )
    valid_marcxml = "<record></record>"
    response = make_robotupload_marcxml(
        "http://localhost:4000",
        valid_marcxml,
        mode="insert",
        callback_url="http://localhost",
    )
    assert response.status_code == 200
    assert "--callback-url http://localhost" in response.text
 def test_robotupload_callback_url(self):
     """Test passing of a callback URL."""
     from inspirehep.utils.robotupload import make_robotupload_marcxml
     body = (
         "[INFO] bibupload batchupload --insert /some/path"
         "--callback-url http://localhost"
     )
     httpretty.register_uri(
         httpretty.POST,
         "http://localhost:4000/batchuploader/robotupload/insert",
         body=body,
         status=200
     )
     valid_marcxml = "<record></record>"
     response = make_robotupload_marcxml(
         "http://localhost:4000",
         valid_marcxml,
         mode="insert",
         callback_url="http://localhost",
     )
     self.assertEqual(response.status_code, 200)
     self.assertTrue("--callback-url http://localhost" in response.text)
Esempio n. 33
0
    def _update(obj, eng):
        import dictdiffer

        from lxml import objectify, etree

        from invenio_base.globals import cfg
        from invenio_workflows.utils import convert_marcxml_to_bibfield
        from invenio_records.api import Record

        from inspirehep.utils.robotupload import make_robotupload_marcxml

        try:
            recid = obj.extra_data["recid"]
        except KeyError:
            obj.log.error("Cannot locate record ID")
            return

        callback_url = os.path.join(cfg["CFG_SITE_URL"],
                                    "callback/workflows/continue")

        search_url = "%s?p=recid:%s&of=xm" % (cfg["WORKFLOWS_MATCH_REMOTE_SERVER_URL"], recid)

        prod_data = objectify.parse(search_url)
        # remove controlfields
        root = prod_data.getroot()
        record = root['record']
        while True:
            try:
                record.remove(record['controlfield'])
            except AttributeError:
                break
        prod_data = etree.tostring(record)
        prod_data = convert_marcxml_to_bibfield(prod_data, model=["hep"])
        new_data = dict(obj.data.dumps(clean=True))
        prod_data = dict(prod_data.dumps(clean=True))
        updated_keys = []
        diff = dictdiffer.diff(prod_data, new_data)
        for diff_type, new_key, content in diff:
            if diff_type == 'add':
                if new_key:
                    if isinstance(new_key, list):
                        # ['subject_terms', 0]
                        updated_keys.append(new_key[0])
                    else:
                        # 'subject_terms'
                        updated_keys.append(new_key)
                else:
                    # content must be list of new adds
                    for key in content:
                        updated_keys.append(key)

        updates = dictdiffer.patch(diff, new_data)
        for key in updates.keys():
            if key not in updated_keys:
                del updates[key]
        if updates:
            updates['recid'] = recid
            marcxml = Record(updates).legacy_export_as_marc()
            result = make_robotupload_marcxml(
                url=url,
                marcxml=marcxml,
                callback_url=callback_url,
                mode='correct',
                nonce=obj.id
            )
            if "[INFO]" not in result.text:
                if "cannot use the service" in result.text:
                    # IP not in the list
                    obj.log.error("Your IP is not in "
                                  "CFG_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                                  "on host")
                    obj.log.error(result.text)
                from invenio_workflows.errors import WorkflowError
                txt = "Error while submitting robotupload: {0}".format(result.text)
                raise WorkflowError(txt, eng.uuid, obj.id)
            else:
                obj.log.info("Robotupload sent!")
                obj.log.info(result.text)
                eng.halt("Waiting for robotupload: {0}".format(result.text))
            obj.log.info("end of upload")
        else:
            obj.log.info("No updates to do.")
Esempio n. 34
0
    def _send_robotupload(obj, eng):
        is_update = obj.extra_data.get('is-update')

        if is_update and not current_app.config.get(
                'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY', False):
            obj.log.info(
                'skipping upload to legacy, feature flag ``FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY`` is disabled.'
            )
            return

        combined_callback_url = ''
        if callback_url:
            combined_callback_url = os.path.join(
                current_app.config["SERVER_NAME"], callback_url)
            if not combined_callback_url.startswith('http'):
                combined_callback_url = "https://{0}".format(
                    combined_callback_url)

        if extra_data_key is not None:
            data = obj.extra_data.get(extra_data_key) or {}
        else:
            data = obj.data
        marcxml = record2marcxml(data)

        if current_app.debug:
            # Log what we are sending
            LOGGER.debug(
                "Going to robotupload mode:%s to url:%s:\n%s\n",
                mode,
                url,
                marcxml,
            )

        if not in_production_mode():
            obj.log.debug(
                "Going to robotupload %s to %s:\n%s\n",
                mode,
                url,
                marcxml,
            )
            obj.log.debug("Base object data:\n%s", pformat(data))
            return

        result = make_robotupload_marcxml(
            url=url,
            marcxml=marcxml,
            callback_url=combined_callback_url,
            mode=mode,
            nonce=obj.id,
            priority=5,
        )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error(
                    "Your IP is not in "
                    "app.config_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                    "on host: %s", result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise Exception(txt)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            if callback_url:
                eng.halt("Waiting for robotupload: {0}".format(result.text))

        obj.log.info("end of upload")
Esempio n. 35
0
    def _send_robotupload(obj, eng):
        combined_callback_url = ''
        if callback_url:
            combined_callback_url = os.path.join(
                current_app.config["SERVER_NAME"], callback_url)
            if not combined_callback_url.startswith('http'):
                combined_callback_url = "https://{0}".format(
                    combined_callback_url)

        if extra_data_key is not None:
            data = obj.extra_data.get(extra_data_key) or {}
        else:
            data = obj.data

        if not current_app.config.get(
                'FEATURE_FLAG_ENABLE_SENDING_REFERENCES_TO_LEGACY'):
            data = copy(data)
            data.pop('references', None)

        marcxml = record2marcxml(data)

        if current_app.debug:
            # Log what we are sending
            LOGGER.debug(
                "Going to robotupload mode:%s to url:%s:\n%s\n",
                mode,
                url,
                marcxml,
            )

        if not in_production_mode():
            obj.log.debug(
                "Going to robotupload %s to %s:\n%s\n",
                mode,
                url,
                marcxml,
            )
            obj.log.debug("Base object data:\n%s", pformat(data))
            return

        priority = 5
        if priority_config_key:
            priority = current_app.config.get(priority_config_key, priority)

        result = make_robotupload_marcxml(
            url=url,
            marcxml=marcxml,
            callback_url=combined_callback_url,
            mode=mode,
            nonce=obj.id,
            priority=priority,
        )
        if "[INFO]" not in result.text:
            if "cannot use the service" in result.text:
                # IP not in the list
                obj.log.error(
                    "Your IP is not in "
                    "app.config_BATCHUPLOADER_WEB_ROBOT_RIGHTS "
                    "on host: %s", result.text)
            txt = "Error while submitting robotupload: {0}".format(result.text)
            raise Exception(txt)
        else:
            obj.log.info("Robotupload sent!")
            obj.log.info(result.text)
            if callback_url:
                eng.halt("Waiting for robotupload: {0}".format(result.text))

        obj.log.info("end of upload")