From 58e2d783a00194a21a1a32d89106e73edb8a0077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Marie=CC=81thoz?= Date: Tue, 23 Aug 2022 11:40:16 +0200 Subject: [PATCH] tests: add record fixtures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes alembic scripts. * Creates records fixtures for agents and concepts. * Adds a new create record test utils function. Co-Authored-by: Johnny Mariéthoz Co-Authored-by: Peter Weber --- rero_mef/agents/__init__.py | 10 +- .../alembic/c658fa8e9fa5_inital_branch.py | 4 +- rero_mef/concepts/__init__.py | 4 +- tests/api/test_monitoring_rest.py | 6 +- tests/api/test_view_agents_gnd.py | 10 - tests/api/test_view_agents_idref.py | 10 - tests/api/test_view_agents_mef.py | 9 - tests/api/test_view_agents_rero.py | 9 - tests/api/test_view_agents_viaf.py | 9 - tests/conftest.py | 178 +----------------- tests/fixtures/agents_data.py | 140 ++++++++++++++ tests/fixtures/agents_records.py | 57 ++++++ tests/fixtures/concepts_data.py | 64 +++++++ tests/fixtures/concepts_records.py | 29 +++ tests/unit/agents/test_agents_api.py | 32 ++-- tests/unit/agents/test_agents_api_no_viaf.py | 8 +- tests/unit/agents/test_agents_api_updates.py | 11 +- tests/unit/agents/test_agents_mef_api.py | 15 +- tests/unit/agents/test_signals.py | 6 +- tests/unit/test_api.py | 10 +- tests/unit/test_concepts_task.py | 16 +- tests/unit/test_monitoring.py | 5 +- tests/utils.py | 12 ++ 23 files changed, 366 insertions(+), 288 deletions(-) create mode 100644 tests/fixtures/agents_data.py create mode 100644 tests/fixtures/agents_records.py create mode 100644 tests/fixtures/concepts_data.py create mode 100644 tests/fixtures/concepts_records.py diff --git a/rero_mef/agents/__init__.py b/rero_mef/agents/__init__.py index d00b961e..c17bd6cd 100644 --- a/rero_mef/agents/__init__.py +++ b/rero_mef/agents/__init__.py @@ -23,8 +23,8 @@ from .rero.api import AgentReroIndexer, AgentReroRecord, AgentReroSearch from .viaf.api import AgentViafIndexer, AgentViafRecord, AgentViafSearch -__all__ = (AgentGndIndexer, AgentGndRecord, AgentGndSearch, - AgentIdrefIndexer, AgentIdrefRecord, AgentIdrefSearch, - AgentMefIndexer, AgentMefRecord, AgentMefSearch, - AgentReroIndexer, AgentReroRecord, AgentReroSearch, - AgentViafIndexer, AgentViafRecord, AgentViafSearch) +__all__ = ('AgentGndIndexer', 'AgentGndRecord', 'AgentGndSearch', + 'AgentIdrefIndexer', 'AgentIdrefRecord', 'AgentIdrefSearch', + 'AgentMefIndexer', 'AgentMefRecord', 'AgentMefSearch', + 'AgentReroIndexer', 'AgentReroRecord', 'AgentReroSearch', + 'AgentViafIndexer', 'AgentViafRecord', 'AgentViafSearch') diff --git a/rero_mef/alembic/c658fa8e9fa5_inital_branch.py b/rero_mef/alembic/c658fa8e9fa5_inital_branch.py index af6d4967..2e2663c2 100644 --- a/rero_mef/alembic/c658fa8e9fa5_inital_branch.py +++ b/rero_mef/alembic/c658fa8e9fa5_inital_branch.py @@ -20,8 +20,8 @@ # revision identifiers, used by Alembic. revision = 'c658fa8e9fa5' -down_revision = '0bea81e3b83e' -branch_labels = () +down_revision = None +branch_labels = ('rero_mef',) depends_on = None diff --git a/rero_mef/concepts/__init__.py b/rero_mef/concepts/__init__.py index a50ddfc5..c70f2a0c 100644 --- a/rero_mef/concepts/__init__.py +++ b/rero_mef/concepts/__init__.py @@ -20,5 +20,5 @@ from .mef.api import ConceptMefIndexer, ConceptMefRecord, ConceptMefSearch from .rero.api import ConceptReroIndexer, ConceptReroRecord, ConceptReroSearch -__all__ = (ConceptMefIndexer, ConceptMefRecord, ConceptMefSearch, - ConceptReroIndexer, ConceptReroRecord, ConceptReroSearch) +__all__ = ('ConceptMefIndexer', 'ConceptMefRecord', 'ConceptMefSearch', + 'ConceptReroIndexer', 'ConceptReroRecord', 'ConceptReroSearch') diff --git a/tests/api/test_monitoring_rest.py b/tests/api/test_monitoring_rest.py index a3246ad6..9e5cde9c 100644 --- a/tests/api/test_monitoring_rest.py +++ b/tests/api/test_monitoring_rest.py @@ -44,15 +44,15 @@ def test_monitoring_es_db_counts(client): } -def test_monitoring_check_es_db_counts(app, client, agent_idref_record): +def test_monitoring_check_es_db_counts(app, client, agent_idref_data): """Test monitoring check_es_db_counts.""" res = client.get(url_for('api_monitoring.check_es_db_counts')) assert res.status_code == 200 assert json.loads(res.get_data(as_text=True)) == { 'data': {'status': 'green'}} - pers = AgentIdrefRecord.create( - data=agent_idref_record, + AgentIdrefRecord.create( + data=agent_idref_data, delete_pid=False, dbcommit=True, reindex=False) diff --git a/tests/api/test_view_agents_gnd.py b/tests/api/test_view_agents_gnd.py index da6112eb..2901133d 100644 --- a/tests/api/test_view_agents_gnd.py +++ b/tests/api/test_view_agents_gnd.py @@ -21,19 +21,9 @@ from flask import url_for -from rero_mef.agents.gnd.api import AgentGndRecord - def test_view_agents_gnd(client, agent_gnd_record): """Test redirect GND.""" - - AgentGndRecord.create( - data=agent_gnd_record, - delete_pid=False, - dbcommit=True, - reindex=True, - ) - AgentGndRecord.flush_indexes() pid = agent_gnd_record.get('pid') url = url_for('api_agents_gnd.redirect_list') res = client.get(url) diff --git a/tests/api/test_view_agents_idref.py b/tests/api/test_view_agents_idref.py index 5ecea898..ce80ff85 100644 --- a/tests/api/test_view_agents_idref.py +++ b/tests/api/test_view_agents_idref.py @@ -21,19 +21,9 @@ from flask import url_for -from rero_mef.agents.idref.api import AgentIdrefRecord - def test_view_agents_idref(client, agent_idref_record): """Test redirect IDREF.""" - - AgentIdrefRecord.create( - data=agent_idref_record, - delete_pid=False, - dbcommit=True, - reindex=True, - ) - AgentIdrefRecord.flush_indexes() pid = agent_idref_record.get('pid') url = url_for('api_agents_idref.redirect_list') res = client.get(url) diff --git a/tests/api/test_view_agents_mef.py b/tests/api/test_view_agents_mef.py index caf8a9b1..50371d0e 100644 --- a/tests/api/test_view_agents_mef.py +++ b/tests/api/test_view_agents_mef.py @@ -21,18 +21,9 @@ from flask import url_for -from rero_mef.agents.mef.api import AgentMefRecord - def test_view_agents_mef(client, agent_mef_record): """Test redirect MEF.""" - AgentMefRecord.create( - data=agent_mef_record, - delete_pid=False, - dbcommit=True, - reindex=True, - ) - AgentMefRecord.flush_indexes() pid = agent_mef_record.get('pid') url = url_for('api_agents_mef.redirect_list') res = client.get(url) diff --git a/tests/api/test_view_agents_rero.py b/tests/api/test_view_agents_rero.py index 40e0c2e3..2a94085f 100644 --- a/tests/api/test_view_agents_rero.py +++ b/tests/api/test_view_agents_rero.py @@ -21,19 +21,10 @@ from flask import url_for -from rero_mef.agents.rero.api import AgentReroRecord - def test_view_agents_rero(client, agent_rero_record): """Test redirect RERO.""" - AgentReroRecord.create( - data=agent_rero_record, - delete_pid=False, - dbcommit=True, - reindex=True, - ) - AgentReroRecord.flush_indexes() pid = agent_rero_record.get('pid') url = url_for('api_agents_rero.redirect_list') res = client.get(url) diff --git a/tests/api/test_view_agents_viaf.py b/tests/api/test_view_agents_viaf.py index d6919300..873e90bd 100644 --- a/tests/api/test_view_agents_viaf.py +++ b/tests/api/test_view_agents_viaf.py @@ -21,19 +21,10 @@ from flask import url_for -from rero_mef.agents.viaf.api import AgentViafRecord - def test_view_agents_viaf(client, agent_viaf_record): """Test redirect VIAF.""" - AgentViafRecord.create( - data=agent_viaf_record, - delete_pid=False, - dbcommit=True, - reindex=True, - ) - AgentViafRecord.flush_indexes() pid = agent_viaf_record.get('pid') url = url_for('api_agents_viaf.redirect_list') res = client.get(url) diff --git a/tests/conftest.py b/tests/conftest.py index a7ffa41b..037bf107 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,7 +19,13 @@ import pytest -pytest_plugins = ("celery.contrib.pytest", ) +pytest_plugins = ( + 'celery.contrib.pytest', + 'fixtures.agents_data', + 'fixtures.agents_records', + 'fixtures.concepts_data', + 'fixtures.concepts_records', +) @pytest.fixture(scope='module') @@ -61,173 +67,3 @@ def app_config(app_config): app_config['CELERY_TASK_ALWAYS_EAGER'] = True app_config['CELERY_TASK_EAGER_PROPAGATES'] = True return app_config - - -@pytest.fixture(scope='session') -def agent_mef_record(): - """Agent MEF record.""" - record = { - "$schema": "https://mef.rero.ch/schemas/mef/mef-v0.0.1.json", - "gnd": {"$ref": "https://mef.rero.ch/api/gnd/12391664X"}, - "rero": {"$ref": "https://mef.rero.ch/api/rero/A023655346"}, - "idref": {"$ref": "https://mef.rero.ch/api/idref/069774331"}, - "viaf_pid": "66739143" - } - return record - - -@pytest.fixture(scope='session') -def agent_viaf_record(): - """Agent VIAF record.""" - record = { - "$schema": "https://mef.rero.ch/schemas/viaf/viaf-v0.0.1.json", - "pid": "66739143", - "gnd_pid": "12391664X", - "rero_pid": "A023655346", - "idref_pid": "069774331" - } - return record - - -@pytest.fixture(scope='session') -def agent_gnd_record(): - """Agent GND record.""" - record = { - "$schema": - "https://mef.rero.ch/schemas/agents_gnd/gnd-agent-v0.0.1.json", - "identifier": "http://d-nb.info/gnd/12391664X", - "pid": "12391664X", - "bf:Agent": "bf:Person", - "variant_name": [ - "Cavaleriis, Joannes Baptista \u0098de\u009c", - "Cavalleris, Joannes Baptista \u0098de\u009c", - "Cavaleriis, Joanes Baptista \u0098de\u009c", - "Cavalleriis, Johannes Baptista \u0098de\u009c", - "Cavalerius, Johannes Battista \u0098de\u009c", - "Cavallerys, Johannes Baptista \u0098de\u009c", - "Cavaleriis, Johannes Baptista \u0098de\u009c", - "Cavalieri, Giovanni Battista \u0098de\u009c", - "Cavallieri, Giovan Battista \u0098de\u009c", - "Cavalleriis, Johannes Battista", - "Cavallerius, Johannes Baptista", - "Cavallerius, Joannes Baptista", - "Cavalleriis, Johannes Baptista", - "Cavallieri, Giovanni Battista", - "Cavaleriis, Giovanni Battista", - "Cavalleriis, Io. Baptista \u0098de\u009c", - "Cavallieri, Giovanni Battista \u0098de\u009c", - "Cavalerijs, Io. Baptista \u0098de\u009c", - "Cavallieri, Giovanni B.", - "Cavaleriis, Joannes B. \u0098de\u009c", - "Cavallerius, Jo. B. \u0098de\u009c", - "Cavalleriis, Joannes Baptista \u0098de\u009c", - "Cavallerijs, Baptista \u0098de\u009c", - "Cavalleriis, Giovanni Battista \u0098de\u009c", - "Cavallieri, Giovanbattista \u0098de\u009c", - "Cavallerius, Io. Bap.ta", - "Cavalierii, Johannes Baptista \u0098de\u009c" - ], - "authorized_access_point": "Cavalieri, Giovanni Battista, 1525-1601", - "biographical_information": [ - "LoC-NA", - "LCAuth" - ], - "preferred_name": "Cavalieri, Giovanni Battista", - "date_of_birth": "ca. 1525", - "date_of_death": "1601" - } - return record - - -@pytest.fixture(scope='session') -def agent_rero_record(): - """Agent RERO record.""" - record = { - "$schema": - "https://mef.rero.ch/schemas/agents_rero/rero-agent-v0.0.1.json", - "bf:Agent": "bf:Person", - "authorized_access_point": - "Cavalieri, Giovanni Battista,, ca.1525-1601", - "date_of_birth": "ca.1525-1601", - "biographical_information": [ - "Graveur, dessinateur et \u00e9diteur" - ], - "variant_name": [ - "De Cavalieri, Giovanni Battista,", - "Cavalleriis, Baptista de,", - "Cavalleriis, Giovanni Battista de,", - "Cavalieri, Gianbattista," - ], - "identifier": "http://data.rero.ch/02-A023655346", - "pid": "A023655346", - "preferred_name": "Cavalieri, Giovanni Battista," - } - return record - - -@pytest.fixture(scope='session') -def agent_idref_record(): - """Agent IDREF record.""" - record = { - "pid": "069774331", - "bf:Agent": "bf:Person", - "date_of_birth": "....", - "date_of_death": "1540", - "language": ["fre"], - "identifier": "http://www.idref.fr/069774331", - "biographical_information": [ - "Grammairien" - ], - "preferred_name": "Briss\u00e9, Nicolas, grammairien", - "authorized_access_point": - "Briss\u00e9, Nicolas, ....-1540, grammairien", - "gender": "male", - "$schema": - "https://mef.rero.ch/schemas/agents_idref/idref-agent-v0.0.1.json" - } - return record - - -@pytest.fixture(scope='session') -def concept_rero_record(): - """Concept RERO record.""" - record = { - "$schema": - "https://mef.rero.ch/schemas/" - "concepts_rero/rero-concept-v0.0.1.json", - "authorized_access_point": "Activités d'éveil", - "broader": [{ - "authorized_access_point": "Enseignement primaire" - }], - "identifiedBy": [{ - "source": "RERO", - "type": "bf:Local", - "value": "A021001006" - }, { - "source": "BNF", - "type": "bf:Local", - "value": "FRBNF11930822X" - }, { - "type": "uri", - "value": "http://catalogue.bnf.fr/ark:/12148/cb119308220" - }], - "note": [{ - "label": [ - "Vocabulaire de l'éducation / G. Mialaret, 1979" - ], - "noteType": "dataSource" - }, { - "label": ["LCSH, 1995-03"], - "noteType": "dataNotFound" - }], - "pid": "A021001006", - "related": [{ - "authorized_access_point": "Leçons de choses" - }], - "variant_access_point": [ - "Activités d'éveil (enseignement primaire)", - "Disciplines d'éveil", - "Éveil, Activités d'" - ] - } - return record diff --git a/tests/fixtures/agents_data.py b/tests/fixtures/agents_data.py new file mode 100644 index 00000000..dd218445 --- /dev/null +++ b/tests/fixtures/agents_data.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +# +# RERO MEF +# Copyright (C) 2022 RERO +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""Agents data.""" + +import pytest + + +@pytest.fixture(scope='module') +def agent_gnd_data(): + """Agent GND record.""" + return { + "$schema": + "https://mef.rero.ch/schemas/agents_gnd/gnd-agent-v0.0.1.json", + "identifier": "http://d-nb.info/gnd/12391664X", + "pid": "12391664X", + "bf:Agent": "bf:Person", + "variant_name": [ + "Cavaleriis, Joannes Baptista \u0098de\u009c", + "Cavalleris, Joannes Baptista \u0098de\u009c", + "Cavaleriis, Joanes Baptista \u0098de\u009c", + "Cavalleriis, Johannes Baptista \u0098de\u009c", + "Cavalerius, Johannes Battista \u0098de\u009c", + "Cavallerys, Johannes Baptista \u0098de\u009c", + "Cavaleriis, Johannes Baptista \u0098de\u009c", + "Cavalieri, Giovanni Battista \u0098de\u009c", + "Cavallieri, Giovan Battista \u0098de\u009c", + "Cavalleriis, Johannes Battista", + "Cavallerius, Johannes Baptista", + "Cavallerius, Joannes Baptista", + "Cavalleriis, Johannes Baptista", + "Cavallieri, Giovanni Battista", + "Cavaleriis, Giovanni Battista", + "Cavalleriis, Io. Baptista \u0098de\u009c", + "Cavallieri, Giovanni Battista \u0098de\u009c", + "Cavalerijs, Io. Baptista \u0098de\u009c", + "Cavallieri, Giovanni B.", + "Cavaleriis, Joannes B. \u0098de\u009c", + "Cavallerius, Jo. B. \u0098de\u009c", + "Cavalleriis, Joannes Baptista \u0098de\u009c", + "Cavallerijs, Baptista \u0098de\u009c", + "Cavalleriis, Giovanni Battista \u0098de\u009c", + "Cavallieri, Giovanbattista \u0098de\u009c", + "Cavallerius, Io. Bap.ta", + "Cavalierii, Johannes Baptista \u0098de\u009c" + ], + "authorized_access_point": "Cavalieri, Giovanni Battista, 1525-1601", + "biographical_information": [ + "LoC-NA", + "LCAuth" + ], + "preferred_name": "Cavalieri, Giovanni Battista", + "date_of_birth": "ca. 1525", + "date_of_death": "1601" + } + + +@pytest.fixture(scope='module') +def agent_rero_data(): + """Agent RERO record.""" + return { + "$schema": + "https://mef.rero.ch/schemas/agents_rero/rero-agent-v0.0.1.json", + "bf:Agent": "bf:Person", + "authorized_access_point": + "Cavalieri, Giovanni Battista,, ca.1525-1601", + "date_of_birth": "ca.1525-1601", + "biographical_information": [ + "Graveur, dessinateur et \u00e9diteur" + ], + "variant_name": [ + "De Cavalieri, Giovanni Battista,", + "Cavalleriis, Baptista de,", + "Cavalleriis, Giovanni Battista de,", + "Cavalieri, Gianbattista," + ], + "identifier": "http://data.rero.ch/02-A023655346", + "pid": "A023655346", + "preferred_name": "Cavalieri, Giovanni Battista," + } + + +@pytest.fixture(scope='module') +def agent_idref_data(): + """Agent IDREF record.""" + return { + "pid": "069774331", + "bf:Agent": "bf:Person", + "date_of_birth": "....", + "date_of_death": "1540", + "language": ["fre"], + "identifier": "http://www.idref.fr/069774331", + "biographical_information": [ + "Grammairien" + ], + "preferred_name": "Briss\u00e9, Nicolas, grammairien", + "authorized_access_point": + "Briss\u00e9, Nicolas, ....-1540, grammairien", + "gender": "male", + "$schema": + "https://mef.rero.ch/schemas/agents_idref/idref-agent-v0.0.1.json" + } + + +@pytest.fixture(scope='module') +def agent_mef_data(): + """Agent MEF record.""" + return { + "$schema": "https://mef.rero.ch/schemas/mef/mef-v0.0.1.json", + "gnd": {"$ref": "https://mef.rero.ch/api/gnd/12391664X"}, + "rero": {"$ref": "https://mef.rero.ch/api/rero/A023655346"}, + "idref": {"$ref": "https://mef.rero.ch/api/idref/069774331"}, + "viaf_pid": "66739143" + } + + +@pytest.fixture(scope='module') +def agent_viaf_data(): + """Agent VIAF record.""" + return { + "$schema": "https://mef.rero.ch/schemas/viaf/viaf-v0.0.1.json", + "pid": "66739143", + "gnd_pid": "12391664X", + "rero_pid": "A023655346", + "idref_pid": "069774331" + } diff --git a/tests/fixtures/agents_records.py b/tests/fixtures/agents_records.py new file mode 100644 index 00000000..6e0a8245 --- /dev/null +++ b/tests/fixtures/agents_records.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# +# RERO MEF +# Copyright (C) 2022 RERO +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""Agents records.""" + +import pytest +from utils import create_record + +from rero_mef.agents import AgentGndRecord, AgentIdrefRecord, AgentMefRecord, \ + AgentReroRecord, AgentViafRecord + + +@pytest.fixture(scope='module') +def agent_idref_record(app, agent_idref_data): + """Create a IdRef record.""" + return create_record(AgentIdrefRecord, agent_idref_data) + + +@pytest.fixture(scope='module') +def agent_gnd_record(app, agent_gnd_data): + """Create a GND record.""" + return create_record(AgentGndRecord, agent_gnd_data) + + +@pytest.fixture(scope='module') +def agent_rero_record(app, agent_rero_data): + """Create a RERO record.""" + return create_record(AgentReroRecord, agent_rero_data) + + +@pytest.fixture(scope='module') +def agent_viaf_record( + app, agent_viaf_data, agent_idref_record, agent_rero_record, + agent_gnd_record +): + """Create a VIAF record.""" + return create_record(AgentViafRecord, agent_viaf_data) + + +@pytest.fixture(scope='module') +def agent_mef_record(app, agent_mef_data, agent_viaf_record): + """Create a IdRef record.""" + return create_record(AgentMefRecord, agent_mef_data) diff --git a/tests/fixtures/concepts_data.py b/tests/fixtures/concepts_data.py new file mode 100644 index 00000000..91dacec7 --- /dev/null +++ b/tests/fixtures/concepts_data.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# +# RERO MEF +# Copyright (C) 2022 RERO +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""Concepts data.""" + +import pytest + + +@pytest.fixture(scope='module') +def concept_rero_data(): + """Concept RERO record.""" + return { + "$schema": + "https://mef.rero.ch/schemas/" + "concepts_rero/rero-concept-v0.0.1.json", + "authorized_access_point": "Activités d'éveil", + "broader": [{ + "authorized_access_point": "Enseignement primaire" + }], + "identifiedBy": [{ + "source": "RERO", + "type": "bf:Local", + "value": "A021001006" + }, { + "source": "BNF", + "type": "bf:Local", + "value": "FRBNF11930822X" + }, { + "type": "uri", + "value": "http://catalogue.bnf.fr/ark:/12148/cb119308220" + }], + "note": [{ + "label": [ + "Vocabulaire de l'éducation / G. Mialaret, 1979" + ], + "noteType": "dataSource" + }, { + "label": ["LCSH, 1995-03"], + "noteType": "dataNotFound" + }], + "pid": "A021001006", + "related": [{ + "authorized_access_point": "Leçons de choses" + }], + "variant_access_point": [ + "Activités d'éveil (enseignement primaire)", + "Disciplines d'éveil", + "Éveil, Activités d'" + ] + } diff --git a/tests/fixtures/concepts_records.py b/tests/fixtures/concepts_records.py new file mode 100644 index 00000000..2774f089 --- /dev/null +++ b/tests/fixtures/concepts_records.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# +# RERO MEF +# Copyright (C) 2022 RERO +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""Concepts records.""" + +import pytest +from utils import create_record + +from rero_mef.concepts import ConceptReroRecord + + +@pytest.fixture(scope='module') +def concept_rero_record(app, concept_rero_data): + """Create a IdRef record.""" + return create_record(ConceptReroRecord, concept_rero_data) diff --git a/tests/unit/agents/test_agents_api.py b/tests/unit/agents/test_agents_api.py index b13b0f48..aad38733 100644 --- a/tests/unit/agents/test_agents_api.py +++ b/tests/unit/agents/test_agents_api.py @@ -25,11 +25,11 @@ def test_create_agent_record_with_viaf_links( - app, agent_viaf_record, agent_gnd_record, agent_rero_record, - agent_idref_record): + app, agent_viaf_data, agent_gnd_data, agent_rero_data, + agent_idref_data): """Test create agent record with VIAF links.""" viaf_record, action = AgentViafRecord.create_or_update( - agent_viaf_record, dbcommit=True, reindex=True + agent_viaf_data, dbcommit=True, reindex=True ) AgentViafRecord.flush_indexes() assert action.name == 'CREATE' @@ -40,7 +40,7 @@ def test_create_agent_record_with_viaf_links( record, action, m_record, m_action, v_record, online = \ AgentGndRecord.create_or_update_agent_mef_viaf( - data=agent_gnd_record, + data=agent_gnd_data, dbcommit=True, reindex=True, online=False @@ -59,7 +59,7 @@ def test_create_agent_record_with_viaf_links( record, action, m_record, m_action, v_record, online = \ AgentReroRecord.create_or_update_agent_mef_viaf( - data=agent_rero_record, + data=agent_rero_data, dbcommit=True, reindex=True, online=False @@ -78,7 +78,7 @@ def test_create_agent_record_with_viaf_links( record, action, m_record, m_action, v_record, online = \ AgentIdrefRecord.create_or_update_agent_mef_viaf( - data=agent_idref_record, + data=agent_idref_data, dbcommit=True, reindex=True, online=False @@ -104,46 +104,46 @@ def test_create_agent_record_with_viaf_links( def test_update_agent_record_with_viaf_links( - app, agent_viaf_record, agent_gnd_record, agent_rero_record, - agent_idref_record): + app, agent_gnd_data, agent_rero_data, + agent_idref_data): """Test create agent record with VIAF links.""" returned_record, action = AgentGndRecord.create_or_update( - agent_gnd_record, dbcommit=True, reindex=True + agent_gnd_data, dbcommit=True, reindex=True ) assert action.name == 'UPDATE' assert returned_record['pid'] == '12391664X' returned_record, action = AgentReroRecord.create_or_update( - agent_rero_record, dbcommit=True, reindex=True + agent_rero_data, dbcommit=True, reindex=True ) assert action.name == 'UPDATE' assert returned_record['pid'] == 'A023655346' returned_record, action = AgentIdrefRecord.create_or_update( - agent_idref_record, dbcommit=True, reindex=True + agent_idref_data, dbcommit=True, reindex=True ) assert action.name == 'UPDATE' assert returned_record['pid'] == '069774331' def test_uptodate_agent_record_with_viaf_links_md5( - app, agent_viaf_record, agent_gnd_record, agent_rero_record, - agent_idref_record): + app, agent_gnd_data, agent_rero_data, + agent_idref_data): """Test create agent record with VIAF links.""" returned_record, action = AgentGndRecord.create_or_update( - agent_gnd_record, dbcommit=True, reindex=True, test_md5=True + agent_gnd_data, dbcommit=True, reindex=True, test_md5=True ) assert action.name == 'UPTODATE' assert returned_record['pid'] == '12391664X' returned_record, action = AgentReroRecord.create_or_update( - agent_rero_record, dbcommit=True, reindex=True, test_md5=True + agent_rero_data, dbcommit=True, reindex=True, test_md5=True ) assert action.name == 'UPTODATE' assert returned_record['pid'] == 'A023655346' returned_record, action = AgentIdrefRecord.create_or_update( - agent_idref_record, dbcommit=True, reindex=True, + agent_idref_data, dbcommit=True, reindex=True, test_md5=True ) assert action.name == 'UPTODATE' diff --git a/tests/unit/agents/test_agents_api_no_viaf.py b/tests/unit/agents/test_agents_api_no_viaf.py index bc7cfd31..29c2a47d 100644 --- a/tests/unit/agents/test_agents_api_no_viaf.py +++ b/tests/unit/agents/test_agents_api_no_viaf.py @@ -23,11 +23,11 @@ def test_create_agent_record_no_viaf_links( - app, agent_gnd_record, agent_rero_record, agent_idref_record): + app, agent_gnd_data, agent_rero_data, agent_idref_data): """Test create agent record without VIAF links.""" record, action, m_record, m_action, v_record, online = \ AgentGndRecord.create_or_update_agent_mef_viaf( - data=agent_gnd_record, + data=agent_gnd_data, dbcommit=True, reindex=True, online=False @@ -44,7 +44,7 @@ def test_create_agent_record_no_viaf_links( record, action, m_record, m_action, v_record, online = \ AgentReroRecord.create_or_update_agent_mef_viaf( - data=agent_rero_record, + data=agent_rero_data, dbcommit=True, reindex=True, online=False @@ -61,7 +61,7 @@ def test_create_agent_record_no_viaf_links( record, action, m_record, m_action, v_record, online = \ AgentIdrefRecord.create_or_update_agent_mef_viaf( - data=agent_idref_record, + data=agent_idref_data, dbcommit=True, reindex=True, online=False diff --git a/tests/unit/agents/test_agents_api_updates.py b/tests/unit/agents/test_agents_api_updates.py index 34b2e820..a019fb13 100644 --- a/tests/unit/agents/test_agents_api_updates.py +++ b/tests/unit/agents/test_agents_api_updates.py @@ -28,8 +28,9 @@ @mock.patch( 'rero_mef.agents.viaf.api.AgentViafRecord.get_online_viaf_record') -def test_create_agent_updates(mock_get, app, agent_gnd_record, - agent_rero_record, agent_idref_record): +def test_create_agent_updates( + mock_get, app, agent_idref_data, agent_gnd_data, + agent_rero_data): """Test create agent record with VIAF links.""" # we have to mock the access to viaf mock_get.return_value = { @@ -42,7 +43,7 @@ def test_create_agent_updates(mock_get, app, agent_gnd_record, assert AgentViafRecord.count() == 0 record, action, m_record, m_action, v_record, online = \ AgentIdrefRecord.create_or_update_agent_mef_viaf( - data=agent_idref_record, + data=agent_idref_data, dbcommit=True, reindex=True, online=True @@ -74,7 +75,7 @@ def test_create_agent_updates(mock_get, app, agent_gnd_record, # create second record record, action, m_record, m_action, v_record, online = \ AgentGndRecord.create_or_update_agent_mef_viaf( - data=agent_gnd_record, + data=agent_gnd_data, dbcommit=True, reindex=True, online=True @@ -91,7 +92,7 @@ def test_create_agent_updates(mock_get, app, agent_gnd_record, record, action, m_record, m_action, v_record, online = \ AgentReroRecord.create_or_update_agent_mef_viaf( - data=agent_rero_record, + data=agent_rero_data, dbcommit=True, reindex=True, online=True diff --git a/tests/unit/agents/test_agents_mef_api.py b/tests/unit/agents/test_agents_mef_api.py index 44ad4daf..aadebd72 100644 --- a/tests/unit/agents/test_agents_mef_api.py +++ b/tests/unit/agents/test_agents_mef_api.py @@ -17,6 +17,8 @@ """Test agents MEF api.""" +from utils import create_record + from rero_mef.agents.mef.api import AgentMefRecord @@ -25,20 +27,15 @@ def test_get_all_pids_without_agents_and_viaf(app): record = { "$schema": "https://mef.rero.ch/schemas/mef/mef-v0.0.1.json" } - m_record = AgentMefRecord.create( - data=record, dbcommit=True, reindex=True) - AgentMefRecord.flush_indexes() + m_record = create_record(AgentMefRecord, record) assert list(AgentMefRecord.get_all_pids_without_agents_and_viaf()) == \ [m_record.pid] -def test_get_pids_with_multiple_mef(app, agent_mef_record): +def test_get_pids_with_multiple_mef(app, agent_mef_data): """Test get pids with multiple MEF.""" - m_record_1 = AgentMefRecord.create( - data=agent_mef_record, delete_pid=True, dbcommit=True, reindex=True) - m_record_2 = AgentMefRecord.create( - data=agent_mef_record, delete_pid=True, dbcommit=True, reindex=True) - AgentMefRecord.flush_indexes() + m_record_1 = create_record(AgentMefRecord, agent_mef_data, delete_pid=True) + m_record_2 = create_record(AgentMefRecord, agent_mef_data, delete_pid=True) pids, multiple_pids, missing_pids = AgentMefRecord \ .get_pids_with_multiple_mef(record_types=['aidref', 'aggnd', 'agrero']) assert pids == {'aggnd': {}, 'agrero': {}, 'aidref': {}} diff --git a/tests/unit/agents/test_signals.py b/tests/unit/agents/test_signals.py index e5a7f530..d8d133c3 100644 --- a/tests/unit/agents/test_signals.py +++ b/tests/unit/agents/test_signals.py @@ -22,10 +22,10 @@ from rero_mef.agents.viaf.api import AgentViafRecord -def test_create_mef_with_viaf_links(app, agent_viaf_record, agent_gnd_record): +def test_create_mef_with_viaf_links(app, agent_viaf_data, agent_gnd_data): """Test create MEF record from agent with VIAF links.""" v_record, action = AgentViafRecord.create_or_update( - agent_viaf_record, dbcommit=True, reindex=True + agent_viaf_data, dbcommit=True, reindex=True ) assert action.name == 'CREATE' assert v_record['pid'] == '66739143' @@ -35,7 +35,7 @@ def test_create_mef_with_viaf_links(app, agent_viaf_record, agent_gnd_record): record, action, m_record, m_action, v_record, online = \ AgentGndRecord.create_or_update_agent_mef_viaf( - data=agent_gnd_record, + data=agent_gnd_data, dbcommit=True, reindex=True, online=False diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py index c867a6df..82970b6e 100644 --- a/tests/unit/test_api.py +++ b/tests/unit/test_api.py @@ -27,15 +27,7 @@ def test_reromefrecord_api(app, agent_idref_record): """Test ReroMefRecord api.""" - - idref = AgentIdrefRecord.create( - data=agent_idref_record, - delete_pid=False, - dbcommit=True, - reindex=True, - ) - AgentIdrefRecord.flush_indexes() - + idref = agent_idref_record assert AgentIdrefRecord.count() == 1 assert AgentIdrefRecord.index_all() == 1 diff --git a/tests/unit/test_concepts_task.py b/tests/unit/test_concepts_task.py index 7f77f1bf..51cd7838 100644 --- a/tests/unit/test_concepts_task.py +++ b/tests/unit/test_concepts_task.py @@ -17,23 +17,19 @@ """Test api.""" +from utils import create_record + from rero_mef.concepts.mef.api import ConceptMefRecord from rero_mef.concepts.rero.api import ConceptReroRecord from rero_mef.concepts.tasks import task_create_mef_for_concept -def test_task_create_mef_for_concept(app, concept_rero_record): +def test_task_create_mef_for_concept(app, concept_rero_data): """Test ReroMefRecord api.""" - rero = ConceptReroRecord.create( - data=concept_rero_record, - delete_pid=False, - dbcommit=True, - reindex=True - ) - ConceptReroRecord.flush_indexes() + record = create_record(ConceptReroRecord, concept_rero_data) assert task_create_mef_for_concept('XXXX', 'corero') == \ 'Not found concept corero:XXXX' - assert task_create_mef_for_concept(rero.pid, 'corero') == \ + assert task_create_mef_for_concept(record.pid, 'corero') == \ 'Create MEF from corero pid: A021001006 | mef: 1 create' mef = ConceptMefRecord.get_record_by_pid('1') assert mef == { @@ -41,5 +37,5 @@ def test_task_create_mef_for_concept(app, concept_rero_record): 'https://mef.rero.ch/schemas/concepts_mef/mef-concept-v0.0.1.json', 'pid': '1', 'rero': { - '$ref': f'https://mef.rero.ch/api/concepts/rero/{rero.pid}'} + '$ref': f'https://mef.rero.ch/api/concepts/rero/{record.pid}'} } diff --git a/tests/unit/test_monitoring.py b/tests/unit/test_monitoring.py index f1d11ec3..14bf7926 100644 --- a/tests/unit/test_monitoring.py +++ b/tests/unit/test_monitoring.py @@ -23,7 +23,7 @@ from rero_mef.monitoring import Monitoring, es_db_counts_cli, es_db_missing_cli -def test_monitoring(app, agent_idref_record, script_info): +def test_monitoring(app, agent_idref_data, script_info): """Test monitoring.""" cli_output = [ @@ -40,8 +40,9 @@ def test_monitoring(app, agent_idref_record, script_info): mon = Monitoring() assert mon.get_es_count('xxx') == 'No >>xxx<< in ES' assert mon.get_db_count('xxx') == 'No >>xxx<< in DB' + idref = AgentIdrefRecord.create( - data=agent_idref_record, + data=agent_idref_data, delete_pid=False, dbcommit=True, reindex=False diff --git a/tests/utils.py b/tests/utils.py index 5fd50cc8..e57cc1c3 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -20,6 +20,18 @@ from invenio_accounts.testutils import login_user_via_session +def create_record(cls, data, delete_pid=False): + """Create a record in DB and index it.""" + record = cls.create( + data=data, + delete_pid=delete_pid, + dbcommit=True, + reindex=True + ) + cls.flush_indexes() + return record + + def create_and_login_monitoring_user(app, client): """Creates and logins a monitoring user.""" datastore = app.extensions['invenio-accounts'].datastore