Skip to content

Commit 83d308d

Browse files
committed
tests: add tests for read-only mode
* the tests use the service rather than the resource because there are no write operations for vocabularies exposed in the REST API
1 parent 4c32868 commit 83d308d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/services/test_service.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# This file is part of Invenio.
44
# Copyright (C) 2020-2021 CERN.
5+
# Copyright (C) 2022 TU Wien.
56
#
67
# Invenio-Vocabularies is free software; you can redistribute it and/or
78
# modify it under the terms of the MIT License; see LICENSE file for more
@@ -13,6 +14,7 @@
1314
import pytest
1415
from invenio_cache import current_cache
1516
from invenio_pidstore.errors import PIDAlreadyExists, PIDDeletedError
17+
from invenio_records_resources.services.errors import PermissionDeniedError
1618
from marshmallow.exceptions import ValidationError
1719
from sqlalchemy.exc import IntegrityError
1820

@@ -181,3 +183,44 @@ def test_indexed_at_query(app, db, service, identity, lang_type, lang_data):
181183
type="languages",
182184
)
183185
assert res.total == 1
186+
187+
188+
#
189+
# Read-only mode
190+
#
191+
192+
193+
def test_create_ro(app, service, identity, lang_type, lang_data):
194+
"""Try to create a vocabulary in read-only mode."""
195+
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True
196+
197+
pytest.raises(PermissionDeniedError, service.create, identity, lang_data)
198+
199+
200+
def test_update_ro(app, service, identity, lang_type, lang_data):
201+
"""Try to update a vocabulary in read-only mode."""
202+
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = False
203+
item = service.create(identity, lang_data)
204+
205+
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True
206+
pytest.raises(
207+
PermissionDeniedError, service.update, identity, ("languages", "eng"), lang_data
208+
)
209+
210+
211+
def test_delete_ro(app, service, identity, lang_type, lang_data):
212+
"""Try to delete a vocabulary in read-only mode."""
213+
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = False
214+
item = service.create(identity, lang_data)
215+
216+
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True
217+
pytest.raises(PermissionDeniedError, service.delete, identity, ("languages", "eng"))
218+
219+
220+
def test_create_type_ro(app, service, identity):
221+
"""Try to create a vocabulary type in read-only mode."""
222+
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True
223+
224+
pytest.raises(
225+
PermissionDeniedError, service.create_type, identity, "newtype", "new"
226+
)

0 commit comments

Comments
 (0)