throw error for missing permission_sets in PermissionSets.get_many

This commit is contained in:
dandds 2019-03-19 06:11:35 -04:00
parent 366ada5a90
commit 7c5e931c67
3 changed files with 13 additions and 4 deletions

View File

@ -32,12 +32,17 @@ class PermissionSets(object):
@classmethod
def get_many(cls, perms_set_names):
return (
permission_sets = (
db.session.query(PermissionSet)
.filter(PermissionSet.name.in_(perms_set_names))
.all()
)
if len(permission_sets) != len(perms_set_names):
raise NotFoundError("permission_set")
return permission_sets
ATAT_ROLES = [
{

View File

@ -30,3 +30,8 @@ def test_get_many():
assert first_or_none(
lambda p: p.name == PermissionSets.EDIT_PORTFOLIO_FUNDING, perms_sets
)
def test_get_many_nonexistent():
with pytest.raises(NotFoundError):
PermissionSets.get_many(["nonexistent", "not real"])

View File

@ -20,10 +20,9 @@ def test_create_user_with_existing_email():
Users.create(DOD_ID, email="thisusersemail@usersRus.com")
@pytest.mark.skip(reason="no more roles")
def test_create_user_with_nonexistent_role():
def test_create_user_with_nonexistent_permission_set():
with pytest.raises(NotFoundError):
Users.create(DOD_ID, "nonexistent")
Users.create(DOD_ID, permission_sets=["nonexistent"])
def test_get_or_create_nonexistent_user():