1 changed files with 21 additions and 0 deletions
@ -1,5 +1,6 @@ |
|||||
import importlib |
import importlib |
||||
from types import ModuleType |
from types import ModuleType |
||||
|
from unittest.mock import patch |
||||
|
|
||||
import pytest |
import pytest |
||||
from fastapi.testclient import TestClient |
from fastapi.testclient import TestClient |
||||
@ -155,6 +156,26 @@ def test_token_nonexistent_user(mod: ModuleType): |
|||||
assert response.headers["WWW-Authenticate"] == "Bearer" |
assert response.headers["WWW-Authenticate"] == "Bearer" |
||||
|
|
||||
|
|
||||
|
def test_token_inactive_user(mod: ModuleType): |
||||
|
client = TestClient(mod.app) |
||||
|
alice_user_data = { |
||||
|
"username": "alice", |
||||
|
"full_name": "Alice Wonderson", |
||||
|
"email": "[email protected]", |
||||
|
"hashed_password": mod.get_password_hash("secretalice"), |
||||
|
"disabled": True, |
||||
|
} |
||||
|
with patch.dict(f"{mod.__name__}.fake_users_db", {"alice": alice_user_data}): |
||||
|
access_token = get_access_token( |
||||
|
username="alice", password="secretalice", client=client |
||||
|
) |
||||
|
response = client.get( |
||||
|
"/users/me", headers={"Authorization": f"Bearer {access_token}"} |
||||
|
) |
||||
|
assert response.status_code == 400, response.text |
||||
|
assert response.json() == {"detail": "Inactive user"} |
||||
|
|
||||
|
|
||||
def test_read_items(mod: ModuleType): |
def test_read_items(mod: ModuleType): |
||||
client = TestClient(mod.app) |
client = TestClient(mod.app) |
||||
access_token = get_access_token(client=client) |
access_token = get_access_token(client=client) |
||||
|
|||||
Loading…
Reference in new issue