def test_journal_relation_from_publication_info(app): """Test journal-document relation from publication info field.""" document_data = { "$schema": "https://127.0.0.1:5000/schemas/documents/document-v1.0.0.json", "created_by": {"type": "script", "value": "test"}, "pid": "4321", "legacy_recid": "1111", "title": "Book: A Book", "document_type": "BOOK", "authors": [{"full_name": "Author Author"}], "abstracts": [{"value": "This is an abstract"}], "language": ["it"], "publication_year": "2020", "identifiers": [{"scheme": "ISBN", "value": "0123456789"}], "cover_metadata": {"ISBN": "0123456789"}, "publication_info": [{"journal_issue": "issue"}], "_migration": { "has_journal": True, "journal_record_legacy_recids": [ { "recid": "1234", "volume": None, } ], }, } journal_data = { "$schema": "https://127.0.0.1:5000/schemas/series/series-v1.0.0.json", "pid": "serid-4", "title": "Dispersion Forces", "authors": ["Buhmann, Stefan Yoshi"], "abstract": "This is a multipart monograph", "mode_of_issuance": "SERIAL", "legacy_recid": "1234", } record_uuid = mint_record_pid( DOCUMENT_PID_TYPE, "pid", {"pid": document_data["pid"]} ) document = Document.create(document_data, record_uuid) record_uuid = mint_record_pid( SERIES_PID_TYPE, "pid", {"pid": journal_data["pid"]} ) journal = Series.create(journal_data, record_uuid) legacy_recid_minter(journal["legacy_recid"], record_uuid) db.session.commit() ri = RecordIndexer() ri.index(document) ri.index(journal) current_search.flush_and_refresh(index="*") link_documents_and_serials() document_rec = Document.get_record_by_pid(document["pid"]) assert "serial" in document_rec.relations
def testdata(app, db, es_clear, system_user): """Create, index and return test data.""" indexer = RecordIndexer() locations = load_json_from_datadir("locations.json") for location in locations: record = Location.create(location) mint_record_pid(LOCATION_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) internal_locations = load_json_from_datadir("internal_locations.json") for internal_location in internal_locations: record = InternalLocation.create(internal_location) mint_record_pid( INTERNAL_LOCATION_PID_TYPE, "pid", record ) record.commit() db.session.commit() indexer.index(record) documents = load_json_from_datadir("documents.json") for doc in documents: record = Document.create(doc) mint_record_pid(DOCUMENT_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) items = load_json_from_datadir("items.json") for item in items: record = Item.create(item) mint_record_pid(ITEM_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) loans = load_json_from_datadir("loans.json") for loan in loans: record = Loan.create(loan) mint_record_pid(CIRCULATION_LOAN_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) series = load_json_from_datadir("series.json") for serie in series: record = Series.create(serie) mint_record_pid(SERIES_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) # flush all indices after indexing, otherwise ES won't be ready for tests current_search.flush_and_refresh(index='*') return { "documents": documents, "items": items, "loans": loans, "locations": locations, "series": series, }