♻️ Refactor and tweaks, rename UserCreateOpen to UserRegister and others (#1143)

This commit is contained in:
Alejandra
2024-04-01 22:53:33 -05:00
committed by GitHub
parent aed4db7521
commit 4239d93ea6
45 changed files with 537 additions and 518 deletions

View File

@@ -17,8 +17,8 @@ from app.models import (
UpdatePassword,
User,
UserCreate,
UserCreateOpen,
UserOut,
UserRegister,
UsersOut,
UserUpdate,
UserUpdateMe,
@@ -122,8 +122,8 @@ def read_user_me(session: SessionDep, current_user: CurrentUser) -> Any:
return current_user
@router.post("/open", response_model=UserOut)
def create_user_open(session: SessionDep, user_in: UserCreateOpen) -> Any:
@router.post("/signup", response_model=UserOut)
def register_user(session: SessionDep, user_in: UserRegister) -> Any:
"""
Create new user without the need to be logged in.
"""
@@ -138,7 +138,7 @@ def create_user_open(session: SessionDep, user_in: UserCreateOpen) -> Any:
status_code=400,
detail="The user with this email already exists in the system",
)
user_create = UserCreate.from_orm(user_in)
user_create = UserCreate.model_validate(user_in)
user = crud.create_user(session=session, user_create=user_create)
return user

View File

@@ -16,7 +16,7 @@ class UserCreate(UserBase):
# TODO replace email str with EmailStr when sqlmodel supports it
class UserCreateOpen(SQLModel):
class UserRegister(SQLModel):
email: str
password: str
full_name: str | None = None

View File

@@ -263,14 +263,14 @@ def test_update_password_me_same_password_error(
)
def test_create_user_open(client: TestClient) -> None:
def test_register_user(client: TestClient) -> None:
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True):
username = random_email()
password = random_lower_string()
full_name = random_lower_string()
data = {"email": username, "password": password, "full_name": full_name}
r = client.post(
f"{settings.API_V1_STR}/users/open",
f"{settings.API_V1_STR}/users/signup",
json=data,
)
assert r.status_code == 200
@@ -279,14 +279,14 @@ def test_create_user_open(client: TestClient) -> None:
assert created_user["full_name"] == full_name
def test_create_user_open_forbidden_error(client: TestClient) -> None:
def test_register_user_forbidden_error(client: TestClient) -> None:
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", False):
username = random_email()
password = random_lower_string()
full_name = random_lower_string()
data = {"email": username, "password": password, "full_name": full_name}
r = client.post(
f"{settings.API_V1_STR}/users/open",
f"{settings.API_V1_STR}/users/signup",
json=data,
)
assert r.status_code == 403
@@ -295,7 +295,7 @@ def test_create_user_open_forbidden_error(client: TestClient) -> None:
)
def test_create_user_open_already_exists_error(client: TestClient) -> None:
def test_register_user_already_exists_error(client: TestClient) -> None:
with patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True):
password = random_lower_string()
full_name = random_lower_string()
@@ -305,7 +305,7 @@ def test_create_user_open_already_exists_error(client: TestClient) -> None:
"full_name": full_name,
}
r = client.post(
f"{settings.API_V1_STR}/users/open",
f"{settings.API_V1_STR}/users/signup",
json=data,
)
assert r.status_code == 400