Beispiel #1
0
def test_organisation_create(app, db, org_martigny_data, org_sion_data):
    """Test organisation creation."""
    org_martigny_data['pid'] = '1'
    org = Organisation.create(org_martigny_data, dbcommit=True, reindex=True)
    assert org == org_martigny_data
    assert org.get('pid') == '1'

    assert org.get_links_to_me() == {}
    assert org.can_delete

    org = Organisation.get_record_by_pid('1')
    assert org == org_martigny_data

    fetched_pid = fetcher(org.id, org)
    assert fetched_pid.pid_value == '1'
    assert fetched_pid.pid_type == 'org'

    org_sion_data['pid'] = '2'
    org = Organisation.create(
        org_sion_data, dbcommit=True, reindex=True)
    assert org.get('pid') == '2'

    identifier = Organisation.provider.identifier
    append_fixtures_new_identifiers(identifier, ['1', '2'])
    assert identifier.next() == identifier.max() == 3
Beispiel #2
0
def test_organisation_create(app, db, org_martigny_data):
    """Test organisation creation."""
    org = Organisation.create(org_martigny_data, delete_pid=True)
    assert org == org_martigny_data
    assert org.get('pid') == '1'

    assert org.get_links_to_me() == {}
    assert org.can_delete

    org = Organisation.get_record_by_pid('1')
    assert org == org_martigny_data

    fetched_pid = fetcher(org.id, org)
    assert fetched_pid.pid_value == '1'
    assert fetched_pid.pid_type == 'org'
Beispiel #3
0
def contribution_view_method(pid, record, template=None, **kwargs):
    """Display default view.

    Sends record_viewed signal and renders template.
    :param pid: PID object.
    """
    record_viewed.send(
        current_app._get_current_object(), pid=pid, record=record)

    # Get contribution persons documents
    search = DocumentsSearch().filter(
        'term', contribution__agent__pid=pid.pid_value
    )

    viewcode = kwargs['viewcode']
    if (viewcode != current_app.config.get(
        'RERO_ILS_SEARCH_GLOBAL_VIEW_CODE'
    )):
        org_pid = Organisation.get_record_by_viewcode(viewcode)['pid']
        search = search \
            .filter('term', holdings__organisation__organisation_pid=org_pid)
    search = search \
        .params(preserve_order=True)\
        .sort({'sort_title': {"order": "asc"}})

    record['documents'] = list(search.scan())
    return render_template(
        template,
        record=record,
        viewcode=viewcode
    )
Beispiel #4
0
def organisation(database, organisation_data):
    """."""
    org = Organisation.create(
        data=organisation_data,
        delete_pid=False,
        dbcommit=True)
    return org
Beispiel #5
0
def index():
    """Home Page."""
    return render_template('rero_ils/frontpage.html',
                           version=__version__,
                           organisations=Organisation.get_all(),
                           viewcode=current_app.config.get(
                               'RERO_ILS_SEARCH_GLOBAL_VIEW_CODE'))
Beispiel #6
0
def persons_detailed_view(viewcode, pid):
    """Display default view.

    Sends record_viewed signal and renders template.
    :param pid: PID object.
    """
    # record_viewed.send(
    #     current_app._get_current_object(), pid=pid, record=record)
    mef_url = '{url}{pid}'.format(
        url=current_app.config.get('RERO_ILS_MEF_URL'), pid=pid)
    response = requests.get(url=mef_url, params=dict(resolve=1, sources=1))
    if response.status_code != requests.codes.ok:
        current_app.logger.info('Mef Error: {status} {url}'.format(
            status=response.status_code, url=mef_url))
        abort(response.status_code)
    record = response.json()
    record = record.get('metadata')
    search = DocumentsSearch()
    search = search.filter('term', authors__pid=pid)
    if (viewcode !=
            current_app.config.get('RERO_ILS_SEARCH_GLOBAL_VIEW_CODE')):
        org_pid = Organisation.get_record_by_viewcode(viewcode)['pid']
        search = search.filter('term',
                               items__organisation__organisation_pid=org_pid)
    for result in search.execute().hits.hits:
        record.setdefault('documents', []).append(result.get('_source'))
    return render_template('rero_ils/detailed_view_persons.html',
                           record=record,
                           viewcode=viewcode)
Beispiel #7
0
def organisation_temp(app, org_martigny):
    """Scope function organisation data."""
    org = Organisation.create(data=org_martigny,
                              dbcommit=True,
                              delete_pid=True,
                              reindex=True)
    flush_index(OrganisationsSearch.Meta.index)
    return org
