Skip to content
Merged
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
9 changes: 8 additions & 1 deletion backend/app/api/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,15 @@ def delete_user_me(session: SessionDep, current_user: CurrentUser) -> Any:
return Message(message="User deleted successfully")


@router.post("/signup", response_model=UserPublic)
@router.post(
"/signup",
dependencies=[Depends(get_current_active_superuser)],
response_model=UserPublic,
)
def register_user(session: SessionDep, user_in: UserRegister) -> Any:
"""
This endpoint allows the registration of a new user and is accessible only by a superuser.
"""
if get_user_by_email(session=session, email=user_in.email):
raise HTTPException(
status_code=400,
Expand Down
10 changes: 8 additions & 2 deletions backend/app/tests/api/routes/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,16 @@ def test_update_password_me_same_password_error(
assert updated_user["error"] == "New password cannot be the same as the current one"


def test_register_user(client: TestClient, db: Session) -> None:
def test_register_user(
client: TestClient, superuser_token_headers: dict[str, str], db: Session
) -> None:
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/signup",
headers=superuser_token_headers,
json=data,
)
assert r.status_code == 200
Expand All @@ -281,7 +284,9 @@ def test_register_user(client: TestClient, db: Session) -> None:
assert verify_password(password, user_db.hashed_password)


def test_register_user_already_exists_error(client: TestClient) -> None:
def test_register_user_already_exists_error(
client: TestClient, superuser_token_headers: dict[str, str]
) -> None:
password = random_lower_string()
full_name = random_lower_string()
data = {
Expand All @@ -291,6 +296,7 @@ def test_register_user_already_exists_error(client: TestClient) -> None:
}
r = client.post(
f"{settings.API_V1_STR}/users/signup",
headers=superuser_token_headers,
json=data,
)
assert r.status_code == 400
Expand Down