def create_collections(input_file, max_item=10): """Create collections.""" organisation_items = {} with open(input_file, 'r', encoding='utf-8') as request_file: collections = json.load(request_file) for collection_data in collections: organisation_pid = extracted_data_from_ref( collection_data.get('organisation').get('$ref')) if organisation_pid not in organisation_items: organisation_items[organisation_pid] =\ get_items_by_organisation_pid(organisation_pid) items = random.choices( organisation_items[organisation_pid], k=random.randint(1, max_item) ) collection_data['items'] = [] for item_pid in items: ref = get_ref_for_pid('items', item_pid) collection_data['items'].append({'$ref': ref}) request = Collection.create( collection_data, dbcommit=True, reindex=True ) click.echo('\tCollection: #{pid}'.format( pid=request.pid, ))
def test_get_items(document, item_type_standard_martigny, item_lib_martigny, item2_lib_martigny, loc_public_martigny, coll_martigny_1): """Test get items.""" result = [{ '$schema': 'https://ils.rero.ch/schemas/items/item-v0.0.1.json', 'barcode': '1234', 'call_number': '00001', 'document': { '$ref': 'https://ils.rero.ch/api/documents/doc1' }, 'holding': { '$ref': 'https://ils.rero.ch/api/holdings/1' }, 'item_type': { '$ref': 'https://ils.rero.ch/api/item_types/itty1' }, 'location': { '$ref': 'https://ils.rero.ch/api/locations/loc1' }, 'notes': [{ 'content': 'Lorem ipsum et blablabla...', 'type': 'staff_note' }], 'organisation': { '$ref': 'https://ils.rero.ch/api/organisations/org1' }, 'pid': 'item1', 'status': 'on_shelf', 'type': 'standard' }, { '$schema': 'https://ils.rero.ch/schemas/items/item-v0.0.1.json', 'barcode': '8712133', 'call_number': '001313', 'document': { '$ref': 'https://ils.rero.ch/api/documents/doc1' }, 'holding': { '$ref': 'https://ils.rero.ch/api/holdings/1' }, 'item_type': { '$ref': 'https://ils.rero.ch/api/item_types/itty1' }, 'location': { '$ref': 'https://ils.rero.ch/api/locations/loc1' }, 'organisation': { '$ref': 'https://ils.rero.ch/api/organisations/org1' }, 'pid': 'item5', 'status': 'on_shelf', 'type': 'standard' }] assert Collection.get_items(coll_martigny_1) == result
def coll_saxon_1(app, org_martigny, lib_saxon, coll_saxon_1_data, item2_lib_martigny, item_lib_martigny): """Create collection Saxon 1.""" coll = Collection.create(data=coll_saxon_1_data, delete_pid=False, dbcommit=True, reindex=True) flush_index(CollectionsSearch.Meta.index) return coll
def test_collections_es_mapping(es, db, org_martigny, coll_martigny_1_data, item_lib_martigny, item2_lib_martigny): """Test collections elasticsearch mapping.""" search = CollectionsSearch() mapping = get_mapping(search.Meta.index) assert mapping collection = Collection.create(coll_martigny_1_data, dbcommit=True, reindex=True, delete_pid=True) assert mapping == get_mapping(search.Meta.index) collection.delete(force=True, dbcommit=True, delindex=True)
def test_get_items(item_lib_martigny, item2_lib_martigny, coll_martigny_1): """Test get items for a collection""" assert Collection.get_items(coll_martigny_1) == \ [item_lib_martigny, item2_lib_martigny]
def test_start_end_date(db, coll_martigny_1_data): """Test date format.""" result = '01/09/2020 - 31/12/2020' coll = Collection.create(coll_martigny_1_data, delete_pid=True) assert _start_end_date(coll.get('start_date'), coll.get('end_date')) == result