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

tests: add record fixtures #100

Merged
merged 1 commit into from
Aug 24, 2022
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
tests: add record fixtures
* Fixes alembic scripts.
* Creates records fixtures for agents and concepts.
* Adds a new create record test utils function.

Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
jma and rerowep committed Aug 23, 2022
commit d8a71e031db54559a9b7f8522eec638cca06b69b
10 changes: 5 additions & 5 deletions rero_mef/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
4 changes: 2 additions & 2 deletions rero_mef/alembic/c658fa8e9fa5_inital_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions rero_mef/concepts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/api/test_monitoring_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
178 changes: 7 additions & 171 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Loading