def test_sru_documents(client, document_ref, contribution_person_data): """Test sru documents rest api.""" api_url = url_for('api_sru.documents', version='1.1', operation='searchRetrieve', query='al-Wajīz') res = client.get(api_url) assert res.status_code == 200 xml_dict = get_xml_dict(res) assert 'searchRetrieveResponse' in xml_dict search_rr = xml_dict['searchRetrieveResponse'] assert search_rr.get('echoedSearchRetrieveRequest') == { 'maximumRecords': '100', 'query': 'al-Wajīz', 'query_es': 'al-Wajīz', 'recordPacking': 'XML', 'recordSchema': 'info:sru/schema/1/marcxml-v1.1-light', 'resultSetTTL': '0', 'startRecord': '1' } assert search_rr.get('numberOfRecords') == str(Document.count())
def test_publish_harvested_records(app, ebooks_1_xml, ebooks_2_xml, org_martigny, loc_online_martigny, item_type_online_martigny, org_sion, loc_online_sion, item_type_online_sion, capsys): """Test publish harvested records.""" Identifier = namedtuple('Identifier', 'identifier') Record = namedtuple('Record', 'xml deleted header') records = [] records.append( Record(xml=ebooks_1_xml, deleted=False, header=Identifier(identifier='record1'))) records.append( Record(xml=ebooks_2_xml, deleted=False, header=Identifier(identifier='record2'))) records.append( Record(xml=ebooks_2_xml, deleted=True, header=Identifier(identifier='record3'))) kwargs = {'max': 100} publish_harvested_records(sender=None, records=records, kwargs=kwargs) flush_index(DocumentsSearch.Meta.index) flush_index(HoldingsSearch.Meta.index) assert Document.count() == 2 doc1 = Document.get_record_by_pid('1') assert doc1.get('$schema') is not None assert doc1.get('identifiedBy') == [{ 'type': 'bf:Isbn', 'value': '9782075118842' }, { 'type': 'bf:Local', 'value': 'cantook-EDEN502344' }, { 'type': 'bf:Local', 'source': 'cantook', 'value': 'record1' }] assert len(list(Holding.get_holdings_pid_by_document_pid(doc1.pid))) == 1 doc2 = Document.get_record_by_pid('2') assert doc2.get('$schema') is not None assert doc2.get('identifiedBy') == [{ 'type': 'bf:Isbn', 'value': '9782811234157' }, { 'type': 'bf:Local', 'value': 'cantook-immateriel.frO1006810' }, { 'type': 'bf:Local', 'source': 'cantook', 'value': 'record2' }] assert len(list(Holding.get_holdings_pid_by_document_pid(doc2.pid))) == 1 # test update publish_harvested_records(sender=None, records=records) flush_index(DocumentsSearch.Meta.index) flush_index(HoldingsSearch.Meta.index) assert len(list(Holding.get_holdings_pid_by_document_pid(doc1.pid))) == 1 assert len(list(Holding.get_holdings_pid_by_document_pid(doc2.pid))) == 1 # test delete records = [] del doc1['electronicLocator'] records.append(doc1) doc2['electronicLocator'] = [{ "content": "coverImage", "type": "relatedResource", "url": "http://images.immateriel.fr/covers/DEQ2C5A.png" }] records.append(doc2) create_records(records=records) flush_index(DocumentsSearch.Meta.index) flush_index(HoldingsSearch.Meta.index) assert len(list(Holding.get_holdings_pid_by_document_pid(doc1.pid))) == 0 assert len(list(Holding.get_holdings_pid_by_document_pid(doc2.pid))) == 0 assert 2 == delete_records(records=records)