Skip to content

Commit

Permalink
tests: add tests for read-only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
max-moser committed Nov 15, 2022
1 parent 91791aa commit 9a72301
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/services/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2020-2021 CERN.
# Copyright (C) 2022 TU Wien.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand All @@ -13,6 +14,7 @@
import pytest
from invenio_cache import current_cache
from invenio_pidstore.errors import PIDAlreadyExists, PIDDeletedError
from invenio_records_resources.services.errors import PermissionDeniedError
from marshmallow.exceptions import ValidationError
from sqlalchemy.exc import IntegrityError

Expand Down Expand Up @@ -181,3 +183,44 @@ def test_indexed_at_query(app, db, service, identity, lang_type, lang_data):
type="languages",
)
assert res.total == 1


#
# Read-only mode
#


def test_create_ro(app, service, identity, lang_type, lang_data):
"""Try to create a vocabulary in read-only mode."""
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True

pytest.raises(PermissionDeniedError, service.create, identity, lang_data)


def test_update_ro(app, service, identity, lang_type, lang_data):
"""Try to update a vocabulary in read-only mode."""
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = False
item = service.create(identity, lang_data)

app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True
pytest.raises(
PermissionDeniedError, service.update, identity, ("languages", "eng"), lang_data
)


def test_delete_ro(app, service, identity, lang_type, lang_data):
"""Try to delete a vocabulary in read-only mode."""
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = False
item = service.create(identity, lang_data)

app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True
pytest.raises(PermissionDeniedError, service.delete, identity, ("languages", "eng"))


def test_create_type_ro(app, service, identity):
"""Try to create a vocabulary type in read-only mode."""
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True

pytest.raises(
PermissionDeniedError, service.create_type, identity, "newtype", "new"
)

0 comments on commit 9a72301

Please sign in to comment.