Example #1
0
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,
            ))
Example #2
0
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
Example #3
0
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_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