def test_preprocessor_mixin_searchhit(): """Test preprocessor mixin.""" pid = PersistentIdentifier( pid_type='doi', pid_value='10.1234/foo', status='R') data = PreprocessorMixin.preprocess_search_hit(pid, { '_source': { 'title': 'test', '_created': '2015-10-01T11:11:11.000001+00:00', '_updated': '2015-12-01T11:11:11.000001+00:00', }, '_version': 1, }) for k in keys: assert k in data assert data['metadata']['title'] == 'test' assert data['created'] == '2015-10-01T11:11:11.000001+00:00' assert data['revision'] == 1 assert '_created' not in data['metadata'] assert '_updated' not in data['metadata'] data = PreprocessorMixin.preprocess_search_hit(pid, { '_source': {'title': 'test'}, '_version': 1, }) assert data['created'] is None assert data['updated'] is None
def test_preprocessor_mixin_searchhit(): """Test preprocessor mixin.""" pid = PersistentIdentifier(pid_type='doi', pid_value='10.1234/foo', status='R') data = PreprocessorMixin.preprocess_search_hit( pid, { '_source': { 'title': 'test', '_created': '2015-10-01T11:11:11.000001+00:00', '_updated': '2015-12-01T11:11:11.000001+00:00', }, '_version': 1, }) for k in keys: assert k in data assert data['metadata']['title'] == 'test' assert data['created'] == '2015-10-01T11:11:11.000001+00:00' assert data['revision'] == 1 assert '_created' not in data['metadata'] assert '_updated' not in data['metadata'] data = PreprocessorMixin.preprocess_search_hit(pid, { '_source': { 'title': 'test' }, '_version': 1, }) assert data['created'] is None assert data['updated'] is None
def test_preprocessor_mixin_record(app, db): """Test preprocessor mixin.""" pid, record = create_record({'title': 'test', 'aref': {'$ref': '#/title'}}) record.model.created = datetime(2015, 10, 1, 11, 11, 11, 1) db.session.commit() data = PreprocessorMixin().preprocess_record(pid, record) for k in keys: assert k in data assert data['metadata']['title'] == 'test' assert data['metadata']['aref'] == {'$ref': '#/title'} assert data['created'] == '2015-10-01T11:11:11.000001+00:00' assert data['revision'] == 1 data = PreprocessorMixin(replace_refs=True).preprocess_record( pid, Record({ 'title': 'test2', 'aref': { '$ref': '#/title' } })) assert data['created'] is None assert data['updated'] is None assert data['metadata']['aref'] == 'test2'
def preprocess_search_hit(pid, record_hit, links_factory=None, **kwargs): """Prepare a record hit from Elasticsearch for serialization.""" ret = PreprocessorMixin.preprocess_search_hit( pid, record_hit, links_factory=links_factory, **kwargs) matched_acls = record_hit.get('matched_queries', []) matched_acls = [ x.replace(f'{ACL_MATCHED_QUERY}_', '') for x in matched_acls ] ret['invenio_explicit_acls'] = matched_acls return ret
def test_preprocessor_mixin_record(app): """Test preprocessor mixin.""" with db.session.begin_nested(): recuuid = uuid.uuid4() record = Record.create({ 'title': 'test', 'aref': { '$ref': '#/title' } }, id_=recuuid) record.model.created = datetime(2015, 10, 1, 11, 11, 11, 1) pid = PersistentIdentifier.create('recid', '1', object_type='rec', object_uuid=recuuid, status=PIDStatus.REGISTERED) db.session.commit() data = PreprocessorMixin().preprocess_record(pid, record) for k in keys: assert k in data assert data['metadata']['title'] == 'test' assert data['metadata']['aref'] == {'$ref': '#/title'} assert data['created'] == '2015-10-01T11:11:11.000001+00:00' assert data['revision'] == 1 data = PreprocessorMixin(replace_refs=True).preprocess_record( pid, Record({ 'title': 'test2', 'aref': { '$ref': '#/title' } })) assert data['created'] is None assert data['updated'] is None assert data['metadata']['aref'] == 'test2'
def test_preprocessor_mixin_record(app): """Test preprocessor mixin.""" with db.session.begin_nested(): recuuid = uuid.uuid4() record = Record.create({'title': 'test'}, id_=recuuid) record.model.created = datetime(2015, 10, 1, 11, 11, 11, 1) pid = PersistentIdentifier.create( 'recid', '1', object_type='rec', object_uuid=recuuid, status=PIDStatus.REGISTERED) db.session.commit() data = PreprocessorMixin.preprocess_record(pid, record) for k in keys: assert k in data assert data['metadata']['title'] == 'test' assert data['created'] == '2015-10-01T11:11:11.000001+00:00' assert data['revision'] == 1 data = PreprocessorMixin.preprocess_record(pid, Record({'title': 'test2'})) assert data['created'] is None assert data['updated'] is None