-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
permissions: evaluate per transition #26
Added support for custom permission factory per transition.
- Loading branch information
Showing
5 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2018 CERN. | ||
# Copyright (C) 2018 RERO. | ||
# | ||
# Invenio-Circulation is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
|
||
"""Test circulation permissions on transitions.""" | ||
|
||
import pytest | ||
from invenio_records_rest.utils import allow_all, deny_all | ||
|
||
from invenio_circulation.api import Loan | ||
from invenio_circulation.errors import InvalidCirculationPermission | ||
from invenio_circulation.transitions.transitions import CreatedToPending | ||
|
||
|
||
def test_valid_permission(loan_created, params): | ||
"""Test transition with valid permission.""" | ||
transition = CreatedToPending( | ||
'CREATED', 'PENDING', trigger='next', permission_factory=allow_all | ||
) | ||
transition.execute(loan_created, **params) | ||
assert loan_created['state'] == 'PENDING' | ||
|
||
|
||
def test_invalid_permission(loan_created, params): | ||
"""Test transition without permission.""" | ||
transition = CreatedToPending( | ||
'CREATED', 'PENDING', trigger='next', permission_factory=deny_all | ||
) | ||
with pytest.raises(InvalidCirculationPermission): | ||
transition.execute(loan_created, **params) | ||
assert loan_created['state'] == 'CREATED' |