-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to test_login and test_items
- Loading branch information
Showing
6 changed files
with
82 additions
and
5 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
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
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 |
---|---|---|
|
@@ -5,7 +5,9 @@ | |
|
||
from app.core.config import settings | ||
from app.core.security import verify_password | ||
from app.models import User | ||
from app.crud import update_user | ||
from app.models import User, UserUpdate | ||
from app.tests.utils.user import create_user | ||
from app.utils import generate_password_reset_token | ||
|
||
|
||
|
@@ -21,6 +23,20 @@ def test_get_access_token(client: TestClient) -> None: | |
assert tokens["access_token"] | ||
|
||
|
||
def test_get_access_token_inactive_user(client: TestClient, db: Session) -> None: | ||
password = "secretpassword" | ||
user = create_user(db, password=password) | ||
update_user(session=db, db_user=user, user_in=UserUpdate(is_active=False)) | ||
|
||
login_data = { | ||
"username": user.email, | ||
"password": password, | ||
} | ||
r = client.post(f"{settings.API_V1_STR}/login/access-token", data=login_data) | ||
assert r.status_code == 400 | ||
assert r.json() == {"detail": "Inactive user"} | ||
|
||
|
||
def test_get_access_token_incorrect_password(client: TestClient) -> None: | ||
login_data = { | ||
"username": settings.FIRST_SUPERUSER, | ||
|
@@ -88,6 +104,39 @@ def test_reset_password( | |
assert verify_password(data["new_password"], user.hashed_password) | ||
|
||
|
||
def test_reset_password_no_such_user_email( | ||
client: TestClient, superuser_token_headers: dict[str, str], db: Session | ||
) -> None: | ||
token = generate_password_reset_token(email="[email protected]") | ||
data = {"new_password": "changethis", "token": token} | ||
r = client.post( | ||
f"{settings.API_V1_STR}/reset-password/", | ||
headers=superuser_token_headers, | ||
json=data, | ||
) | ||
assert r.status_code == 404 | ||
assert r.json() == { | ||
"detail": "The user with this email does not exist in the system." | ||
} | ||
|
||
|
||
def test_reset_password_inactive_user( | ||
client: TestClient, superuser_token_headers: dict[str, str], db: Session | ||
) -> None: | ||
email = "[email protected]" | ||
user = create_user(db, email=email) | ||
update_user(session=db, db_user=user, user_in=UserUpdate(is_active=False)) | ||
token = generate_password_reset_token(email=email) | ||
data = {"new_password": "changethis", "token": token} | ||
r = client.post( | ||
f"{settings.API_V1_STR}/reset-password/", | ||
headers=superuser_token_headers, | ||
json=data, | ||
) | ||
assert r.status_code == 400 | ||
assert r.json() == {"detail": "Inactive user"} | ||
|
||
|
||
def test_reset_password_invalid_token( | ||
client: TestClient, superuser_token_headers: dict[str, str] | ||
) -> None: | ||
|
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
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
Empty file.