-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Remove uses of the admin settings controller. * Convert discovery_services tests. * Fix up library settings tests * Fix up catalog services controller tests. * Replace admin controller fixture for TestAdminSearchController * Replace admin controller fixture for DiscoveryServiceLibraryRegistrationsController * Replace fixture for TestAdminPermissionsControllerMixin * Replace fixtures in DeviceTokensController tests.
- Loading branch information
1 parent
082bc77
commit 178f69c
Showing
12 changed files
with
497 additions
and
386 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,83 @@ | ||
import pytest | ||
|
||
from api.admin.controller.base import AdminPermissionsControllerMixin | ||
from api.admin.exceptions import AdminNotAuthorized | ||
from core.model import AdminRole | ||
from tests.fixtures.api_admin import AdminControllerFixture | ||
from tests.fixtures.database import DatabaseTransactionFixture | ||
from tests.fixtures.flask import FlaskAppFixture | ||
|
||
|
||
@pytest.fixture() | ||
def controller() -> AdminPermissionsControllerMixin: | ||
return AdminPermissionsControllerMixin() | ||
|
||
|
||
class TestAdminPermissionsControllerMixin: | ||
def test_require_system_admin(self, admin_ctrl_fixture: AdminControllerFixture): | ||
with admin_ctrl_fixture.request_context_with_admin("/admin"): | ||
def test_require_system_admin( | ||
self, | ||
controller: AdminPermissionsControllerMixin, | ||
flask_app_fixture: FlaskAppFixture, | ||
): | ||
with flask_app_fixture.test_request_context("/admin"): | ||
pytest.raises( | ||
AdminNotAuthorized, | ||
admin_ctrl_fixture.manager.admin_work_controller.require_system_admin, | ||
controller.require_system_admin, | ||
) | ||
|
||
admin_ctrl_fixture.admin.add_role(AdminRole.SYSTEM_ADMIN) | ||
admin_ctrl_fixture.manager.admin_work_controller.require_system_admin() | ||
with flask_app_fixture.test_request_context_system_admin("/admin"): | ||
controller.require_system_admin() | ||
|
||
def test_require_sitewide_library_manager( | ||
self, admin_ctrl_fixture: AdminControllerFixture | ||
self, | ||
controller: AdminPermissionsControllerMixin, | ||
flask_app_fixture: FlaskAppFixture, | ||
): | ||
with admin_ctrl_fixture.request_context_with_admin("/admin"): | ||
with flask_app_fixture.test_request_context("/admin"): | ||
pytest.raises( | ||
AdminNotAuthorized, | ||
admin_ctrl_fixture.manager.admin_work_controller.require_sitewide_library_manager, | ||
controller.require_sitewide_library_manager, | ||
) | ||
|
||
admin_ctrl_fixture.admin.add_role(AdminRole.SITEWIDE_LIBRARY_MANAGER) | ||
admin_ctrl_fixture.manager.admin_work_controller.require_sitewide_library_manager() | ||
library_manager = flask_app_fixture.admin_user( | ||
role=AdminRole.SITEWIDE_LIBRARY_MANAGER | ||
) | ||
with flask_app_fixture.test_request_context("/admin", admin=library_manager): | ||
controller.require_sitewide_library_manager() | ||
|
||
def test_require_library_manager(self, admin_ctrl_fixture: AdminControllerFixture): | ||
with admin_ctrl_fixture.request_context_with_admin("/admin"): | ||
def test_require_library_manager( | ||
self, | ||
controller: AdminPermissionsControllerMixin, | ||
flask_app_fixture: FlaskAppFixture, | ||
db: DatabaseTransactionFixture, | ||
): | ||
with flask_app_fixture.test_request_context("/admin"): | ||
pytest.raises( | ||
AdminNotAuthorized, | ||
admin_ctrl_fixture.manager.admin_work_controller.require_library_manager, | ||
admin_ctrl_fixture.ctrl.db.default_library(), | ||
controller.require_library_manager, | ||
db.default_library(), | ||
) | ||
|
||
admin_ctrl_fixture.admin.add_role( | ||
AdminRole.LIBRARY_MANAGER, admin_ctrl_fixture.ctrl.db.default_library() | ||
) | ||
admin_ctrl_fixture.manager.admin_work_controller.require_library_manager( | ||
admin_ctrl_fixture.ctrl.db.default_library() | ||
) | ||
library_manager = flask_app_fixture.admin_user( | ||
role=AdminRole.LIBRARY_MANAGER, library=db.default_library() | ||
) | ||
with flask_app_fixture.test_request_context("/admin", admin=library_manager): | ||
controller.require_library_manager(db.default_library()) | ||
|
||
def test_require_librarian(self, admin_ctrl_fixture: AdminControllerFixture): | ||
with admin_ctrl_fixture.request_context_with_admin("/admin"): | ||
def test_require_librarian( | ||
self, | ||
controller: AdminPermissionsControllerMixin, | ||
flask_app_fixture: FlaskAppFixture, | ||
db: DatabaseTransactionFixture, | ||
): | ||
with flask_app_fixture.test_request_context("/admin"): | ||
pytest.raises( | ||
AdminNotAuthorized, | ||
admin_ctrl_fixture.manager.admin_work_controller.require_librarian, | ||
admin_ctrl_fixture.ctrl.db.default_library(), | ||
controller.require_librarian, | ||
db.default_library(), | ||
) | ||
|
||
admin_ctrl_fixture.admin.add_role( | ||
AdminRole.LIBRARIAN, admin_ctrl_fixture.ctrl.db.default_library() | ||
) | ||
admin_ctrl_fixture.manager.admin_work_controller.require_librarian( | ||
admin_ctrl_fixture.ctrl.db.default_library() | ||
) | ||
librarian = flask_app_fixture.admin_user( | ||
role=AdminRole.LIBRARIAN, library=db.default_library() | ||
) | ||
with flask_app_fixture.test_request_context("/admin", admin=librarian): | ||
controller.require_librarian(db.default_library()) |
Oops, something went wrong.