-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove a loop in checking if a user is an admin
- Loading branch information
Showing
2 changed files
with
58 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
55 changes: 55 additions & 0 deletions
55
validation_service_api/validation_service/tests/test_user.py
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,55 @@ | ||
""" | ||
Tests of the User class | ||
Note: These will fail if the test user's permissions are too elevated. | ||
""" | ||
|
||
import os | ||
|
||
from fastapi.security import HTTPAuthorizationCredentials | ||
import pytest | ||
|
||
from ..auth import User | ||
|
||
|
||
token = HTTPAuthorizationCredentials( | ||
credentials=os.environ["VF_TEST_TOKEN"], scheme="Bearer" | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user__is_admin(): | ||
user = User(token, allow_anonymous=False) | ||
is_admin = await user.is_admin() | ||
assert not is_admin | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_user_info(): | ||
user = User(token, allow_anonymous=False) | ||
user_info = await user.get_user_info() | ||
assert "collab-model-validation-administrator" not in user_info["roles"]["team"] | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_collab_permissions(): | ||
user = User(token, allow_anonymous=False) | ||
permissions = await user.get_collab_permissions("model-validation") | ||
assert permissions == { | ||
"UPDATE": False, | ||
"VIEW": True, | ||
} | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_can_view_collab(): | ||
user = User(token, allow_anonymous=False) | ||
can_view = await user.can_view_collab("model-validation") | ||
assert can_view | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_can_edit_collab(): | ||
user = User(token, allow_anonymous=False) | ||
can_edit = await user.can_edit_collab("model-validation") | ||
assert not can_edit |