Beispiel #1
0
def get_internal_location_by_legacy_recid(legacy_recid):
    """Search for internal location by legacy id."""
    search = InternalLocationSearch().query(
        "bool", filter=[Q("term", legacy_ids=legacy_recid)]
    )
    result = search.execute()
    hits_total = result.hits.total.value
    if not result.hits or hits_total < 1:
        click.secho(
            "no internal location found with legacy id {}".format(
                legacy_recid
            ),
            fg="red",
        )
        raise ItemMigrationError(
            "no internal location found with legacy id {}".format(legacy_recid)
        )
    elif hits_total > 1:
        raise ItemMigrationError(
            "found more than one internal location with legacy id {}".format(
                legacy_recid
            )
        )
    else:
        return InternalLocation.get_record_by_pid(result.hits[0].pid)
Beispiel #2
0
    def get_internal_location(internal_location_pid):
        """Return the InternalLocation record."""
        internal_location = InternalLocation.get_record_by_pid(
            internal_location_pid)
        del internal_location["$schema"]

        return internal_location
def test_internal_locations_validation(db, testdata):
    """Test validation when updating an Internal Location."""
    intloc_pid = testdata["internal_locations"][0]["pid"]
    intloc = InternalLocation.get_record_by_pid(intloc_pid)

    intloc["location_pid"] = "not_found_pid"
    with pytest.raises(LocationNotFoundError):
        intloc.commit()
    def test_on_internal_location_update():
        """Test internal location resolvers."""
        indexer = _get_mock()

        pid = "ilocid-2"
        intloc = InternalLocation.get_record_by_pid(pid)
        InternalLocationIndexer().index(intloc)

        referenced = _assert_origin(indexer, INTERNAL_LOCATION_PID_TYPE, pid)

        # should re-index items
        n_items = 4  # from test data
        _assert_contains(referenced, ITEM_PID_TYPE)

        assert len(referenced) == n_items
Beispiel #5
0
def get_internal_location_by_legacy_recid(legacy_recid):
    """Search for internal location by legacy id."""
    search = InternalLocationSearch().query('bool',
                                            filter=[
                                                Q('term',
                                                  legacy_id=legacy_recid),
                                            ])
    result = search.execute()
    hits_total = result.hits.total if lt_es7 else result.hits.total.value
    if not result.hits or hits_total < 1:
        click.secho('no internal location found with legacy id {}'.format(
            legacy_recid),
                    fg='red')
        raise ItemMigrationError(
            'no internal location found with legacy id {}'.format(
                legacy_recid))
    elif hits_total > 1:
        raise MultipartMigrationError(
            'found more than one internal location with legacy id {}'.format(
                legacy_recid))
    else:
        return InternalLocation.get_record_by_pid(result.hits[0].pid)
Beispiel #6
0
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,
    }