Exemplo n.º 1
0
def test_ill_request_get_request(ill_request_martigny, ill_request_sion,
                                 patron_martigny_no_email):
    """Test ill request get_request functions."""
    assert len(list(ILLRequest.get_requests_by_patron_pid(
        patron_martigny_no_email.pid, status='pending'
    ))) == 1
    assert len(list(ILLRequest.get_requests_by_patron_pid(
        patron_martigny_no_email.pid, status='denied'
    ))) == 0
Exemplo n.º 2
0
def test_extended_validation(app, ill_request_martigny_data_tmp):
    """Test extended validation for ill request."""
    data = ill_request_martigny_data_tmp

    # pages are reqiured if request is a request copy
    data['copy'] = True
    if 'pages' in data:
        del data['pages']
    with pytest.raises(RecordValidationError):
        ILLRequest.validate(ILLRequest(data))
Exemplo n.º 3
0
def create_ill_requests(input_file):
    """Create ILL request for each organisation."""
    locations = get_locations()
    patron_pids = {}

    with open(input_file, 'r', encoding='utf-8') as request_file:
        requests = json.load(request_file)
        for request_data in requests:
            for organisation_pid, location_pid in locations.items():
                if 'pid' in request_data:
                    del request_data['pid']
                if organisation_pid not in patron_pids:
                    patron_pids[organisation_pid] = list(
                        Patron.get_all_pids_for_organisation(organisation_pid))
                patron_pid = random.choice(patron_pids[organisation_pid])
                request_data['patron'] = {
                    '$ref': get_ref_for_pid('patrons', patron_pid)
                }
                request_data['pickup_location'] = {
                    '$ref': get_ref_for_pid('locations', location_pid)
                }
                request = ILLRequest.create(request_data,
                                            dbcommit=True,
                                            reindex=True)
                click.echo('\tRequest: #{pid}  \tfor org#{org_id}'.format(
                    pid=request.pid, org_id=request.organisation_pid))
Exemplo n.º 4
0
def ill_request_sion(app, loc_public_sion, patron_sion, ill_request_sion_data):
    """Create ill request for Sion location."""
    illr = ILLRequest.create(data=ill_request_sion_data,
                             delete_pid=False,
                             dbcommit=True,
                             reindex=True)
    flush_index(ILLRequestsSearch.Meta.index)
    return illr
Exemplo n.º 5
0
def ill_request_martigny2(app, loc_public_martigny, patron_martigny_no_email,
                          ill_request_martigny2_data):
    """Create ill request for Martigny2 location."""
    illr = ILLRequest.create(data=ill_request_martigny2_data,
                             delete_pid=False,
                             dbcommit=True,
                             reindex=True)
    flush_index(ILLRequestsSearch.Meta.index)
    return illr
Exemplo n.º 6
0
def test_ill_request_es_mapping(es, db, loc_public_martigny, patron_martigny,
                                ill_request_martigny_data):
    """Test ill request elasticsearch mapping."""
    search = ILLRequestsSearch()
    mapping = get_mapping(search.Meta.index)
    assert mapping
    request = ILLRequest.create(ill_request_martigny_data,
                                dbcommit=True,
                                reindex=True,
                                delete_pid=True)
    assert mapping == get_mapping(search.Meta.index)
    request.delete(force=True, dbcommit=True, delindex=True)
Exemplo n.º 7
0
    def update(cls, user, record):
        """Update permission check.

        :param user: Logged user.
        :param record: Record to check.
        :return: True is action can be done.
        """
        # only staff members (lib, sys_lib) can update request
        # record cannot be null
        if not current_patron or not current_patron.is_librarian or not record:
            return False
        return current_organisation['pid'] \
            == ILLRequest(record).organisation_pid
Exemplo n.º 8
0
    def read(cls, user, record):
        """Read permission check.

        :param user: Logged user.
        :param record: Record to check.
        :return: True is action can be done.
        """
        if current_librarian:
            # staff member (lib, sys_lib) can always read request from their
            # own organisation
            return current_librarian.organisation_pid \
                    == ILLRequest(record).organisation_pid
        # patron can only read their own requests
        elif current_patrons:
            return record.patron_pid in [ptrn.pid for ptrn in current_patrons]
        return False
def test_extended_validation(app, ill_request_martigny_data_tmp):
    """Test extended validation for ill request."""
    data = copy.deepcopy(ill_request_martigny_data_tmp)

    # pages are required if request is a request copy
    data['copy'] = True
    if 'pages' in data:
        del data['pages']
    with pytest.raises(RecordValidationError):
        ILLRequest.validate(ILLRequest(data))

    # test on 'notes' field :: have 2 note of the same type is disallowed
    data = copy.deepcopy(ill_request_martigny_data_tmp)
    data['notes'] = [{
        'type': ILLRequestNoteStatus.PUBLIC_NOTE,
        'content': 'dummy content'
    }]
    ILLRequest.validate(ILLRequest(data))
    with pytest.raises(RecordValidationError):
        data['notes'].append({
            'type': ILLRequestNoteStatus.PUBLIC_NOTE,
            'content': 'second dummy note'
        })
        ILLRequest.validate(ILLRequest(data))
Exemplo n.º 10
0
    def update(cls, user, record):
        """Update permission check.

        :param user: Logged user.
        :param record: Record to check.
        :return: True is action can be done.
        """
        # only staff members (lib, sys_lib) can update request
        # record cannot be null
        if not current_patron or not current_patron.is_librarian or not record:
            return False
        if current_organisation['pid'] == ILLRequest(record).organisation_pid:
            # 'sys_lib' can update all request
            if current_patron.is_system_librarian:
                return True
            # 'lib' can only update request linked to its own library
            return current_patron.library_pid and \
                record.get_library().pid == current_patron.library_pid
        return False