def test_delete_member(reindex, db, minimal_member_record, minimal_location_record): """Test Member delete.""" memb = MemberWithLocations.create(minimal_member_record) location1 = Location.create(minimal_location_record) memb.add_location(location1) pid1 = PersistentIdentifier.get_by_object('loc', 'rec', location1.id) location2 = Location.create(minimal_location_record) memb.add_location(location2) pid2 = PersistentIdentifier.get_by_object('loc', 'rec', location2.id) location3 = Location.create(minimal_location_record) memb.add_location(location3) pid3 = PersistentIdentifier.get_by_object('loc', 'rec', location3.id) memb.dbcommit() assert MembersLocationsMetadata.query.count() == 3 assert RecordMetadata.query.count() == 4 assert pid1.is_registered() assert pid2.is_registered() assert pid3.is_registered() memb.delete(force=True) assert MembersLocationsMetadata.query.count() == 0 assert RecordMetadata.query.count() == 0 assert pid1.is_deleted() assert pid2.is_deleted() assert pid3.is_deleted()
def create_items(verbose, count, itemscount, missing, reindex): """Create circulation items.""" uids = DocumentsWithItems.get_all_ids() if count == -1: count = len(uids) click.secho('Starting generating {0} items, random {1} ...'.format( count, itemscount), fg='green') locations_pids = Location.get_all_pids() patrons_barcodes = get_patrons_barcodes() missing *= len(patrons_barcodes) members_pids = Member.get_all_pids() with click.progressbar(reversed(uids[:count]), length=count) as bar: for id in bar: document = DocumentsWithItems.get_record_by_id(id) for i in range(0, randint(1, itemscount)): missing, item = create_random_item( locations_pids=locations_pids, patrons_barcodes=patrons_barcodes, members_pids=members_pids, missing=missing, verbose=False) document.add_item(item, dbcommit=True) document.dbcommit(reindex=reindex) RecordIndexer().client.indices.flush()
def create_minimal_resources_on_loan(db, minimal_member_record, minimal_location_record, item_record_on_loan, minimal_book_record): """Simple patron record.""" member = MemberWithLocations.create(minimal_member_record, dbcommit=True) location = Location.create(minimal_location_record, dbcommit=True) member.add_location(location) doc = DocumentsWithItems.create(minimal_book_record, dbcommit=True) item = Item.create({}) item.update(item_record_on_loan, dbcommit=True) doc.add_item(item, dbcommit=True) db.session.commit() yield doc, item, member, location
def test_delete_location(reindex, db, minimal_member_record, minimal_location_record): """Test MembersLocations delete.""" memb = MemberWithLocations.create(minimal_member_record, dbcommit=True) location = Location.create(minimal_location_record, dbcommit=True) memb.add_location(location, dbcommit=True) pid = PersistentIdentifier.get_by_object('loc', 'rec', location.id) assert pid.is_registered() memb.remove_location(location) assert pid.is_deleted() assert memb.locations == [] location1 = Location.create(minimal_location_record, dbcommit=True) memb.add_location(location1, dbcommit=True) location2 = Location.create(minimal_location_record, dbcommit=True) memb.add_location(location2, dbcommit=True) location3 = Location.create(minimal_location_record, dbcommit=True) memb.add_location(location3, dbcommit=True) memb.remove_location(location2) assert len(memb.locations) == 2 assert memb.locations[0]['pid'] == '2' assert memb.locations[1]['pid'] == '4'
def test_create(db, minimal_document_record, minimal_item_record, minimal_member_record, minimal_location_record): """Test DocumentWithItems creation.""" memb = MemberWithLocations.create(minimal_member_record, dbcommit=True) loc = Location.create(minimal_location_record, dbcommit=True) memb.add_location(loc, dbcommit=True) minimal_item_record['location_pid'] = loc.pid item = Item.create(minimal_item_record, dbcommit=True) doc = DocumentsWithItems.create(minimal_document_record, dbcommit=True) assert doc.itemslist == [] doc.add_item(item, dbcommit=True) assert doc.itemslist[0] == item dump = doc.dumps() assert dump['itemslist'][0] == item.dumps()
def test_member_name(db, minimal_member_record, minimal_item_record, minimal_location_record): """Test member names.""" member = MemberWithLocations.create(minimal_member_record, dbcommit=True) assert member location = Location.create(minimal_location_record, dbcommit=True) assert location member.add_location(location, dbcommit=True) assert member.locations item = Item.create({}) item.update(minimal_item_record, dbcommit=True) assert item data = item.dumps() assert data.get('member_pid') == '1' assert data.get('member_name') == 'MV Sion' holding = data.get('_circulation').get('holdings')[1] assert holding['pickup_member_name'] == 'MV Sion'