Beispiel #8
0
def org_martigny(app, org_martigny_data):
    """Create Martigny organisation."""
    org = Organisation.create(data=org_martigny_data,
                              delete_pid=False,
                              dbcommit=True,
                              reindex=True)
    flush_index(OrganisationSearch.Meta.index)
    return org
Beispiel #9
0
 def decorated_view(*args, **kwargs):
     viewCodes = Organisation.all_code()
     # Add default view code
     viewCodes.append(current_app.config.get(
         'RERO_ILS_SEARCH_GLOBAL_VIEW_CODE'))
     if not kwargs['viewcode'] in viewCodes:
         abort(404)
     return fn(*args, **kwargs)
Beispiel #10
0
def org_sion(app, org_sion_data):
    """Create Sion organisation."""
    org = Organisation.create(data=org_sion_data,
                              delete_pid=False,
                              dbcommit=True,
                              reindex=True)
    flush_index(OrganisationsSearch.Meta.index)
    return org
Beispiel #11
0
def test_create_fee_euro(client, librarian_martigny_no_email,
                         item_lib_martigny, patron_martigny_no_email,
                         json_header, circulation_policies):
    """ Test overdue loans with if we change the organisation default
        currency."""
    login_user_via_session(client, librarian_martigny_no_email.user)

    # create a checkout
    res, data = postdata(
        client,
        'api_item.checkout',
        {
            'item_pid': item_lib_martigny.pid,
            'patron_pid': patron_martigny_no_email.pid
        },
    )
    assert res.status_code == 200

    # load the created loan and place it in overdue
    loan_pid = data.get('action_applied')[LoanAction.CHECKOUT].get('pid')
    loan = Loan.get_record_by_pid(loan_pid)
    end_date = datetime.now(timezone.utc) - timedelta(days=7)
    loan['end_date'] = end_date.isoformat()
    loan.update(loan, dbcommit=True, reindex=True)
    overdue_loans = get_overdue_loans()
    assert overdue_loans[0].get('pid') == loan_pid

    # ensure that 'default_currency' of the linked organisation in 'EUR'
    org = Organisation.get_record_by_pid(loan.organisation_pid)
    org['default_currency'] = 'EUR'
    org.update(org, dbcommit=True, reindex=True)
    org = Organisation.get_record_by_pid(loan.organisation_pid)
    assert org.get('default_currency') == 'EUR'

    # create notification and check the created fee is in euro
    notification = loan.create_notification(notification_type='overdue')
    flush_index(NotificationsSearch.Meta.index)
    flush_index(LoansSearch.Meta.index)
    fee = list(notification.fees)[0]
    assert fee.get('currency') == org.get('default_currency')
Beispiel #12
0
def person_view_method(pid, record, template=None, **kwargs):
    """Display default view.

    Sends record_viewed signal and renders template.
    :param pid: PID object.
    """
    record_viewed.send(current_app._get_current_object(),
                       pid=pid,
                       record=record)

    # Get author documents
    search = DocumentsSearch().filter('term', authors__pid=pid.pid_value)

    viewcode = kwargs['viewcode']
    if (viewcode !=
            current_app.config.get('RERO_ILS_SEARCH_GLOBAL_VIEW_CODE')):
        org_pid = Organisation.get_record_by_viewcode(viewcode)['pid']
        search = search.filter(
            'term', holdings__organisation__organisation_pid=org_pid)

    record['documents'] = list(search.scan())

    return render_template(template, record=record, viewcode=viewcode)
def test_organisation_create(db, minimal_organisation_record):
    """Test organisation creat."""
    from copy import deepcopy
    org_rec = deepcopy(minimal_organisation_record)
    org = Organisation.create(minimal_organisation_record)
    assert org_rec == org
Beispiel #14
0
def tmp_organisation(db, organisation_data):
    """."""
    org = Organisation.create(data=organisation_data,
                              dbcommit=True,
                              delete_pid=True)
    return org
def test_organisation_create_pid(db, minimal_organisation_record):
    """Test organisation creat with pid."""
    org = Organisation.create(minimal_organisation_record)
    assert org['pid'] == '1'
def test_get_record_by_viewcode(org_martigny):
    """Test Organisation.get_record_by_viewcode."""
    data = Organisation.get_record_by_viewcode('org1')
    assert data['pid'] == org_martigny.pid
    with pytest.raises(Exception):
        assert Organisation.get_record_by_viewcode('dummy')
