def test_document_create_records(app, org_martigny, org_sion, ebook_1_data, ebook_2_data, item_type_online_martigny, loc_online_martigny, item_type_online_sion, loc_online_sion): """Test can create harvested records.""" ebook_1_data['electronic_location'] = [{ "source": "ebibliomedia", "uri": "https://www.site1.org/ebook" }] ebook_2_data['electronic_location'] = [{ "source": "ebibliomedia", "uri": "https://www.site2.org/ebook" }] n_created, n_updated = create_records([ebook_1_data]) assert n_created == 1 assert n_updated == 0 ebook_1_data['electronic_location'] = [{ "source": "ebibliomedia", "uri": "https://www.site2.org/ebook" }, { "source": "mv-cantook", "uri": "https://www.site3.org/ebook" }] n_created, n_updated = create_records([ebook_1_data, ebook_2_data]) assert n_created == 1 assert n_updated == 1 ebook_1_data['electronic_location'] = [{ "source": "mv-cantook", "uri": "https://www.site3.org/ebook" }] n_created, n_updated = create_records([ebook_1_data, ebook_2_data]) assert n_created == 0 assert n_updated == 2
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)
def test_document_create_records(app, ebook_1_data, ebook_2_data): """Test can create harvested records.""" n_created, n_updated = create_records([ebook_1_data, ebook_2_data]) assert n_created == 2 assert n_updated == 0