Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change get_user_by_email to be case insensetive #1450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/app/crud.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from typing import Any

from sqlmodel import Session, select
from sqlmodel import Session, func, select

from app.core.security import get_password_hash, verify_password
from app.models import Item, ItemCreate, User, UserCreate, UserUpdate
Expand Down Expand Up @@ -32,7 +32,7 @@ def update_user(*, session: Session, db_user: User, user_in: UserUpdate) -> Any:


def get_user_by_email(*, session: Session, email: str) -> User | None:
statement = select(User).where(User.email == email)
statement = select(User).where(func.lower(User.email) == func.lower(email))
session_user = session.exec(statement).first()
return session_user

Expand Down
24 changes: 24 additions & 0 deletions backend/app/tests/crud/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,27 @@ def test_update_user(db: Session) -> None:
assert user_2
assert user.email == user_2.email
assert verify_password(new_password, user_2.hashed_password)


def test_get_user_by_email(db: Session) -> None:
password = random_lower_string()
email = random_email()
user_in = UserCreate(email=email, password=password, is_superuser=True)
crud.create_user(session=db, user_create=user_in)
user = crud.get_user_by_email(session=db, email=email)
assert user
user_2 = db.get(User, user.id)
assert user_2
assert user.email == user_2.email


def test_get_user_by_email_case_insesetive(db: Session) -> None:
password = random_lower_string()
email = random_email().lower()
user_in = UserCreate(email=email, password=password, is_superuser=True)
crud.create_user(session=db, user_create=user_in)
user = crud.get_user_by_email(session=db, email=email.upper())
assert user
user_2 = db.get(User, user.id)
assert user_2
assert user.email == user_2.email
Loading