def test_legacy_export_as_marc_falsy_value(): falsy_value = {'001': ''} expected = '<record>\n</record>\n' result = legacy_export_as_marc(falsy_value) assert expected == result
def test_legacy_export_as_marc_empty_json(): empty_json = {} expected = '<record>\n</record>\n' result = legacy_export_as_marc(empty_json) assert expected == result
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")
def test_legacy_export_as_marc_json_with_controlfield(): json_with_controlfield = {'001': '4328'} expected = ('<record>\n' ' <controlfield tag="001">4328</controlfield>\n' '</record>\n') result = legacy_export_as_marc(json_with_controlfield) assert expected == result
def test_legacy_export_as_marc_handles_numbers(): record = { '773': [ { 'y': 1975 }, ], } expected = ('<record>\n' ' <datafield tag="773" ind1="" ind2="">\n' ' <subfield code="y">1975</subfield>\n' ' </datafield>\n' '</record>\n') result = legacy_export_as_marc(record) assert expected == result
def test_legacy_export_as_marc_handles_unicode(): record = { '100': [ { 'a': u'Kätlne, J.' }, ], } expected = (u'<record>\n' u' <datafield tag="100" ind1="" ind2="">\n' u' <subfield code="a">Kätlne, J.</subfield>\n' u' </datafield>\n' u'</record>\n') result = legacy_export_as_marc(record) assert expected == result