Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entities: add place #3456

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3037,15 +3037,20 @@ def _(x):
'base_url': os.environ.get('RERO_ILS_MEF_CONCEPTS_URL', 'https://mef.rero.ch/api/concepts'),
'sources': ['idref'],
'filters': [
{'idref.bnf_type': 'genre/forme Rameau'}
{'idref.bnf_type': 'genre/forme Rameau'}
]
}
},
'places': {
'base_url': os.environ.get('RERO_ILS_MEF_PLACES_URL', 'https://mef.rero.ch/api/places'),
'sources': ['idref']
},
}
RERO_ILS_ENTITY_TYPES = {
'bf:Person': 'agents',
'bf:Organisation': 'agents',
'bf:Topic': 'concepts',
'bf:Temporal': 'concepts'
'bf:Temporal': 'concepts',
'bf:Place': 'places'
}

# The absolute path to put the agent synchronization logs, default is the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"$ref": {
"title": "Subject",
"type": "string",
"pattern": "^(https://mef.rero.ch/api/(agents|concepts)/(gnd|idref|rero)/.*|https://bib.rero.ch/api/local_entities/.*?)$",
"pattern": "^(https://mef.rero.ch/api/(agents|concepts|places)/(gnd|idref|rero)/.*|https://bib.rero.ch/api/local_entities/.*?)$",
"widget": {
"formlyConfig": {
"type": "entityTypeahead",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"bf:Organisation",
"bf:Person",
"bf:Topic",
"bf:Temporal"
"bf:Temporal",
"bf:Place"
]
},
"viaf_pid": {
Expand Down
13 changes: 12 additions & 1 deletion rero_ils/modules/entities/remote_entities/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,18 @@ def create_proxy(category):
'concepts-genreForm': {
'class': MefConceptsGenreFormProxy,
'entities': (EntityType.TOPIC,)
}
},
'places': {
'class': MefPlacesProxy,
'entities': (EntityType.PLACE, )
},
}
# Create proxy configuration aliases
proxy_config[EntityType.PERSON] = proxy_config['person']
proxy_config[EntityType.ORGANISATION] = proxy_config['organisation']
proxy_config[EntityType.TOPIC] = proxy_config['topics']
proxy_config[EntityType.TEMPORAL] = proxy_config['temporals']
proxy_config[EntityType.PLACE] = proxy_config['places']

# Try to create the proxy, otherwise raise a ValueError
if data := proxy_config.get(category):
Expand Down Expand Up @@ -322,3 +327,9 @@ class MefConceptsGenreFormProxy(MefConceptsProxy):
"""Proxy on RERO-MEF authority system for specific `genreForm` concepts."""

mef_entrypoint = 'concepts-genreForm'


class MefPlacesProxy(MEFProxyMixin):
"""Proxy on RERO-MEF authority system when searching for `places`."""

mef_entrypoint = 'places'
18 changes: 16 additions & 2 deletions tests/api/entities/remote_entities/test_remote_entities_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_remote_entities_get(client, entity_person):
@mock.patch('requests.request')
def test_remote_search_proxy(
mock_es_concept_get, app, client,
mef_concept2_es_response, mef_agents1_es_response
mef_concept2_es_response, mef_agents1_es_response, mef_places1_es_response
):
"""Test entities search on remote servers."""
# TEST#1 :: Concepts
Expand Down Expand Up @@ -120,7 +120,21 @@ def test_remote_search_proxy(
assert identifier == response.json['hits']['hits'][0][
'metadata']['idref']['identifiedBy'][0]['value']

# TEST#3 :: Unknown MEF search type
# TEST#3 :: Places
# All result must include a `identifiedBy` object if a root
mock_es_concept_get.return_value = mock_response(
json_data=mef_places1_es_response)
response = client.get(url_for(
'api_remote_entities.remote_search_proxy',
entity_type='places',
term='Rouen'
))
authorized_access_point = mef_places1_es_response['hits']['hits'][0][
'metadata']['idref']['authorized_access_point']
assert authorized_access_point == response.json['hits']['hits'][0][
'metadata']['idref']['authorized_access_point']

# TEST#4 :: Unknown MEF search type
# Try to execute a search on a not-configured MEF category. It should be
# raised a `ValueError` caught by flask to return an HTTP 400 response
category = 'unknown_category'
Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,17 @@ def app_config(app_config):
'base_url': 'https://mef.rero.ch/api/concepts',
'sources': ['idref']
},
'concepts-rameau': {
'concepts-genreForm': {
'base_url': 'https://mef.rero.ch/api/concepts',
'sources': ['idref'],
'filters': [
{'idref.bnf_type': 'sujet Rameau'}
]
}
},
'places': {
'base_url': 'https://mef.rero.ch/api/places',
'sources': ['idref']
},
}
return app_config

