Skip to content

Commit

Permalink
entities: save old date if deleted
Browse files Browse the repository at this point in the history
Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Aug 31, 2022
1 parent 289d9ac commit 9de7f86
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 255 deletions.
502 changes: 265 additions & 237 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions rero_mef/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# RERO MEF
# Copyright (C) 2020 RERO
# 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
Expand All @@ -17,6 +17,7 @@

"""Agents."""

from .api import Action
from .gnd.api import AgentGndIndexer, AgentGndRecord, AgentGndSearch
from .idref.api import AgentIdrefIndexer, AgentIdrefRecord, AgentIdrefSearch
from .mef.api import AgentMefIndexer, AgentMefRecord, AgentMefSearch
Expand All @@ -27,4 +28,5 @@
'AgentIdrefIndexer', 'AgentIdrefRecord', 'AgentIdrefSearch',
'AgentMefIndexer', 'AgentMefRecord', 'AgentMefSearch',
'AgentReroIndexer', 'AgentReroRecord', 'AgentReroSearch',
'AgentViafIndexer', 'AgentViafRecord', 'AgentViafSearch')
'AgentViafIndexer', 'AgentViafRecord', 'AgentViafSearch',
'Action')
10 changes: 10 additions & 0 deletions rero_mef/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ def create_or_update(cls, data, id_=None, delete_pid=True, dbcommit=False,
if agent_record := cls.get_record_by_pid(pid):
# record exist
data = add_schema(data, agent_record.provider.pid_type)
# save the records old data if the new one is empty
copy_fields = ['pid', '$schema', 'identifier', 'identifiedBy',
'authorized_access_point', 'bf:Agent',
'relation_pid', 'deleted']
original_data = {
k: v for k, v in agent_record.items() if k in copy_fields}
# dict merging, `original_data` values
# will be override by `data` values
data = {**original_data, **data}

if test_md5:
return_record, agent_action = agent_record.update_test_md5(
data=data,
Expand Down
4 changes: 3 additions & 1 deletion rero_mef/concepts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

"""Concepts."""

from .api import Action
from .mef.api import ConceptMefIndexer, ConceptMefRecord, ConceptMefSearch
from .rero.api import ConceptReroIndexer, ConceptReroRecord, ConceptReroSearch

__all__ = ('ConceptMefIndexer', 'ConceptMefRecord', 'ConceptMefSearch',
'ConceptReroIndexer', 'ConceptReroRecord', 'ConceptReroSearch')
'ConceptReroIndexer', 'ConceptReroRecord', 'ConceptReroSearch',
'Action')
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"required": [
"$schema",
"pid",
"identifiedBy"
"identifiedBy",
"authorized_access_point"
],
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -79,21 +80,21 @@
"type": "object",
"properties": {
"oneOf": [
{
"$ref": {
"type": "string",
"pattern": "^https://mef.rero.ch/api/.*/.*?$"
{
"$ref": {
"type": "string",
"pattern": "^https://mef.rero.ch/api/.*/.*?$"
}
},
{
"authorized_access_point": {
"title": "Authorized access point",
"type": "string",
"minLength": 1
}
}
},
{
"authorized_access_point": {
"title": "Authorized access point",
"type": "string",
"minLength": 1
}
}
]
}
]
}
}
},
"related": {
Expand Down
28 changes: 28 additions & 0 deletions tests/api/test_agents_gnd_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
"""Test REST API GND."""

import json
from copy import deepcopy

from flask import url_for

from rero_mef.agents import Action, AgentGndRecord


def test_view_agents_gnd(client, agent_gnd_record):
"""Test redirect GND."""
Expand Down Expand Up @@ -55,3 +58,28 @@ def test_view_agents_gnd(client, agent_gnd_record):
"status": 404,
"message": "PID does not exist."
}


def test_save_deleted_data(client, agent_gnd_record, agent_gnd_data):
"""Test save deleted data GND."""
pid = agent_gnd_record.get('pid')
assert agent_gnd_record['identifier'] == 'http://d-nb.info/gnd/12391664X'
data = deepcopy(agent_gnd_data)
data = {
'deleted': '2022-01-31T10:44:22.552001+00:00',
'pid': agent_gnd_record.pid,
'relation_pid': {
'type': 'redirect_to',
'value': '1134995709'
}
}
record, action = AgentGndRecord.create_or_update(
data=data,
delete_pid=False,
dbcommit=True,
reindex=True,
test_md5=False
)
assert action == Action.UPDATE
assert record['deleted'] == data['deleted']
assert record['relation_pid'] == data['relation_pid']

0 comments on commit 9de7f86

Please sign in to comment.