def test_post_partial_internal_location(client, json_headers, testdata, users): """Test POST of internal_location without all required data.""" user_login(client, "admin", users) del NEW_INTERNAL_LOCATION["location_pid"] url = url_for("invenio_records_rest.ilocid_list") validate_response(client, "post", url, json_headers, NEW_INTERNAL_LOCATION, 400)
def test_document_request_add_provider(client, json_headers, testdata, users): """Test add provider to Document Request permissions.""" tests = [ ("patron1", "dreq-1", 403), ("librarian", "dreq-1", 202), ("admin", "dreq-1", 202), ("anonymous", "dreq-1", 401), ] for user, res_id, expected_resp_code in tests: user_login(client, user, users) url = url_for( "invenio_app_ils_document_requests.dreqid_provider", pid_value=res_id, ) data = { "physical_item_provider": { "pid": "acquisition-order-pid", "pid_type": "acquisition", } } validate_response( client, "post", url, json_headers, data, expected_resp_code )
def test_item_circulation(client, json_headers, testdata, users): """Test item circulation filtering.""" tests = [ ("patron1", "itemid-56", 403, False), ("patron2", "itemid-56", 403, True), ("patron1", "itemid-57", 403, True), ("patron2", "itemid-57", 403, False), ("librarian", "itemid-56", 200, False), ("admin", "itemid-57", 200, False), ] for username, pid, expected_resp_code, filtered in tests: user_login(client, username, users) url = url_for("invenio_records_rest.pitmid_item", pid_value=pid) res = validate_response( client, "get", url, json_headers, None, expected_resp_code ) if res.status_code < 400: circulation = res.json["metadata"]["circulation"] filter_keys = ["loan_pid", "patron_pid"] if filtered: for key in filter_keys: assert key not in circulation else: for key in filter_keys: assert key in circulation
def test_post_internal_location(client, json_headers, testdata, users): """Test POST of internal_location.""" user_login(client, "admin", users) url = url_for("invenio_records_rest.ilocid_list") res = validate_response(client, "post", url, json_headers, NEW_INTERNAL_LOCATION, 201) data = json.loads(res.data.decode("utf-8"))["metadata"] assert "name" in data["location"]
def test_document_request_reject(client, json_headers, testdata, users): """Test Document Request permissions to reject request.""" tests = [ ("patron1", "dreq-1", 202), ("librarian", "dreq-5", 202), ("admin", "dreq-6", 202), ("anonymous", "dreq-1", 401), ("admin", "dreq-2", 400), ] for user, res_id, expected_resp_code in tests: user_login(client, user, users) url = url_for("invenio_app_ils_document_requests.dreqid_reject", pid_value=res_id) data = {"reject_reason": "USER_CANCEL"} validate_response(client, "post", url, json_headers, data, expected_resp_code)
def test_post_item(client, json_headers, testdata, users, item_record): """Test POST of an item.""" user_login(client, "admin", users) url = url_for("invenio_records_rest.pitmid_list") del item_record["pid"] res = validate_response(client, "post", url, json_headers, item_record, 201) data = json.loads(res.data.decode("utf-8"))["metadata"] assert "name" in data["internal_location"]
def test_document_request_add_document(client, json_headers, testdata, users): """Test add document to Document Request permissions.""" tests = [ ("patron1", "dreq-1", 403), ("librarian", "dreq-1", 202), ("admin", "dreq-1", 202), ("anonymous", "dreq-1", 401), ] for user, res_id, expected_resp_code in tests: user_login(client, user, users) url = url_for( "invenio_app_ils_document_requests.dreqid_document", pid_value=res_id, ) data = {"document_pid": "docid-1"} validate_response(client, "post", url, json_headers, data, expected_resp_code)
def test_document_request_remove_provider(client, json_headers, testdata, users): """Test remove provider from Document Request permissions.""" tests = [ ("patron1", "dreq-1", 403), ("librarian", "dreq-1", 202), ("admin", "dreq-1", 202), ("anonymous", "dreq-1", 401), ] for user, res_id, expected_resp_code in tests: user_login(client, user, users) url = url_for( "invenio_app_ils_document_requests.dreqid_provider", pid_value=res_id, ) validate_response(client, "delete", url, json_headers, None, expected_resp_code)
def test_get_document_request_endpoint(client, json_headers, testdata, users): """Test GET permissions.""" tests = [ ("patron1", "dreq-1", 200), ("librarian", "dreq-1", 200), ("admin", "dreq-1", 200), ("patron2", "dreq-1", 403), ("anonymous", "dreq-1", 401), ("patron2", "dreq-2", 200), ("librarian", "dreq-2", 200), ("admin", "dreq-2", 200), ("patron1", "dreq-2", 403), ("anonymous", "dreq-2", 401), ] for user, res_id, expected_resp_code in tests: user_login(client, user, users) url = url_for("invenio_records_rest.dreqid_item", pid_value=res_id) validate_response(client, "get", url, json_headers, None, expected_resp_code)