Expand Down
73 changes: 73 additions & 0 deletions tests/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,69 @@
],
"type": "bf:Temporal"
},
"ent_place": {
"$schema": "https://mef.rero.ch/schemas/places_mef/mef-place-v0.0.1.json",
"idref": {
"$schema": "https://mef.rero.ch/schemas/places_idref/idref-place-v0.0.1.json",
"authorized_access_point": "Suisse",
"bnf_type": "sujet Rameau",
"broader": [
{
"authorized_access_point": "Europe centrale"
}
],
"identifiedBy": [
{
"source": "IDREF",
"type": "uri",
"value": "http://www.idref.fr/027249654"
},
{
"source": "BNF",
"type": "uri",
"value": "http://catalogue.bnf.fr/ark:/12148/cb15241146v"
},
{
"source": "BNF",
"type": "uri",
"value": "http://catalogue.bnf.fr/ark:/12148/cb11933332n"
}
],
"md5": "87df11402bcbdfd147ee23a612e5ed69",
"note": [
{
"label": [
"IFLA, Names of states, 1981. GLU, 1991",
"Laval RVM, 1997-02"
],
"noteType": "dataSource"
},
{
"label": [
"Voir aussi la subdivision Et la Suisse aux personnes et collectivit\u00e9s"
],
"noteType": "seeReference"
}
],
"pid": "027249654",
"type": "bf:Place",
"variant_access_point": [
"Conf\u00e9d\u00e9ration helv\u00e9tique",
"Confederazione svizzera",
"Helvetia",
"Helv\u00e9tie",
"Schweiz",
"Schweizerische Eidgenossenschaft",
"Svizra",
"Svizzera"
]
},
"pid": "16788252",
rerowep marked this conversation as resolved.
Show resolved Hide resolved
"sources": [
"idref"
],
"type": "bf:Place"
},
"ent_pers_all": {
"$schema": "https://bib.rero.ch/schemas/remote_entities/remote_entity-v0.0.1.json",
"type": "bf:Person",
Expand Down Expand Up @@ -2150,6 +2213,16 @@
"value": "033472890"
}
}
},
{
"entity": {
"authorized_access_point": "Suisse",
"type": "bf:Place",
"identifiedBy": {
"type": "IdRef",
"value": "027249654"
}
}
}
],
"dimensions": [
Expand Down
59 changes: 58 additions & 1 deletion tests/data/mef.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,62 @@
],
"total": 1
}
},
"es_places_1": {
"hits": {
"hits": [
{
"created": "2023-09-06T08:24:41.125695+00:00",
"id": "16684460",
"links": {
"self": "https://mef.rero.ch/api/places/mef/16684460"
},
"metadata": {
"$schema": "https://mef.rero.ch/schemas/places_mef/mef-place-v0.0.1.json",
"idref": {
"$schema": "https://mef.rero.ch/schemas/places_idref/idref-place-v0.0.1.json",
"authorized_access_point": "Rouen (Seine-Maritime) - Tour Jeanne d'Arc",
"bnf_type": "sujet Rameau",
"broader": [
{
"authorized_access_point": "Rouen(Seine-Maritime) - Ch\u00e2teau"
}
],
"identifiedBy": [
{
"source": "IDREF",
"type": "uri",
"value": "http://www.idref.fr/085544434"
}
],
"md5": "18a0a5d11d1a149449544d2f258690d5",
"note": [
{
"label": [
"Le ch\u00e2teau de Rouen et son donjon dit la Tour Jeanne d'Arc / [texte de Dominique L\u00e9ost], 2004"
],
"noteType": "dataSource"
},
{
"label": [
"Donjon constituant le dernier vestige du ch\u00e2teau construit par Philippe Auguste en 1204"
],
"noteType": "general"
}
],
"pid": "085544434",
"type": "bf:Place"
},
"pid": "16684460",
"sources": [
"idref"
],
"type": "bf:Place"
},
"updated": "2023-09-06T08:24:41.125700+00:00"
}
],
"total": 1
}
}
}
}
8 changes: 7 additions & 1 deletion tests/fixtures/mef.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,11 @@ def mef_concept2_es_response(mef_entities):

@pytest.fixture(scope="module")
def mef_agents1_es_response(mef_entities):
"""Load MEF es_concept_1 data."""
"""Load MEF es_agents_1 data."""
return deepcopy(mef_entities.get('es_agents_1'))


@pytest.fixture(scope="module")
def mef_places1_es_response(mef_entities):
"""Load MEF es_places_1 data."""
return deepcopy(mef_entities.get('es_places_1'))
6 changes: 6 additions & 0 deletions tests/fixtures/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ def entity_topic_data_temporal(data):
return deepcopy(data.get('ent_topic_temporal'))


@pytest.fixture(scope="module")
def entity_place_data(data):
"""Load mef place data."""
return deepcopy(data.get('ent_place'))


@pytest.fixture(scope="module")
def entity_person_response_data(entity_topic_data):
"""Load mef concept topic response data."""
Expand Down
11 changes: 9 additions & 2 deletions tests/ui/entities/remote_entities/test_remote_entities_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def test_remote_entity_properties(
def test_replace_identified_by(
app, entity_organisation, entity_person_rero, person2_data,
entity_person_all, entity_topic_data_2, entity_topic_data_temporal,
entity_place_data,
document, document_sion_items, export_document
):
"""Test replace identified by with $ref."""
Expand Down Expand Up @@ -419,18 +420,24 @@ def test_replace_identified_by(
side_effect=[
mock_response(json_data=entity_person_all),
mock_response(json_data=entity_topic_data_temporal),
mock_response(json_data=entity_place_data),
mock_response(json_data=person2_data),
mock_response(json_data={'rero': {
'authorized_access_point': 'Europe occidentale',
'type': 'bf:Place'
}}),
mock_response(json_data=entity_topic_data_2)
]
):
changed, not_found, rero_only = replace_identified_by.run()
assert changed == 1
assert not_found == 0
assert rero_only == 2
assert rero_only == 3
assert dict(sorted(replace_identified_by.rero_only.items())) == {
'rero:A009963344':
'bf:Person: Athenagoras (patriarche oecuménique ; 1)',
'rero:A021039750': 'bf:Topic: Bases de données déductives'
'rero:A021039750': 'bf:Topic: Bases de données déductives',
'rero:A009975209': 'bf:Place: Europe occidentale'
}


Expand Down