implement PermissionSets.get_many for getting multiple permission sets by name
This commit is contained in:
32
tests/domain/test_permission_sets.py
Normal file
32
tests/domain/test_permission_sets.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import pytest
|
||||
from atst.domain.permission_sets import PermissionSets
|
||||
from atst.domain.exceptions import NotFoundError
|
||||
from atst.utils import first_or_none
|
||||
|
||||
|
||||
def test_get_all():
|
||||
roles = PermissionSets.get_all()
|
||||
assert roles
|
||||
|
||||
|
||||
def test_get_existing_permission_set():
|
||||
role = PermissionSets.get("portfolio_poc")
|
||||
assert role.name == "portfolio_poc"
|
||||
|
||||
|
||||
def test_get_nonexistent_permission_set():
|
||||
with pytest.raises(NotFoundError):
|
||||
PermissionSets.get("nonexistent")
|
||||
|
||||
|
||||
def test_get_many():
|
||||
perms_sets = PermissionSets.get_many(
|
||||
[PermissionSets.VIEW_PORTFOLIO_FUNDING, PermissionSets.EDIT_PORTFOLIO_FUNDING]
|
||||
)
|
||||
assert len(perms_sets) == 2
|
||||
assert first_or_none(
|
||||
lambda p: p.name == PermissionSets.VIEW_PORTFOLIO_FUNDING, perms_sets
|
||||
)
|
||||
assert first_or_none(
|
||||
lambda p: p.name == PermissionSets.EDIT_PORTFOLIO_FUNDING, perms_sets
|
||||
)
|
@@ -18,13 +18,14 @@ def test_add_portfolio_role_with_permission_sets():
|
||||
port_role = PortfolioRoles.add(
|
||||
new_user, portfolio.id, permission_sets=permission_sets
|
||||
)
|
||||
assert len(port_role.permission_sets) == 5
|
||||
assert len(port_role.permission_sets) == 6
|
||||
expected_names = [
|
||||
PermissionSets.EDIT_PORTFOLIO_APPLICATION_MANAGEMENT,
|
||||
PermissionSets.VIEW_PORTFOLIO_APPLICATION_MANAGEMENT,
|
||||
PermissionSets.VIEW_PORTFOLIO_FUNDING,
|
||||
PermissionSets.VIEW_PORTFOLIO_REPORTS,
|
||||
PermissionSets.VIEW_PORTFOLIO_ADMIN,
|
||||
PermissionSets.VIEW_PORTFOLIO,
|
||||
]
|
||||
actual_names = [prms.name for prms in port_role.permission_sets]
|
||||
assert expected_names == expected_names
|
||||
|
@@ -9,7 +9,12 @@ from atst.domain.environments import Environments
|
||||
from atst.domain.permission_sets import PermissionSets, PORTFOLIO_PERMISSION_SETS
|
||||
from atst.models.portfolio_role import Status as PortfolioRoleStatus
|
||||
|
||||
from tests.factories import UserFactory, PortfolioRoleFactory, PortfolioFactory
|
||||
from tests.factories import (
|
||||
UserFactory,
|
||||
PortfolioRoleFactory,
|
||||
PortfolioFactory,
|
||||
get_all_portfolio_permission_sets,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@@ -201,7 +206,7 @@ def test_scoped_portfolio_returns_all_applications_for_portfolio_admin(
|
||||
)
|
||||
|
||||
admin = UserFactory.create()
|
||||
perm_sets = [PermissionSets.get(prms["name"]) for prms in PORTFOLIO_PERMISSION_SETS]
|
||||
perm_sets = get_all_portfolio_permission_sets()
|
||||
PortfolioRoleFactory.create(
|
||||
user=admin, portfolio=portfolio, permission_sets=perm_sets
|
||||
)
|
||||
@@ -263,7 +268,7 @@ def test_get_for_update_information(portfolio, portfolio_owner):
|
||||
assert portfolio == owner_ws
|
||||
|
||||
admin = UserFactory.create()
|
||||
perm_sets = [PermissionSets.get(prms["name"]) for prms in PORTFOLIO_PERMISSION_SETS]
|
||||
perm_sets = get_all_portfolio_permission_sets()
|
||||
PortfolioRoleFactory.create(
|
||||
user=admin, portfolio=portfolio, permission_sets=perm_sets
|
||||
)
|
||||
|
@@ -1,18 +0,0 @@
|
||||
import pytest
|
||||
from atst.domain.permission_sets import PermissionSets
|
||||
from atst.domain.exceptions import NotFoundError
|
||||
|
||||
|
||||
def test_get_all_roles():
|
||||
roles = PermissionSets.get_all()
|
||||
assert roles
|
||||
|
||||
|
||||
def test_get_existing_role():
|
||||
role = PermissionSets.get("portfolio_poc")
|
||||
assert role.name == "portfolio_poc"
|
||||
|
||||
|
||||
def test_get_nonexistent_role():
|
||||
with pytest.raises(NotFoundError):
|
||||
PermissionSets.get("nonexistent")
|
Reference in New Issue
Block a user