def test_get_record_by_online_harvested_source(org_martigny):
    """Test get_record_by_online_harvested_source."""
    source = org_martigny.get('online_harvested_source')
    org = Organisation.get_record_by_online_harvested_source(source)
    assert org.pid == org_martigny.pid
    assert Organisation.get_record_by_online_harvested_source('dummy') is None
Beispiel #18
0
def test_cli_reindex_missing(app, script_info, org_sion_data):
    """Test reindex missing cli."""
    org = Organisation.create(
        data=org_sion_data,
        delete_pid=False,
        dbcommit=True,
    )

    runner = CliRunner()
    res = runner.invoke(reindex_missing, ['-t', 'xxx', '-t', 'org', '-v'],
                        obj=script_info)
    assert res.output.strip().split('\n') == [
        'Indexing missing xxx: ERROR pid type does not exist!',
        'Indexing missing org: 1', '1\torg\torg2'
    ]

    # test reindex with integreted queue
    # - we have to initialize the default indexer queue
    runner = CliRunner()
    res = runner.invoke(init_queue, [], obj=script_info)
    assert res.output.strip().split('\n') == [
        'Queue has been initialized: indexer'
    ]

    runner = CliRunner()
    res = runner.invoke(reindex, ['-t', 'org', '--yes-i-know'],
                        obj=script_info)
    assert res.output.strip().split('\n') == [
        'Sending org to indexing queue : 1',
        'Execute "invenio reroils run" command to process the queue!'
    ]

    runner = CliRunner()
    res = runner.invoke(run, [], obj=script_info)
    assert res.output.strip().split('\n') == [
        'Indexing records ...', '"indexer" indexed: 1 error: 0'
    ]
    # - test direct indexing:
    runner = CliRunner()
    res = runner.invoke(reindex, ['-t', 'org', '--yes-i-know', '-d'],
                        obj=script_info)
    assert res.output.strip().split('\n') == [
        'Indexing org: 1', f'1\t{org.id}\t{org.pid}'
    ]

    # test reindex with dynamicly created queue `test_queue`
    # - initialize a new indexer queue
    queue_name = 'test_queue'
    runner = CliRunner()
    res = runner.invoke(init_queue, ['-n', queue_name], obj=script_info)
    assert res.output.strip().split('\n') == [
        'Queue has been initialized: test_queue'
    ]

    runner = CliRunner()
    res = runner.invoke(reindex,
                        ['-t', 'org', '-q', queue_name, '--yes-i-know'],
                        obj=script_info)
    assert res.output.strip().split('\n') == [
        'Sending org to indexing queue (test_queue): 1',
        f'Execute "invenio reroils run -q {queue_name}" '
        'command to process the queue!'
    ]

    runner = CliRunner()
    res = runner.invoke(run, ['-q', queue_name], obj=script_info)
    assert res.output.strip().split('\n') == [
        f'Indexing records ({queue_name})...',
        f'"{queue_name}" indexed: 1 error: 0'
    ]

    # - purge the new indexer queue
    queue_name = 'test_queue'
    runner = CliRunner()
    res = runner.invoke(purge_queue, ['-n', queue_name], obj=script_info)
    assert res.output.strip().split('\n') == [
        f'Queue has been purged: {queue_name} 0'
    ]
    # - delete the new indexer queue
    queue_name = 'test_queue'
    runner = CliRunner()
    res = runner.invoke(delete_queue, ['-n', queue_name], obj=script_info)
    assert res.output.strip().split('\n') == [
        f'Queue has been deleted: {queue_name}'
    ]
Beispiel #19
0
     pid_minter='organisation_id',
     pid_fetcher='organisation_id',
     search_class=RecordsSearch,
     search_index='organisations',
     indexer_class=IlsRecordIndexer,
     search_type=None,
     record_serializers={
         'application/json':
         ('rero_ils.modules.serializers:json_v1_response')
     },
     search_serializers={
         'application/json': ('rero_ils.modules.serializers:json_v1_search')
     },
     list_route='/organisations/',
     record_loaders={
         'application/json': lambda: Organisation(request.get_json()),
     },
     record_class='rero_ils.modules.organisations.api:Organisation',
     item_route=
     '/organisations/<pid(org, record_class="rero_ils.modules.organisations.api:Organisation"):pid_value>',
     default_media_type='application/json',
     max_result_window=10000,
     search_factory_imp='rero_ils.query:search_factory',
     create_permission_factory_imp=deny_all,
     update_permission_factory_imp=deny_all,
     delete_permission_factory_imp=deny_all,
     read_permission_factory_imp=can_access_organisation_records_factory,
 ),
 lib=dict(
     pid_type='lib',
     pid_minter='library_id',