diff --git a/rero_ils/dojson/utils.py b/rero_ils/dojson/utils.py index ee910fd3bc..87e4104115 100644 --- a/rero_ils/dojson/utils.py +++ b/rero_ils/dojson/utils.py @@ -19,7 +19,6 @@ import contextlib -import os import re import sys import traceback @@ -30,6 +29,7 @@ import requests import xmltodict from dojson import Overdo, utils +from flask import current_app from pkg_resources import resource_string _UNIMARC_LANGUAGES_SCRIPTS = { @@ -419,11 +419,12 @@ def remove_special_characters(value, chars=['\u0098', '\u009C']): return value -def get_contribution_link(bibid, reroid, ids, key): +def get_mef_link(bibid, reroid, entity_type, ids, key): """Get MEF contribution link. :params bibid: Bib id from the record. :params reroid: RERO id from the record. + :params entity_type: Entity type. :params id: $0 from the marc field. :params key: Tag from the marc field. :returns: MEF url. @@ -435,9 +436,13 @@ def get_contribution_link(bibid, reroid, ids, key): # https://mef.test.rero.ch/api/agents/mef/?q=rero.rero_pid:A012327677 if not ids: return - mef_url = os.environ.get( - 'RERO_ILS_MEF_AGENTS_URL', - 'https://mef.rero.ch/api/agents') + entity_types = current_app.config.get('RERO_ILS_ENTITY_TYPES', {}) + entity_type = entity_types.get(entity_type) + mef_config = current_app.config.get('RERO_ILS_MEF_CONFIG') + mef_url = mef_config.get(entity_type, {}).get('base_url') + if not mef_url: + return + sources = mef_config.get(entity_type, {}).get('sources') has_no_de_101 = True for id_ in ids: # see if we have a $0 with (DE-101) @@ -460,7 +465,7 @@ def get_contribution_link(bibid, reroid, ids, key): elif match_type == 'de-588' and has_no_de_101: match_type = 'gnd' match_value = get_gnd_de_101(match_value) - if match_type in ['idref', 'gnd']: + if match_type and match_type in sources: url = f'{mef_url}/mef/latest/{match_type}:{match_value}' response = requests_retry_session().get(url) status_code = response.status_code @@ -468,7 +473,7 @@ def get_contribution_link(bibid, reroid, ids, key): if status_code == requests.codes.ok: if value := response.json().get(match_type, {}).get('pid'): if match_value != value: - error_print('INFO GET MEF CONTRIBUTION:', + error_print(f'INFO GET MEF {entity_type}:', bibid, reroid, key, id_, 'NEW', f'({match_type.upper()}){value}') return f'{mef_url}/{match_type}/{value}' @@ -727,10 +732,9 @@ def get_fields(self, tag=None): fields = [] items = get_field_items(self._blob_record) for blob_key, blob_value in items: - field_data = {} - tag_value = blob_key[0:3] + tag_value = blob_key[:3] if (tag_value == tag) or not tag: - field_data['tag'] = tag_value + field_data = {'tag': tag_value} if len(blob_key) == 3: # if control field field_data['data'] = blob_value.rstrip() else: @@ -753,9 +757,11 @@ def get_subfields(self, field, code=None): """Get all subfields having the given subfield code value.""" if int(field['tag']) < 10: raise ValueError('data field expected (tag >= 01x)') - items = get_field_items(field['subfields']) - return [subfield_data for subfield_code, subfield_data in items - if (subfield_code == code) or not code] + items = get_field_items(field.get('subfields', {})) + return [ + subfield_data for subfield_code, subfield_data in items + if (subfield_code == code) or not code + ] def build_value_with_alternate_graphic( self, tag, code, label, index, link, @@ -800,7 +806,7 @@ def clean_punctuation(value, punct, spaced_punct): else: error_print('WARNING NO VALUE:', self.bib_id, self.rero_id, tag, code, label) - try: + with contextlib.suppress(Exception): alt_gr = self.alternate_graphic[tag][link] subfield = self.get_subfields(alt_gr['field'])[index] value = clean_punctuation(subfield, punct, spaced_punct) @@ -809,8 +815,6 @@ def clean_punctuation(value, punct, spaced_punct): 'value': value, 'language': self.get_language_script(alt_gr['script']) }) - except Exception as err: - pass return data or None def extract_description_from_marc_field(self, key, value, data): @@ -1256,13 +1260,11 @@ def init_country(self): """Initialization country (008 and 044).""" self.country = None self.cantons = [] - fields_044 = self.get_fields(tag='044') - if fields_044: + if fields_044 := self.get_fields(tag='044'): field_044 = fields_044[0] for cantons_code in self.get_subfields(field_044, 'c'): try: - canton = cantons_code.split('-')[1].strip() - if canton: + if canton := cantons_code.split('-')[1].strip(): if canton in _CANTON: self.cantons.append(canton) else: @@ -1275,10 +1277,8 @@ def init_country(self): self.country = 'sz' # We did not find a country in 044 trying 008. if not self.country: - try: + with contextlib.suppress(Exception): self.country = self.field_008_data[15:18].rstrip() - except Exception as err: - pass # Use equivalent if country code is obsolete if self.country in _OBSOLETE_COUNTRIES_MAPPING: self.country = _OBSOLETE_COUNTRIES_MAPPING[self.country] @@ -1338,7 +1338,7 @@ def init_date(self): 3. get dates from 773 $g 4. set start_date to 2050 """ - if (self.date_type_from_008 == 'q' or self.date_type_from_008 == 'n'): + if self.date_type_from_008 in ['q', 'n']: self.date['note'] = 'Date(s) uncertain or unknown' start_date = make_year(self.date1_from_008) if not (start_date and start_date >= -9999 and start_date <= 2050): @@ -1348,8 +1348,7 @@ def init_date(self): for ind2 in ['1', '0', '2', '4', '3']: for field_264 in fields_264: if ind2 == field_264['ind2']: - subfields_c = self.get_subfields(field_264, 'c') - if subfields_c: + if subfields_c := self.get_subfields(field_264, 'c'): year = re.search(r"(-?\d{1,4})", subfields_c[0]) if year: year = int(year.group(0)) @@ -1364,8 +1363,7 @@ def init_date(self): if not start_date: fields_773 = self.get_fields('773') for field_773 in fields_773: - subfields_g = self.get_subfields(field_773, 'g') - if subfields_g: + if subfields_g := self.get_subfields(field_773, 'g'): year = re.search(r"(-?\d{4})", subfields_g[0]) if year: year = int(year.group(0)) @@ -1399,7 +1397,7 @@ def get_script_from_lang(asian=False): if asian: default_script = 'hani' script_per_lang = _SCRIPT_PER_LANG_ASIA - script = script_per_lang.get(self.lang_from_008, None) + script = script_per_lang.get(self.lang_from_008) if not script: for lang in self.langs_from_041_a: if lang in script_per_lang: @@ -1476,8 +1474,7 @@ def build_variant_title_data(self, string_set): for field_246 in fields_246: variant_data = {} subfield_246_a = '' - subfields_246_a = self.get_subfields(field_246, 'a') - if subfields_246_a: + if subfields_246_a := self.get_subfields(field_246, 'a'): subfield_246_a = subfields_246_a[0] subfield_246_a_cleaned = remove_trailing_punctuation( subfield_246_a, ',.', ':;/-=') @@ -1498,37 +1495,44 @@ def build_variant_title_data(self, string_set): subfield_a_parts = blob_value.split(':') part_index = 0 for subfield_a_part in subfield_a_parts: - value_data = self. \ - build_value_with_alternate_graphic( - '246', blob_key, subfield_a_part, - index, link, ',.', ':;/-=') + value_data = \ + self.build_value_with_alternate_graphic( + '246', + blob_key, + subfield_a_part, + index, + link, + ',.', + ':;/-=', + ) if value_data: if part_index == 0: variant_data['type'] = \ - 'bf:VariantTitle' + 'bf:VariantTitle' variant_data['mainTitle'] = value_data else: variant_data['subtitle'] = value_data part_index += 1 elif blob_key in ['n', 'p']: - value_data = self. \ - build_value_with_alternate_graphic( - '246', blob_key, blob_value, - index, link, ',.', ':;/-=') + value_data = \ + self.build_value_with_alternate_graphic( + '246', + blob_key, + blob_value, + index, + link, + ',.', + ':;/-=', + ) if value_data: part_list.update_part( value_data, blob_key, blob_value) if blob_key != '__order__': index += 1 - the_part_list = part_list.get_part_list() - if the_part_list: + if the_part_list := part_list.get_part_list(): variant_data['part'] = the_part_list if variant_data: variant_list.append(variant_data) - else: - pass - # for showing the variant title skipped for debugging purpose - # print('variant skipped', subfield_246_a_cleaned) return variant_list def init_content_media_carrier_type(self): @@ -1550,16 +1554,14 @@ def init_content_media_carrier_type(self): type_key = content_media_carrier_type_per_tag[tag] fields = self.get_fields(tag=tag) for field in fields: - subfields_8 = self.get_subfields(field, '8') - if not subfields_8: - subfields_8 = ['0'] + subfields_8 = self.get_subfields(field, '8') or ['0'] for subfield_b in self.get_subfields(field, 'b'): type_found = False for link in subfields_8: linked_data = content_media_carrier_type.get(link, {}) if tag == '336': linked_data_type_value = \ - linked_data.get(type_key, []) + linked_data.get(type_key, []) type_value = \ content_media_carrier_map_per_tag[tag].get( subfield_b, None) @@ -1575,21 +1577,18 @@ def init_content_media_carrier_type(self): subfield_b, None) linked_data_type_value = \ linked_data.get(type_key, '') - type_value = \ - content_media_carrier_map_per_tag[tag].get( - subfield_b, None) - if type_value: + if type_value := content_media_carrier_map_per_tag[ + tag + ].get(subfield_b, None): linked_data_type_value = type_value linked_data[type_key] = linked_data_type_value type_found = True if tag == '338': - # extract mediaType for the fist char of $b media_type_from_338 = \ - _MEDIA_TYPE_MAPPING.get( - subfield_b[0], None) + _MEDIA_TYPE_MAPPING.get(subfield_b[0]) if media_type_from_338: linked_data['mediaTypeFrom338'] = \ - media_type_from_338 + media_type_from_338 if type_found: content_media_carrier_type[link] = linked_data break # subfield $b in not repetitive @@ -1655,9 +1654,7 @@ def do(self, blob, ignore_missing=True, exception_handlers=None): except Exception as err: self.bib_id = '???' - # get the language code - fields_101 = self.get_fields(tag='101') - if fields_101: + if fields_101 := self.get_fields(tag='101'): field_101_a = self.get_subfields(fields_101[0], 'a') field_101_g = self.get_subfields(fields_101[0], 'g') if field_101_a: @@ -1665,23 +1662,18 @@ def do(self, blob, ignore_missing=True, exception_handlers=None): if field_101_g: self.lang_from_101 = field_101_g[0] - # get the type of continuing ressource - fields_110 = self.get_fields(tag='110') - if fields_110: + if fields_110 := self.get_fields(tag='110'): field_110_a = self.get_subfields(fields_110[0], 'a') if field_110_a and len(field_110_a[0]) > 0: self.serial_type = field_110_a[0][0] - self.admin_meta_data = {} - enc_level = '' - if self.leader: - enc_level = self.leader[17] # LDR 17 - if enc_level in _ENCODING_LEVEL_MAPPING: - encoding_level = _ENCODING_LEVEL_MAPPING[enc_level] - else: - encoding_level = _ENCODING_LEVEL_MAPPING['u'] - self.admin_meta_data['encodingLevel'] = encoding_level - + enc_level = self.leader[17] if self.leader else '' + encoding_level = ( + _ENCODING_LEVEL_MAPPING[enc_level] + if enc_level in _ENCODING_LEVEL_MAPPING + else _ENCODING_LEVEL_MAPPING['u'] + ) + self.admin_meta_data = {'encodingLevel': encoding_level} result = super().do( blob, ignore_missing=ignore_missing, @@ -1710,8 +1702,8 @@ def get_language_script(self, unimarc_script_code): """ if unimarc_script_code in _UNIMARC_LANGUAGES_SCRIPTS: script_code = _UNIMARC_LANGUAGES_SCRIPTS[unimarc_script_code] - lang = self.lang_from_101 if script_code in _LANGUAGES_SCRIPTS: + lang = self.lang_from_101 if lang in _LANGUAGES_SCRIPTS[script_code]: return '-'.join([self.lang_from_101, script_code]) error_print('WARNING LANGUAGE SCRIPTS:', self.bib_id, @@ -1732,7 +1724,7 @@ def get_alt_graphic_fields(self, tag=None): items = get_field_items(self._blob_record) for blob_key, blob_value in items: field_data = {} - tag_value = blob_key[0:3] + tag_value = blob_key[:3] if (tag_value == tag) or not tag: field_data['tag'] = tag_value if len(blob_key) == 3: # if control field @@ -1908,12 +1900,15 @@ def remove_leading_article(string, max_article_len=4): if index == 0 and not field_245_a_end_with_equal: if data_std.rstrip(): main_subtitle.append({'value': data_std.rstrip()}) - if lang and index < len(data_lang_items): - if data_lang_items[index].rstrip(): - main_subtitle.append({ - 'value': data_lang_items[index].rstrip(), - 'language': lang - }) + if ( + lang + and index < len(data_lang_items) + and data_lang_items[index].rstrip() + ): + main_subtitle.append({ + 'value': data_lang_items[index].rstrip(), + 'language': lang + }) else: main_title = [] subtitle = [] diff --git a/rero_ils/modules/documents/dojson/contrib/marc21tojson/loc/model.py b/rero_ils/modules/documents/dojson/contrib/marc21tojson/loc/model.py index 1ba3d70ec2..364fb031d8 100644 --- a/rero_ils/modules/documents/dojson/contrib/marc21tojson/loc/model.py +++ b/rero_ils/modules/documents/dojson/contrib/marc21tojson/loc/model.py @@ -26,8 +26,8 @@ from flask import current_app from rero_ils.dojson.utils import ReroIlsMarc21Overdo, TitlePartList, \ - build_identifier, build_string_from_subfields, get_contribution_link, \ - get_field_items, remove_trailing_punctuation + build_identifier, build_string_from_subfields, get_field_items, \ + get_mef_link, remove_trailing_punctuation from rero_ils.modules.entities.models import EntityType from ..utils import do_abbreviated_title, \ @@ -603,18 +603,17 @@ def marc21_to_subjects_6XX(self, key, value): value, subfield_code_per_tag[creator_tag_key]), '.', '.') field_key = 'genreForm' if tag_key == '655' else config_field_key - if data_type in [EntityType.PERSON, - EntityType.ORGANISATION]: - if ref := get_contribution_link( - bibid=marc21.bib_id, - reroid=marc21.bib_id, - ids=utils.force_list(value.get('0')), - key=key - ): - subject = { - '$ref': ref - } - if not subject.get('$ref'): + if field_key != 'subjects_imported' and (ref := get_mef_link( + bibid=marc21.bib_id, + reroid=marc21.bib_id, + entity_type=data_type, + ids=utils.force_list(value.get('0')), + key=key + )): + subject = { + '$ref': ref + } + else: identifier = build_identifier(value) if identifier: subject['identifiedBy'] = identifier diff --git a/rero_ils/modules/documents/dojson/contrib/marc21tojson/rero/model.py b/rero_ils/modules/documents/dojson/contrib/marc21tojson/rero/model.py index f289b2e2e9..51e1ddd066 100644 --- a/rero_ils/modules/documents/dojson/contrib/marc21tojson/rero/model.py +++ b/rero_ils/modules/documents/dojson/contrib/marc21tojson/rero/model.py @@ -26,9 +26,8 @@ from dojson.utils import GroupableOrderedDict from rero_ils.dojson.utils import ReroIlsMarc21Overdo, build_identifier, \ - build_string_from_subfields, error_print, get_contribution_link, \ - get_field_items, not_repetitive, re_identified, \ - remove_trailing_punctuation + build_string_from_subfields, error_print, get_field_items, get_mef_link, \ + not_repetitive, re_identified, remove_trailing_punctuation from rero_ils.modules.documents.utils import create_authorized_access_point from rero_ils.modules.entities.models import EntityType @@ -123,9 +122,10 @@ def marc21_to_contribution(self, key, value): self['work_access_point'].append(work_access_point) return None agent = {} - if ref := get_contribution_link( + if ref := get_mef_link( bibid=marc21.bib_id, reroid=marc21.rero_id, + entity_type=EntityType.PERSON, ids=utils.force_list(value.get('0')), key=key ): @@ -573,18 +573,17 @@ def marc21_to_subjects(self, key, value): ) + '. ' + subject['authorized_access_point'] field_key = 'genreForm' if tag_key == '655' else 'subjects' subfields_0 = utils.force_list(value.get('0')) - if (data_type in [EntityType.PERSON, EntityType.ORGANISATION] - and subfields_0): - if ref := get_contribution_link( - bibid=marc21.bib_id, - reroid=marc21.rero_id, - ids=subfields_0, - key=key - ): - subject = { - '$ref': ref, - } - if not subject.get('$ref'): + if field_key != 'subjects_imported' and (ref := get_mef_link( + bibid=marc21.bib_id, + reroid=marc21.rero_id, + entity_type=data_type, + ids=utils.force_list(subfields_0), + key=key + )): + subject = { + '$ref': ref, + } + else: if identifier := build_identifier(value): subject['identifiedBy'] = identifier if field_key != 'genreForm': diff --git a/rero_ils/modules/documents/dojson/contrib/marc21tojson/slsp/model.py b/rero_ils/modules/documents/dojson/contrib/marc21tojson/slsp/model.py index 95ee613c70..dc4b5e7601 100644 --- a/rero_ils/modules/documents/dojson/contrib/marc21tojson/slsp/model.py +++ b/rero_ils/modules/documents/dojson/contrib/marc21tojson/slsp/model.py @@ -23,8 +23,7 @@ from flask import current_app from rero_ils.dojson.utils import ReroIlsMarc21Overdo, build_identifier, \ - build_string_from_subfields, get_contribution_link, \ - remove_trailing_punctuation + build_string_from_subfields, get_mef_link, remove_trailing_punctuation from rero_ils.modules.entities.models import EntityType from ..utils import do_abbreviated_title, \ @@ -394,21 +393,24 @@ def marc21_to_subjects_6XX(self, key, value): subject['conference'] = conference_per_tag[tag_key] elif tag_key in ['600t', '610t', '611t']: creator_tag_key = tag_key[:3] # to keep only tag: 600, 610, 611 - subject['creator'] = remove_trailing_punctuation( + creator = remove_trailing_punctuation( build_string_from_subfields( value, subfield_code_per_tag[creator_tag_key]), '.', '.') + if creator: + subject['authorized_access_point'] = \ + f'{creator}. {subject["authorized_access_point"]}' field_key = 'genreForm' if tag_key == '655' else config_field_key - if data_type in [EntityType.PERSON, EntityType.ORGANISATION]: - if ref := get_contribution_link( - bibid=marc21.bib_id, - reroid=marc21.rero_id, - ids=utils.force_list(value.get('0')), - key=key - ): - subject = { - '$ref': ref - } - if not subject.get('$ref'): + if field_key != 'subjects_imported' and (ref := get_mef_link( + bibid=marc21.bib_id, + reroid=marc21.rero_id, + entity_type=data_type, + ids=utils.force_list(value.get('0')), + key=key + )): + subject = { + '$ref': ref + } + else: if identifier := build_identifier(value): sub_2 = next(iter(utils.force_list(value.get('2') or [])), '') if data_type == EntityType.TOPIC and sub_2.lower() == 'rero': diff --git a/rero_ils/modules/documents/dojson/contrib/marc21tojson/utils.py b/rero_ils/modules/documents/dojson/contrib/marc21tojson/utils.py index 0b6a831c2d..20df327500 100644 --- a/rero_ils/modules/documents/dojson/contrib/marc21tojson/utils.py +++ b/rero_ils/modules/documents/dojson/contrib/marc21tojson/utils.py @@ -30,8 +30,8 @@ from rero_ils.dojson.utils import _LANGUAGES, TitlePartList, add_note, \ build_identifier, build_responsibility_data, build_string_from_subfields, \ error_print, extract_subtitle_and_parallel_titles_from_field_245_b, \ - get_contribution_link, get_field_items, get_field_link_data, \ - not_repetitive, re_identified, remove_trailing_punctuation + get_field_items, get_field_link_data, get_mef_link, not_repetitive, \ + re_identified, remove_trailing_punctuation from rero_ils.modules.documents.utils import create_authorized_access_point from rero_ils.modules.entities.models import EntityType @@ -600,9 +600,10 @@ def do_contribution(data, marc21, key, value): return None agent = {} - if ref := get_contribution_link( + if ref := get_mef_link( bibid=marc21.bib_id, reroid=marc21.rero_id, + entity_type=EntityType.PERSON, ids=utils.force_list(value.get('0')), key=key ): diff --git a/rero_ils/modules/documents/dojson/contrib/unimarctojson/model.py b/rero_ils/modules/documents/dojson/contrib/unimarctojson/model.py index 5428ffd26a..e4e2c0f1bf 100644 --- a/rero_ils/modules/documents/dojson/contrib/unimarctojson/model.py +++ b/rero_ils/modules/documents/dojson/contrib/unimarctojson/model.py @@ -32,7 +32,7 @@ remove_trailing_punctuation from rero_ils.modules.documents.api import Document from rero_ils.modules.documents.dojson.contrib.marc21tojson.utils import \ - get_contribution_link + get_mef_link from rero_ils.modules.documents.utils import create_authorized_access_point from rero_ils.modules.entities.models import EntityType @@ -655,9 +655,10 @@ def unimarc_to_contribution(self, key, value): ids = utils.force_list(value.get('3')) or [] ids = [f'(idref){id_}' for id_ in ids] - if ids and (ref := get_contribution_link( + if ids and (ref := get_mef_link( bibid=unimarc.bib_id, reroid=unimarc.rero_id, + entity_type=EntityType.PERSON, ids=ids, key=key )): diff --git a/rero_ils/modules/imports/serializers/serializers.py b/rero_ils/modules/imports/serializers/serializers.py index 621d15102b..c875214284 100644 --- a/rero_ils/modules/imports/serializers/serializers.py +++ b/rero_ils/modules/imports/serializers/serializers.py @@ -122,23 +122,25 @@ def post_process(self, metadata): titles, responsibility, with_subtitle=False) if text_title: metadata['ui_title_text_responsibility'] = text_title - contributions = metadata.get('contribution', []) - new_contributions = [] - for contribution in contributions: - agent = contribution['entity'] - # convert a MEF link into a local entity - if agent_data := JsonRef.replace_refs(agent, loader=None).get( - 'metadata' - ): - agent = { - local_value: agent_data[local_key] - for local_key, local_value in self.entity_mapping.items() - if agent_data.get(local_key) - } - new_contributions.append({'entity': agent}) - if new_contributions: - metadata['contribution'] = \ - process_i18n_literal_fields(new_contributions) + for entity_type in ['contribution', 'subjects', 'genreForm']: + entities = metadata.get(entity_type, []) + new_entities = [] + for entity in entities: + ent = entity['entity'] + # convert a MEF link into a local entity + if entity_data := JsonRef.replace_refs(ent, loader=None).get( + 'metadata' + ): + ent = { + local_value: entity_data[local_key] + for local_key, local_value + in self.entity_mapping.items() + if entity_data.get(local_key) + } + new_entities.append({'entity': ent}) + if new_entities: + metadata[entity_type] = \ + process_i18n_literal_fields(new_entities) return metadata diff --git a/tests/unit/documents/test_documents_dojson.py b/tests/unit/documents/test_documents_dojson.py index 09737e467c..0ec5d82d4a 100644 --- a/tests/unit/documents/test_documents_dojson.py +++ b/tests/unit/documents/test_documents_dojson.py @@ -19,8 +19,6 @@ from __future__ import absolute_import, print_function -import os - import mock from dojson.contrib.marc21.utils import create_record from utils import mock_response @@ -28,9 +26,10 @@ from rero_ils.dojson.utils import not_repetitive from rero_ils.modules.documents.dojson.contrib.marc21tojson.rero import marc21 from rero_ils.modules.documents.dojson.contrib.marc21tojson.rero.model import \ - get_contribution_link + get_mef_link from rero_ils.modules.documents.views import create_publication_statement, \ get_cover_art, get_other_accesses +from rero_ils.modules.entities.models import EntityType def test_not_repetetive(capsys): @@ -5598,28 +5597,27 @@ def test_marc21_to_identified_by_from_930(): @mock.patch('requests.Session.get') -def test_get_contribution_link(mock_get, capsys): +def test_get_mef_link(mock_get, capsys): """Test get mef contribution link""" - os.environ[ - 'RERO_ILS_MEF_AGENTS_URL'] = 'https://mef.xxx.rero.ch/api/agents' - mock_get.return_value = mock_response(json_data={ 'pid': 'test', 'idref': {'pid': '003945843'} }) - mef_url = get_contribution_link( + mef_url = get_mef_link( bibid='1', reroid='1', + entity_type=EntityType.PERSON, ids=['(IdRef)003945843'], key='100..' ) - assert mef_url == 'https://mef.xxx.rero.ch/api/agents/idref/003945843' + assert mef_url == 'https://mef.rero.ch/api/agents/idref/003945843' mock_get.return_value = mock_response(status=404) - mef_url = get_contribution_link( + mef_url = get_mef_link( bibid='1', reroid='1', + entity_type=EntityType.PERSON, ids=['(IdRef)123456789'], key='100..' ) @@ -5627,14 +5625,15 @@ def test_get_contribution_link(mock_get, capsys): out, err = capsys.readouterr() assert out == ( 'WARNING GET MEF CONTRIBUTION:\t1\t1\t100..\t(IdRef)123456789\t' - 'https://mef.xxx.rero.ch/api/agents/mef/latest/' + 'https://mef.rero.ch/api/agents/mef/latest/' 'idref:123456789\t404\t0\t\n' ) mock_get.return_value = mock_response(status=400) - mef_url = get_contribution_link( + mef_url = get_mef_link( bibid='1', reroid='1', + entity_type=EntityType.PERSON, ids=['X123456789'], key='100..' )