|
2 | 2 | # |
3 | 3 | # This file is part of Invenio. |
4 | 4 | # Copyright (C) 2020-2021 CERN. |
| 5 | +# Copyright (C) 2022 TU Wien. |
5 | 6 | # |
6 | 7 | # Invenio-Vocabularies is free software; you can redistribute it and/or |
7 | 8 | # modify it under the terms of the MIT License; see LICENSE file for more |
|
13 | 14 | import pytest |
14 | 15 | from invenio_cache import current_cache |
15 | 16 | from invenio_pidstore.errors import PIDAlreadyExists, PIDDeletedError |
| 17 | +from invenio_records_resources.services.errors import PermissionDeniedError |
16 | 18 | from marshmallow.exceptions import ValidationError |
17 | 19 | from sqlalchemy.exc import IntegrityError |
18 | 20 |
|
@@ -181,3 +183,44 @@ def test_indexed_at_query(app, db, service, identity, lang_type, lang_data): |
181 | 183 | type="languages", |
182 | 184 | ) |
183 | 185 | 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