Skip to content

Commit a6c3afa

Browse files
committed
tests: add tests for the conditional disable generators
1 parent 7782fde commit a6c3afa

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tests/test_generators.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#
33
# Copyright (C) 2019 CERN.
44
# Copyright (C) 2019 Northwestern University.
5-
# Copyright (C) 2023 Graz University of Technology
5+
# Copyright (C) 2023 Graz University of Technology.
6+
# Copyright (C) 2024 TU Wien.
67
#
78
# Invenio-Records-Permissions is free software; you can redistribute it
89
# and/or modify it under the terms of the MIT License; see LICENSE file for
@@ -22,6 +23,7 @@
2223
AuthenticatedUser,
2324
ConditionalGenerator,
2425
Disable,
26+
DisableIfReadOnly,
2527
Generator,
2628
IfConfig,
2729
RecordOwners,
@@ -266,3 +268,18 @@ def test_ifconfig(app, create_record):
266268
UserNeed(2),
267269
UserNeed(3),
268270
}
271+
272+
273+
def test_disable_if_read_only(app):
274+
generator = DisableIfReadOnly()
275+
276+
# Normal operation
277+
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = False
278+
assert generator.excludes(record=None) == set()
279+
assert generator.query_filter(record=None) == []
280+
281+
# System is in read-only mode
282+
app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True
283+
assert generator.excludes(record=None) == {any_user}
284+
query_filter = generator.query_filter(record=None)
285+
assert query_filter.to_dict() == {"match_none": {}}

0 commit comments

Comments
 (0)