示例#1
0
def test_can_access_item_patron(client, json_header, patron_martigny_no_email,
                                item_lib_martigny):
    """Test a patron can access an item."""

    login_user_for_view(client, patron_martigny_no_email)
    assert not can_access_item()
    assert not can_access_item(item=item_lib_martigny)
示例#2
0
def test_can_access_item_librarian(
        client, json_header,
        librarian_martigny_no_email, item_lib_martigny):
    """Test a librarian can access an item."""
    user = librarian_martigny_no_email.user
    assert not can_access_item(user=user)
    login_user_for_view(client, librarian_martigny_no_email)
    assert not can_access_item(user=user)
    assert can_access_item(user=user, item=item_lib_martigny)
示例#3
0
def test_ill_request_create_request_form(client, app,
                                         ill_request_martigny_data_tmp,
                                         loc_public_martigny, patron_martigny):
    """ test ill request create form."""
    request_form_url = url_for('ill_requests.ill_request_form',
                               viewcode='global')

    # Not logged user don't have access to request_form. It is redirected to
    # login form
    res = client.get(request_form_url)
    assert res.status_code == 302

    # logged as user
    login_user_for_view(client, patron_martigny)
    res = client.get(request_form_url)
    assert res.status_code == 200

    # try to create an ill_request with incorrect data
    #   as user request a copy of document part, they need to specify pages.
    #   the form submission, will return a response status == 200 (display the
    #   form with error message)
    form_data = {
        'document-title': 'test title',
        'request_copy': '1',
        'document-year': '2020',
        'pickup_location': loc_public_martigny.pid
    }
    res = client.post(request_form_url, data=form_data)
    assert res.status_code == 200

    # try to create an ill_request with correct data
    #   as user request a copy of document part, they need to specify pages.
    #   the form submission, will return a response status == 201 (user should
    #   be redirected to patron profile page)
    form_data['pages'] = '12-13'
    res = client.post(request_form_url, data=form_data)
    assert res.status_code == 302
示例#4
0
def test_loan_operation_log(client, operation_log_data,
                            loan_validated_martigny, librarian_martigny):
    """Test operation logs creation."""
    login_user_for_view(client, librarian_martigny)

    operation_log = LoanOperationLog.create(deepcopy(loan_validated_martigny),
                                            index_refresh='wait_for')
    operation_log['$schema'] = current_jsonschemas.path_to_url(
        LoanOperationLog._schema)
    operation_log.validate()
    log_data = LoanOperationLog.get_record(operation_log.id)
    assert log_data['operation'] == 'create'
    assert log_data['user_name'] == 'Pedronni, Marie'
    assert log_data['date'] == loan_validated_martigny['transaction_date']
    assert not log_data['loan']['override_flag']
    assert log_data['loan']['transaction_channel'] == 'system'
    assert log_data['loan']['transaction_user']['name'] == 'Pedronni, Marie'
    assert log_data['loan']['transaction_location'][
        'name'] == 'Martigny Library Public Space'
    assert log_data['loan']['pickup_location'][
        'name'] == 'Martigny Library Public Space'
    assert log_data['loan']['patron'] == {
        'pid': 'ptrn6',
        'hashed_pid': 'e11ff43bff5be4cf70350e2d15149e29',
        'name': 'Roduit, Louis',
        'type': 'children',
        'age': 74,
        'postal_code': '1920',
        'gender': 'other',
        'local_codes': ['code1']
    }
    assert log_data['loan']['item'] == {
        'category': 'standard',
        'call_number': '001313',
        'document': {
            'pid':
            'doc1',
            'title':
            'titre en chinois. Part Number, Part Number = Titolo cinese : '
            'sottotitolo in cinese',
            'type':
            'docsubtype_other_book'
        },
        'holding': {
            'pid': '1',
            'location_name': 'Martigny Library Public Space'
        },
        'library_pid': 'lib1',
        'pid': 'item5'
    }

    # Test SIP2
    loan = deepcopy(loan_validated_martigny)
    loan['selfcheck_terminal_id'] = 'ABCDEF'
    operation_log = LoanOperationLog.create(loan, index_refresh='wait_for')
    operation_log['$schema'] = current_jsonschemas.path_to_url(
        LoanOperationLog._schema)
    operation_log.validate()
    log_data = LoanOperationLog.get_record(operation_log.id)
    assert log_data['loan']['transaction_channel'] == 'sip2'
    assert not log_data['loan'].get('transaction_user')
示例#5
0
def test_librarian_update_permission_factory(client, document, ebook_1,
                                             librarian_martigny):
    """Test librarian_update_permission_factory function."""
    assert not librarian_update_permission_factory(ebook_1).can()
    login_user_for_view(client, librarian_martigny)
    assert librarian_update_permission_factory(document).can()