-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_auth.py
More file actions
21 lines (17 loc) · 800 Bytes
/
Copy pathtest_auth.py
File metadata and controls
21 lines (17 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pytest
from fastapi import HTTPException
from ubiblio.dependencies.auth import get_admin_user, get_user
from tests.helpers.create_test_user import create_test_user
class TestGetAdminUser:
def test_admin_user_is_returned(self):
with create_test_user(is_admin=True) as test_user:
user = get_user(test_user.username)
result = get_admin_user(user)
assert result is user
def test_non_admin_raises_403(self):
with create_test_user(is_admin=False) as test_user:
user = get_user(test_user.username)
with pytest.raises(HTTPException) as exc_info:
get_admin_user(user)
assert exc_info.value.status_code == 403
assert exc_info.value.detail == "Only an admin can perform this action."