def test_item_refs(app, testdata): """Test creation of an item.""" item = Item.create( dict( pid="itemid-99", document_pid="docid-1", internal_location_pid="ilocid-4", created_by=dict(type="script", value="demo"), barcode="348048", status="CAN_CIRCULATE", circulation_restriction="NO_RESTRICTION", medium="PAPER", )) assert "$schema" in item assert "document" in item and "$ref" in item["document"] assert "internal_location" in item and "$ref" in item["internal_location"] item = Item.get_record_by_pid("itemid-1") item = item.replace_refs() assert "document" in item and item["document"]["title"] assert "internal_location" in item and item["internal_location"]["name"]
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, }