invenio-app-ils 4.6.0__py2.py3-none-any.whl → 5.0.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- invenio_app_ils/__init__.py +1 -1
- invenio_app_ils/assets/semantic-ui/less/theme.config +103 -0
- invenio_app_ils/circulation/api.py +9 -5
- invenio_app_ils/circulation/config.py +1 -0
- invenio_app_ils/circulation/loaders/schemas/json/loan_checkout.py +1 -1
- invenio_app_ils/circulation/loaders/schemas/json/loan_request.py +2 -2
- invenio_app_ils/circulation/notifications/api.py +9 -1
- invenio_app_ils/circulation/notifications/messages.py +2 -1
- invenio_app_ils/circulation/templates/invenio_app_ils_circulation/notifications/update_dates.html +19 -0
- invenio_app_ils/cli.py +92 -64
- invenio_app_ils/config.py +10 -2
- invenio_app_ils/documents/loaders/jsonschemas/document.py +1 -1
- invenio_app_ils/eitems/loaders/jsonschemas/eitems.py +2 -2
- invenio_app_ils/patrons/anonymization.py +0 -4
- invenio_app_ils/series/loaders/jsonschemas/series.py +1 -1
- invenio_app_ils/webpack.py +27 -0
- {invenio_app_ils-4.6.0.dist-info → invenio_app_ils-5.0.0.dist-info}/METADATA +52 -42
- {invenio_app_ils-4.6.0.dist-info → invenio_app_ils-5.0.0.dist-info}/RECORD +24 -112
- {invenio_app_ils-4.6.0.dist-info → invenio_app_ils-5.0.0.dist-info}/entry_points.txt +3 -0
- {invenio_app_ils-4.6.0.dist-info → invenio_app_ils-5.0.0.dist-info}/top_level.txt +0 -1
- invenio_app_ils/notifications/admin.py +0 -57
- tests/__init__.py +0 -8
- tests/api/__init__.py +0 -8
- tests/api/acquisition/__init__.py +0 -8
- tests/api/acquisition/test_acq_orders_crud.py +0 -99
- tests/api/acquisition/test_acq_orders_permissions.py +0 -104
- tests/api/acquisition/test_acq_providers_permissions.py +0 -83
- tests/api/circulation/__init__.py +0 -8
- tests/api/circulation/test_expired_loans.py +0 -88
- tests/api/circulation/test_loan_bulk_extend.py +0 -169
- tests/api/circulation/test_loan_checkout.py +0 -422
- tests/api/circulation/test_loan_default_durations.py +0 -43
- tests/api/circulation/test_loan_document_resolver.py +0 -18
- tests/api/circulation/test_loan_extend.py +0 -122
- tests/api/circulation/test_loan_item_permissions.py +0 -135
- tests/api/circulation/test_loan_item_resolver.py +0 -26
- tests/api/circulation/test_loan_list_permissions.py +0 -98
- tests/api/circulation/test_loan_patron_resolver.py +0 -38
- tests/api/circulation/test_loan_request.py +0 -338
- tests/api/circulation/test_loan_update.py +0 -150
- tests/api/circulation/test_notifications.py +0 -221
- tests/api/conftest.py +0 -227
- tests/api/document_requests/__init__.py +0 -8
- tests/api/document_requests/test_document_requests.py +0 -131
- tests/api/document_requests/test_document_requests_permissions.py +0 -159
- tests/api/document_requests/test_notifications_filter.py +0 -35
- tests/api/ill/__init__.py +0 -8
- tests/api/ill/test_ill_brw_crud.py +0 -74
- tests/api/ill/test_ill_brw_reqs_patron_loan_create_action.py +0 -198
- tests/api/ill/test_ill_brw_reqs_patron_loan_extension_actions.py +0 -280
- tests/api/ill/test_ill_brw_reqs_permissions.py +0 -163
- tests/api/ill/test_ill_providers_permissions.py +0 -82
- tests/api/ils/__init__.py +0 -8
- tests/api/ils/documents/__init__.py +0 -8
- tests/api/ils/documents/test_document_crud.py +0 -57
- tests/api/ils/documents/test_document_permissions.py +0 -100
- tests/api/ils/documents/test_document_resolvers.py +0 -35
- tests/api/ils/eitems/__init__.py +0 -8
- tests/api/ils/eitems/test_eitems_crud.py +0 -42
- tests/api/ils/eitems/test_eitems_permissions.py +0 -85
- tests/api/ils/eitems/test_files.py +0 -162
- tests/api/ils/items/__init__.py +0 -8
- tests/api/ils/items/test_apis.py +0 -43
- tests/api/ils/items/test_items_crud.py +0 -99
- tests/api/ils/items/test_items_permissions.py +0 -107
- tests/api/ils/records_relations/__init__.py +0 -8
- tests/api/ils/records_relations/helpers.py +0 -115
- tests/api/ils/records_relations/test_records_relations_parentchild.py +0 -560
- tests/api/ils/records_relations/test_records_relations_sequence.py +0 -294
- tests/api/ils/records_relations/test_records_relations_siblings.py +0 -751
- tests/api/ils/series/__init__.py +0 -8
- tests/api/ils/series/test_series_permissions.py +0 -95
- tests/api/ils/test_anonymization.py +0 -181
- tests/api/ils/test_apis.py +0 -76
- tests/api/ils/test_closures.py +0 -353
- tests/api/ils/test_errors.py +0 -125
- tests/api/ils/test_facets.py +0 -88
- tests/api/ils/test_internal_locations.py +0 -96
- tests/api/ils/test_loaders.py +0 -51
- tests/api/ils/test_metadata_extensions.py +0 -206
- tests/api/ils/test_notifications.py +0 -173
- tests/api/ils/test_notifications_mails.py +0 -37
- tests/api/ils/test_notifications_permissions.py +0 -55
- tests/api/ils/test_patrons.py +0 -102
- tests/api/ils/test_record_delete.py +0 -42
- tests/api/ils/test_record_permissions.py +0 -132
- tests/api/ils/test_resolvers.py +0 -205
- tests/api/ils/test_stats.py +0 -142
- tests/api/ils/test_tasks.py +0 -209
- tests/api/ils/test_vocabularies.py +0 -35
- tests/conftest.py +0 -221
- tests/data/acq_orders.json +0 -110
- tests/data/acq_providers.json +0 -12
- tests/data/document_requests.json +0 -77
- tests/data/documents.json +0 -238
- tests/data/eitems.json +0 -71
- tests/data/ill_borrowing_requests.json +0 -77
- tests/data/ill_providers.json +0 -12
- tests/data/internal_locations.json +0 -22
- tests/data/items.json +0 -304
- tests/data/loans.json +0 -133
- tests/data/loans_most_loaned.json +0 -128
- tests/data/locations.json +0 -26
- tests/data/series.json +0 -33
- tests/helpers.py +0 -107
- tests/templates/notifications/title_body.html +0 -8
- tests/templates/notifications/title_body_html.html +0 -13
- tests/templates/notifications/title_body_html_ctx.html +0 -13
- tests/templates/notifications/title_only.html +0 -3
- tests/test_post_logout_redirect.py +0 -23
- tests/test_version.py +0 -17
- /tests/templates/notifications/blank.html → /invenio_app_ils/assets/semantic-ui/templates/.gitkeep +0 -0
- {invenio_app_ils-4.6.0.dist-info → invenio_app_ils-5.0.0.dist-info}/WHEEL +0 -0
- {invenio_app_ils-4.6.0.dist-info → invenio_app_ils-5.0.0.dist-info}/licenses/AUTHORS.rst +0 -0
- {invenio_app_ils-4.6.0.dist-info → invenio_app_ils-5.0.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
#
|
|
3
|
-
# Copyright (C) 2020 CERN.
|
|
4
|
-
#
|
|
5
|
-
# invenio-app-ils is free software; you can redistribute it and/or modify it
|
|
6
|
-
# under the terms of the MIT License; see LICENSE file for more details.
|
|
7
|
-
|
|
8
|
-
"""Test ILL borrowing requests actions."""
|
|
9
|
-
|
|
10
|
-
import json
|
|
11
|
-
from datetime import timedelta
|
|
12
|
-
|
|
13
|
-
import arrow
|
|
14
|
-
from flask import url_for
|
|
15
|
-
|
|
16
|
-
from invenio_app_ils.ill.api import BORROWING_REQUEST_PID_TYPE
|
|
17
|
-
from tests.helpers import user_login, user_logout
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def _create_on_loan_brwreq(
|
|
21
|
-
patron_id, loan_start_date, loan_end_date, client, json_headers
|
|
22
|
-
):
|
|
23
|
-
"""Create a new ON_LOAN ILL borrowing request."""
|
|
24
|
-
|
|
25
|
-
def _create_brwreq(patron_id):
|
|
26
|
-
brwreq = dict(
|
|
27
|
-
document_pid="docid-3",
|
|
28
|
-
provider_pid="ill-provid-2",
|
|
29
|
-
patron_pid=patron_id,
|
|
30
|
-
status="REQUESTED",
|
|
31
|
-
type="PHYSICAL_COPY",
|
|
32
|
-
)
|
|
33
|
-
url = url_for("invenio_records_rest.illbid_list")
|
|
34
|
-
res = client.post(url, headers=json_headers, data=json.dumps(brwreq))
|
|
35
|
-
assert res.status_code == 201
|
|
36
|
-
brw_req = res.get_json()["metadata"]
|
|
37
|
-
return brw_req["pid"]
|
|
38
|
-
|
|
39
|
-
def _create_loan_action(pid):
|
|
40
|
-
"""Send request to create a new loan from the ILL."""
|
|
41
|
-
data = dict(
|
|
42
|
-
loan_start_date=loan_start_date,
|
|
43
|
-
loan_end_date=loan_end_date,
|
|
44
|
-
transaction_location_pid="locid-1",
|
|
45
|
-
)
|
|
46
|
-
url = url_for("invenio_app_ils_ill.illbid_create_loan", pid_value=pid)
|
|
47
|
-
res = client.post(url, headers=json_headers, data=json.dumps(data))
|
|
48
|
-
assert res.status_code == 200
|
|
49
|
-
brw_req = res.get_json()["metadata"]
|
|
50
|
-
assert brw_req["status"] == "ON_LOAN"
|
|
51
|
-
return brw_req
|
|
52
|
-
|
|
53
|
-
brwreq_pid = _create_brwreq(patron_id)
|
|
54
|
-
return _create_loan_action(brwreq_pid)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def _create_on_loan_brwreq_random_dates(patron_id, client, json_headers):
|
|
58
|
-
"""Create a new ON_LOAN ILL borrowing request with random start/end."""
|
|
59
|
-
loan_start_date = arrow.utcnow()
|
|
60
|
-
loan_end_date = loan_start_date + timedelta(days=15)
|
|
61
|
-
brwreq = _create_on_loan_brwreq(
|
|
62
|
-
patron_id,
|
|
63
|
-
loan_start_date.date().isoformat(),
|
|
64
|
-
loan_end_date.date().isoformat(),
|
|
65
|
-
client,
|
|
66
|
-
json_headers,
|
|
67
|
-
)
|
|
68
|
-
return brwreq, brwreq["pid"]
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def _create_on_loan_brwreq_with_pending_extension(patron_id, client, json_headers):
|
|
72
|
-
"""Create a new ON_LOAN ILL borrowing request with pending extension."""
|
|
73
|
-
today = arrow.utcnow().date().isoformat()
|
|
74
|
-
brwreq, brwreq_pid = _create_on_loan_brwreq_random_dates("1", client, json_headers)
|
|
75
|
-
res = _request_extension_action(brwreq_pid, client, json_headers)
|
|
76
|
-
assert res.status_code == 200
|
|
77
|
-
|
|
78
|
-
brwreq = res.get_json()["metadata"]
|
|
79
|
-
patron_loan = brwreq["patron_loan"]
|
|
80
|
-
|
|
81
|
-
assert patron_loan["loan"]["state"] == "ITEM_ON_LOAN"
|
|
82
|
-
assert "extension_count" not in patron_loan["loan"]
|
|
83
|
-
assert patron_loan["extension"]["status"] == "PENDING"
|
|
84
|
-
assert patron_loan["extension"]["request_date"] == today
|
|
85
|
-
|
|
86
|
-
return brwreq, brwreq["pid"]
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def _request_extension_action(pid, client, json_headers):
|
|
90
|
-
"""Send HTTP request to request extension of ILL Borrowing Request."""
|
|
91
|
-
url = url_for("invenio_app_ils_ill.illbid_request_extension", pid_value=pid)
|
|
92
|
-
return client.post(url, headers=json_headers, data=json.dumps({}))
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def _accept_extension_action(pid, data, client, json_headers):
|
|
96
|
-
"""Send HTTP request to accept extension of ILL Borrowing Request."""
|
|
97
|
-
data["transaction_location_pid"] = "locid-1"
|
|
98
|
-
url = url_for("invenio_app_ils_ill.illbid_accept_extension", pid_value=pid)
|
|
99
|
-
return client.post(url, headers=json_headers, data=json.dumps(data))
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def _decline_extension_action(pid, _, client, json_headers):
|
|
103
|
-
"""Send HTTP request to decline extension of ILL Borrowing Request."""
|
|
104
|
-
url = url_for("invenio_app_ils_ill.illbid_decline_extension", pid_value=pid)
|
|
105
|
-
return client.post(url, headers=json_headers, data=json.dumps({}))
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def test_brwreq_request_extension_only_owner(client, testdata, json_headers, users):
|
|
109
|
-
"""Test that patron can request extension only for his own loan."""
|
|
110
|
-
user_login(client, "librarian", users)
|
|
111
|
-
|
|
112
|
-
brwreq, brwreq_pid = _create_on_loan_brwreq_random_dates("1", client, json_headers)
|
|
113
|
-
|
|
114
|
-
# anonymous, forbidden
|
|
115
|
-
user_logout(client)
|
|
116
|
-
res = _request_extension_action(brwreq_pid, client, json_headers)
|
|
117
|
-
assert res.status_code == 401
|
|
118
|
-
|
|
119
|
-
# patron2 is not the owner, forbidden
|
|
120
|
-
user_login(client, "patron2", users)
|
|
121
|
-
res = _request_extension_action(brwreq_pid, client, json_headers)
|
|
122
|
-
assert res.status_code == 403
|
|
123
|
-
|
|
124
|
-
# patron1 is the owner, success
|
|
125
|
-
user_login(client, "patron1", users)
|
|
126
|
-
res = _request_extension_action(brwreq_pid, client, json_headers)
|
|
127
|
-
assert res.status_code == 200
|
|
128
|
-
extension = res.get_json()["metadata"]["patron_loan"]["extension"]
|
|
129
|
-
assert extension["status"] == "PENDING"
|
|
130
|
-
assert extension["request_date"] == arrow.now().date().isoformat()
|
|
131
|
-
|
|
132
|
-
# create a new one with patron2 owner, librarian can request extension
|
|
133
|
-
user_login(client, "librarian", users)
|
|
134
|
-
brwreq, brwreq_pid = _create_on_loan_brwreq_random_dates("2", client, json_headers)
|
|
135
|
-
res = _request_extension_action(brwreq_pid, client, json_headers)
|
|
136
|
-
assert res.status_code == 200
|
|
137
|
-
assert extension["status"] == "PENDING"
|
|
138
|
-
assert extension["request_date"] == arrow.now().date().isoformat()
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
def test_brwreq_accept_decline_extension_only_librarian(
|
|
142
|
-
client, testdata, json_headers, users
|
|
143
|
-
):
|
|
144
|
-
"""Test that only librarian can accept or decline an extension."""
|
|
145
|
-
|
|
146
|
-
tests = [_accept_extension_action, _decline_extension_action]
|
|
147
|
-
for action in tests:
|
|
148
|
-
user_login(client, "librarian", users)
|
|
149
|
-
|
|
150
|
-
# create request
|
|
151
|
-
brwreq, brwreq_pid = _create_on_loan_brwreq_with_pending_extension(
|
|
152
|
-
"1", client, json_headers
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
loan_end_date = arrow.utcnow() + timedelta(days=15)
|
|
156
|
-
data = dict(loan_end_date=loan_end_date.date().isoformat())
|
|
157
|
-
|
|
158
|
-
# accept/decline
|
|
159
|
-
|
|
160
|
-
# anonymous, forbidden
|
|
161
|
-
user_logout(client)
|
|
162
|
-
res = action(brwreq_pid, data, client, json_headers)
|
|
163
|
-
assert res.status_code == 401
|
|
164
|
-
|
|
165
|
-
# patron, forbidden
|
|
166
|
-
user_login(client, "patron1", users)
|
|
167
|
-
res = action(brwreq_pid, data, client, json_headers)
|
|
168
|
-
assert res.status_code == 403
|
|
169
|
-
|
|
170
|
-
# librarian, success
|
|
171
|
-
user_login(client, "librarian", users)
|
|
172
|
-
res = action(brwreq_pid, data, client, json_headers)
|
|
173
|
-
assert res.status_code == 200
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
def test_brwreq_request_extension_fails_on_wrong_status(
|
|
177
|
-
client, testdata, json_headers, users
|
|
178
|
-
):
|
|
179
|
-
user_login(client, "patron1", users)
|
|
180
|
-
# demo data "illbid-1" is not ON_LOAN
|
|
181
|
-
res = _request_extension_action("illbid-1", client, json_headers)
|
|
182
|
-
assert res.status_code == 400
|
|
183
|
-
# demo data "illbid-7" has already a pending request extension
|
|
184
|
-
res = _request_extension_action("illbid-7", client, json_headers)
|
|
185
|
-
assert res.status_code == 400
|
|
186
|
-
# demo data "illbid-" has declined request extension
|
|
187
|
-
res = _request_extension_action("illbid-8", client, json_headers)
|
|
188
|
-
assert res.status_code == 400
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
def test_brwreq_accept_decline_extension_should_fail_when_loan_not_active(
|
|
192
|
-
client, testdata, json_headers, users
|
|
193
|
-
):
|
|
194
|
-
"""Test that accept or decline an extension fails on loan not active."""
|
|
195
|
-
|
|
196
|
-
tests = [_accept_extension_action, _decline_extension_action]
|
|
197
|
-
for action in tests:
|
|
198
|
-
user_login(client, "librarian", users)
|
|
199
|
-
|
|
200
|
-
# create request
|
|
201
|
-
brwreq, brwreq_pid = _create_on_loan_brwreq_with_pending_extension(
|
|
202
|
-
"1", client, json_headers
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
# check-in loan
|
|
206
|
-
loan_pid = brwreq["patron_loan"]["pid"]
|
|
207
|
-
url = url_for(
|
|
208
|
-
"invenio_circulation_loan_actions.loanid_actions",
|
|
209
|
-
pid_value=loan_pid,
|
|
210
|
-
action="checkin",
|
|
211
|
-
)
|
|
212
|
-
item_pid = dict(type=BORROWING_REQUEST_PID_TYPE, value=brwreq["pid"])
|
|
213
|
-
params = dict(
|
|
214
|
-
document_pid=brwreq["document_pid"],
|
|
215
|
-
item_pid=item_pid,
|
|
216
|
-
patron_pid=brwreq["patron_pid"],
|
|
217
|
-
transaction_location_pid="locid-1",
|
|
218
|
-
transaction_user_pid="1",
|
|
219
|
-
)
|
|
220
|
-
res = client.post(url, headers=json_headers, data=json.dumps(params))
|
|
221
|
-
assert res.status_code == 202
|
|
222
|
-
|
|
223
|
-
# accept extension
|
|
224
|
-
loan_end_date = arrow.utcnow() + timedelta(days=15)
|
|
225
|
-
data = dict(loan_end_date=loan_end_date.date().isoformat())
|
|
226
|
-
|
|
227
|
-
res = action(brwreq_pid, data, client, json_headers)
|
|
228
|
-
assert res.status_code == 400
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
def test_brwreq_accept_extension_success(client, testdata, json_headers, users):
|
|
232
|
-
"""Test accept extension success."""
|
|
233
|
-
user_login(client, "librarian", users)
|
|
234
|
-
|
|
235
|
-
# create request
|
|
236
|
-
brwreq, brwreq_pid = _create_on_loan_brwreq_with_pending_extension(
|
|
237
|
-
"1", client, json_headers
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
loan_end_date = arrow.utcnow() + timedelta(days=15)
|
|
241
|
-
end_date = loan_end_date.date().isoformat()
|
|
242
|
-
data = dict(loan_end_date=end_date)
|
|
243
|
-
|
|
244
|
-
user_login(client, "librarian", users)
|
|
245
|
-
# accept extension
|
|
246
|
-
res = _accept_extension_action(brwreq_pid, data, client, json_headers)
|
|
247
|
-
assert res.status_code == 200
|
|
248
|
-
|
|
249
|
-
patron_loan = res.get_json()["metadata"]["patron_loan"]
|
|
250
|
-
assert patron_loan["loan"]["state"] == "ITEM_ON_LOAN"
|
|
251
|
-
assert patron_loan["loan"]["extension_count"] == 1
|
|
252
|
-
assert patron_loan["loan"]["end_date"] == end_date
|
|
253
|
-
assert "status" not in patron_loan["extension"]
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
def test_brwreq_decline_extension_success(client, testdata, json_headers, users):
|
|
257
|
-
"""Test declone extension success."""
|
|
258
|
-
user_login(client, "librarian", users)
|
|
259
|
-
|
|
260
|
-
# create request
|
|
261
|
-
brwreq, brwreq_pid = _create_on_loan_brwreq_with_pending_extension(
|
|
262
|
-
"1", client, json_headers
|
|
263
|
-
)
|
|
264
|
-
end_date = brwreq["patron_loan"]["loan"]["end_date"]
|
|
265
|
-
|
|
266
|
-
user_login(client, "librarian", users)
|
|
267
|
-
# decline extension
|
|
268
|
-
res = _decline_extension_action(brwreq_pid, dict(), client, json_headers)
|
|
269
|
-
assert res.status_code == 200
|
|
270
|
-
|
|
271
|
-
patron_loan = res.get_json()["metadata"]["patron_loan"]
|
|
272
|
-
assert patron_loan["loan"]["state"] == "ITEM_ON_LOAN"
|
|
273
|
-
assert "extension_count" not in patron_loan["loan"]
|
|
274
|
-
assert patron_loan["loan"]["end_date"] == end_date
|
|
275
|
-
assert patron_loan["extension"]["status"] == "DECLINED"
|
|
276
|
-
|
|
277
|
-
# request again should now fail because it has been declined
|
|
278
|
-
user_login(client, "patron1", users)
|
|
279
|
-
res = _request_extension_action(brwreq_pid, client, json_headers)
|
|
280
|
-
assert res.status_code == 400
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
#
|
|
3
|
-
# Copyright (C) 2020 CERN.
|
|
4
|
-
#
|
|
5
|
-
# invenio-app-ils is free software; you can redistribute it and/or modify it
|
|
6
|
-
# under the terms of the MIT License; see LICENSE file for more details.
|
|
7
|
-
|
|
8
|
-
"""Test ILL borrowing requests."""
|
|
9
|
-
|
|
10
|
-
import json
|
|
11
|
-
|
|
12
|
-
from flask import url_for
|
|
13
|
-
from invenio_search import current_search
|
|
14
|
-
|
|
15
|
-
from tests.helpers import user_login
|
|
16
|
-
|
|
17
|
-
_HTTP_OK = [200, 201, 204]
|
|
18
|
-
BRWREQ_PID = "illbid-1"
|
|
19
|
-
ITEM_ENDPOINT = "invenio_records_rest.illbid_item"
|
|
20
|
-
LIST_ENDPOINT = "invenio_records_rest.illbid_list"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def test_ill_brwreqs_list_permissions(client, testdata, json_headers, users):
|
|
24
|
-
"""Test borrowing requests list permissions."""
|
|
25
|
-
patron1_brwreq = dict(
|
|
26
|
-
status="PENDING",
|
|
27
|
-
document_pid="docid-1",
|
|
28
|
-
patron_pid="1",
|
|
29
|
-
provider_pid="ill-provid-1",
|
|
30
|
-
type="PHYSICAL_COPY",
|
|
31
|
-
)
|
|
32
|
-
patron2_brwreq = dict(
|
|
33
|
-
status="PENDING",
|
|
34
|
-
document_pid="docid-1",
|
|
35
|
-
patron_pid="2",
|
|
36
|
-
provider_pid="ill-provid-1",
|
|
37
|
-
type="PHYSICAL_COPY",
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
def _test_list(expected_status, pids):
|
|
41
|
-
"""Test get list for given pids."""
|
|
42
|
-
q = " OR ".join(["pid:{}".format(pid) for pid in pids])
|
|
43
|
-
list_url = url_for(LIST_ENDPOINT, q=q)
|
|
44
|
-
res = client.get(list_url, headers=json_headers)
|
|
45
|
-
assert res.status_code in expected_status
|
|
46
|
-
return res.get_json()
|
|
47
|
-
|
|
48
|
-
# create records
|
|
49
|
-
list_url = url_for(LIST_ENDPOINT)
|
|
50
|
-
user_login(client, "admin", users)
|
|
51
|
-
res = client.post(list_url, headers=json_headers, data=json.dumps(patron1_brwreq))
|
|
52
|
-
patron1_brwreq_pid = res.get_json()["metadata"]["pid"]
|
|
53
|
-
|
|
54
|
-
res = client.post(list_url, headers=json_headers, data=json.dumps(patron2_brwreq))
|
|
55
|
-
patron2_brwreq_pid = res.get_json()["metadata"]["pid"]
|
|
56
|
-
all_pids = [patron1_brwreq_pid, patron2_brwreq_pid]
|
|
57
|
-
# wait for ES
|
|
58
|
-
current_search.flush_and_refresh(index="ill_borrowing_requests")
|
|
59
|
-
|
|
60
|
-
# test results
|
|
61
|
-
tests = [
|
|
62
|
-
("admin", _HTTP_OK, all_pids),
|
|
63
|
-
("librarian", _HTTP_OK, all_pids),
|
|
64
|
-
("patron1", _HTTP_OK, [patron1_brwreq_pid]),
|
|
65
|
-
("patron2", _HTTP_OK, [patron2_brwreq_pid]),
|
|
66
|
-
]
|
|
67
|
-
for username, expected_status, expected_pids in tests:
|
|
68
|
-
user_login(client, username, users)
|
|
69
|
-
results = _test_list(expected_status, all_pids)
|
|
70
|
-
assert results["hits"]["total"] == len(expected_pids)
|
|
71
|
-
found_pids = [hit["metadata"]["pid"] for hit in results["hits"]["hits"]]
|
|
72
|
-
assert set(expected_pids) == set(found_pids)
|
|
73
|
-
|
|
74
|
-
# anonymous
|
|
75
|
-
user_login(client, "anonymous", users)
|
|
76
|
-
_test_list([401], [])
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def test_ill_brwreq_details_permissions(client, testdata, json_headers, users):
|
|
80
|
-
"""Test borrowing requests details permissions."""
|
|
81
|
-
dummy_borrowing_request = dict(
|
|
82
|
-
status="PENDING",
|
|
83
|
-
document_pid="docid-1",
|
|
84
|
-
patron_pid="1",
|
|
85
|
-
provider_pid="ill-provid-1",
|
|
86
|
-
type="PHYSICAL_COPY",
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
def _test_create(expected_status, data, user):
|
|
90
|
-
"""Test record creation."""
|
|
91
|
-
url = url_for(LIST_ENDPOINT)
|
|
92
|
-
res = client.post(url, headers=json_headers, data=json.dumps(data))
|
|
93
|
-
assert res.status_code in expected_status
|
|
94
|
-
|
|
95
|
-
if res.status_code < 400:
|
|
96
|
-
brw_req = res.get_json()["metadata"]
|
|
97
|
-
assert brw_req["status"] == "PENDING"
|
|
98
|
-
expected_created_by = dict(type="user_id", value=str(user.id))
|
|
99
|
-
assert brw_req["created_by"] == expected_created_by
|
|
100
|
-
assert not brw_req.get("updated_by")
|
|
101
|
-
return brw_req["pid"]
|
|
102
|
-
|
|
103
|
-
def _test_update(expected_status, data, pid, user):
|
|
104
|
-
"""Test record update."""
|
|
105
|
-
pid_value = pid or BRWREQ_PID
|
|
106
|
-
url = url_for(ITEM_ENDPOINT, pid_value=pid_value)
|
|
107
|
-
res = client.put(url, headers=json_headers, data=json.dumps(data))
|
|
108
|
-
assert res.status_code in expected_status
|
|
109
|
-
if res.status_code < 400:
|
|
110
|
-
expected_changed_by = dict(type="user_id", value=str(user.id))
|
|
111
|
-
brw_req = res.get_json()["metadata"]
|
|
112
|
-
assert brw_req["created_by"] == expected_changed_by
|
|
113
|
-
assert brw_req["updated_by"] == expected_changed_by
|
|
114
|
-
|
|
115
|
-
def _test_read(expected_status, pid):
|
|
116
|
-
"""Test record read."""
|
|
117
|
-
pid_value = pid or BRWREQ_PID
|
|
118
|
-
url = url_for(ITEM_ENDPOINT, pid_value=pid_value)
|
|
119
|
-
res = client.get(url, headers=json_headers)
|
|
120
|
-
assert res.status_code in expected_status
|
|
121
|
-
|
|
122
|
-
def _test_delete(expected_status, pid):
|
|
123
|
-
"""Test record delete."""
|
|
124
|
-
url = url_for(ITEM_ENDPOINT, pid_value=pid)
|
|
125
|
-
res = client.delete(url, headers=json_headers)
|
|
126
|
-
assert res.status_code in expected_status
|
|
127
|
-
|
|
128
|
-
# create/update
|
|
129
|
-
tests = [
|
|
130
|
-
("anonymous", [401], dummy_borrowing_request),
|
|
131
|
-
("patron2", [403], dummy_borrowing_request),
|
|
132
|
-
("patron1", [403], dummy_borrowing_request),
|
|
133
|
-
("librarian", _HTTP_OK, dummy_borrowing_request),
|
|
134
|
-
("admin", _HTTP_OK, dummy_borrowing_request),
|
|
135
|
-
]
|
|
136
|
-
for username, expected_status, data in tests:
|
|
137
|
-
user = user_login(client, username, users)
|
|
138
|
-
pid = _test_create(expected_status, data, user)
|
|
139
|
-
_test_update(expected_status, data, pid, user)
|
|
140
|
-
|
|
141
|
-
# get
|
|
142
|
-
tests = [
|
|
143
|
-
("anonymous", [401]),
|
|
144
|
-
("patron2", [403]),
|
|
145
|
-
("patron1", _HTTP_OK),
|
|
146
|
-
("librarian", _HTTP_OK),
|
|
147
|
-
("admin", _HTTP_OK),
|
|
148
|
-
]
|
|
149
|
-
for username, expected_status in tests:
|
|
150
|
-
user_login(client, username, users)
|
|
151
|
-
_test_read(expected_status, BRWREQ_PID)
|
|
152
|
-
|
|
153
|
-
# delete
|
|
154
|
-
tests = [
|
|
155
|
-
("anonymous", [401]),
|
|
156
|
-
("patron2", [403]),
|
|
157
|
-
("patron1", [403]),
|
|
158
|
-
("librarian", [403]),
|
|
159
|
-
("admin", _HTTP_OK),
|
|
160
|
-
]
|
|
161
|
-
for username, expected_status in tests:
|
|
162
|
-
user_login(client, username, users)
|
|
163
|
-
_test_delete(expected_status, BRWREQ_PID)
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
#
|
|
3
|
-
# Copyright (C) 2020 CERN.
|
|
4
|
-
#
|
|
5
|
-
# invenio-app-ils is free software; you can redistribute it and/or modify it
|
|
6
|
-
# under the terms of the MIT License; see LICENSE file for more details.
|
|
7
|
-
|
|
8
|
-
"""Test ILL providers."""
|
|
9
|
-
|
|
10
|
-
import json
|
|
11
|
-
|
|
12
|
-
from flask import url_for
|
|
13
|
-
|
|
14
|
-
from tests.helpers import user_login
|
|
15
|
-
|
|
16
|
-
_HTTP_OK = [200, 201, 204]
|
|
17
|
-
PROVIDER_PID = "ill-provid-1"
|
|
18
|
-
PROVIDER_NAME = "A library"
|
|
19
|
-
PROVIDER_TYPE = "LIBRARY"
|
|
20
|
-
ITEM_ENDPOINT = "invenio_records_rest.provid_item"
|
|
21
|
-
LIST_ENDPOINT = "invenio_records_rest.provid_list"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def test_ill_providers_permissions(client, testdata, json_headers, users):
|
|
25
|
-
"""Test providers endpoints permissions."""
|
|
26
|
-
dummy_provider = dict(name=PROVIDER_NAME, type=PROVIDER_TYPE)
|
|
27
|
-
tests = [
|
|
28
|
-
("admin", _HTTP_OK, dummy_provider),
|
|
29
|
-
("librarian", _HTTP_OK, dummy_provider),
|
|
30
|
-
("patron1", [403], dummy_provider),
|
|
31
|
-
("anonymous", [401], dummy_provider),
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
def _test_list(expected_status):
|
|
35
|
-
"""Test get list."""
|
|
36
|
-
url = url_for(LIST_ENDPOINT)
|
|
37
|
-
res = client.get(url, headers=json_headers)
|
|
38
|
-
assert res.status_code in expected_status
|
|
39
|
-
|
|
40
|
-
def _test_create(expected_status, data):
|
|
41
|
-
"""Test record creation."""
|
|
42
|
-
url = url_for(LIST_ENDPOINT)
|
|
43
|
-
res = client.post(url, headers=json_headers, data=json.dumps(data))
|
|
44
|
-
assert res.status_code in expected_status
|
|
45
|
-
|
|
46
|
-
if res.status_code < 400:
|
|
47
|
-
record = res.get_json()["metadata"]
|
|
48
|
-
assert record["name"] == PROVIDER_NAME
|
|
49
|
-
assert record["type"] == PROVIDER_TYPE
|
|
50
|
-
return record["pid"]
|
|
51
|
-
|
|
52
|
-
def _test_update(expected_status, data, pid):
|
|
53
|
-
"""Test record update."""
|
|
54
|
-
pid_value = pid or PROVIDER_PID
|
|
55
|
-
url = url_for(ITEM_ENDPOINT, pid_value=pid_value)
|
|
56
|
-
res = client.put(url, headers=json_headers, data=json.dumps(data))
|
|
57
|
-
assert res.status_code in expected_status
|
|
58
|
-
if res.status_code < 400:
|
|
59
|
-
record = res.get_json()["metadata"]
|
|
60
|
-
assert record["name"] == PROVIDER_NAME
|
|
61
|
-
|
|
62
|
-
def _test_read(expected_status, pid):
|
|
63
|
-
"""Test record read."""
|
|
64
|
-
pid_value = pid or PROVIDER_PID
|
|
65
|
-
url = url_for(ITEM_ENDPOINT, pid_value=pid_value)
|
|
66
|
-
res = client.get(url, headers=json_headers)
|
|
67
|
-
assert res.status_code in expected_status
|
|
68
|
-
|
|
69
|
-
def _test_delete(expected_status, pid):
|
|
70
|
-
"""Test record delete."""
|
|
71
|
-
pid_value = pid or PROVIDER_PID
|
|
72
|
-
url = url_for(ITEM_ENDPOINT, pid_value=pid_value)
|
|
73
|
-
res = client.delete(url, headers=json_headers)
|
|
74
|
-
assert res.status_code in expected_status
|
|
75
|
-
|
|
76
|
-
for username, expected_status, data in tests:
|
|
77
|
-
user_login(client, username, users)
|
|
78
|
-
_test_list(expected_status)
|
|
79
|
-
pid = _test_create(expected_status, data)
|
|
80
|
-
_test_update(expected_status, data, pid)
|
|
81
|
-
_test_read(expected_status, pid)
|
|
82
|
-
_test_delete(expected_status, pid)
|
tests/api/ils/__init__.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
#
|
|
3
|
-
# Copyright (C) 2020 CERN.
|
|
4
|
-
#
|
|
5
|
-
# Invenio-Circulation is free software; you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the MIT License; see LICENSE file for more details.
|
|
7
|
-
|
|
8
|
-
"""Tests documents CRUD."""
|
|
9
|
-
|
|
10
|
-
from invenio_app_ils.documents.api import Document
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def _assert_extra_fields(doc):
|
|
14
|
-
"""Test that extra fields are automatically added."""
|
|
15
|
-
assert "$schema" in doc
|
|
16
|
-
assert "circulation" in doc and "$ref" in doc["circulation"]
|
|
17
|
-
assert "relations" in doc and "$ref" in doc["relations"]
|
|
18
|
-
assert "eitems" in doc and "$ref" in doc["eitems"]
|
|
19
|
-
assert "items" in doc and "$ref" in doc["items"]
|
|
20
|
-
assert "stock" in doc and "$ref" in doc["stock"]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def test_document_creation_refs(app):
|
|
24
|
-
"""Test creation of a document."""
|
|
25
|
-
d = dict(
|
|
26
|
-
pid="a1bc",
|
|
27
|
-
created_by={"type": "script", "value": "demo"},
|
|
28
|
-
title="Test title",
|
|
29
|
-
authors=[dict(full_name="John Doe")],
|
|
30
|
-
publication_year="2010",
|
|
31
|
-
document_type="BOOK",
|
|
32
|
-
)
|
|
33
|
-
doc = Document.create(d)
|
|
34
|
-
|
|
35
|
-
_assert_extra_fields(doc)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def test_document_update_refs(app):
|
|
39
|
-
"""Test update of a document."""
|
|
40
|
-
d = dict(
|
|
41
|
-
pid="a1bc",
|
|
42
|
-
title="Test title",
|
|
43
|
-
created_by={"type": "script", "value": "demo"},
|
|
44
|
-
authors=[dict(full_name="John Doe")],
|
|
45
|
-
publication_year="2010",
|
|
46
|
-
document_type="BOOK",
|
|
47
|
-
)
|
|
48
|
-
doc = Document.create(d)
|
|
49
|
-
del doc["circulation"]
|
|
50
|
-
del doc["relations"]
|
|
51
|
-
del doc["eitems"]
|
|
52
|
-
del doc["items"]
|
|
53
|
-
del doc["stock"]
|
|
54
|
-
doc.update(dict(title="Test title 2"))
|
|
55
|
-
|
|
56
|
-
_assert_extra_fields(doc)
|
|
57
|
-
assert doc["title"] == "Test title 2"
|