From f95a38a4b502f0518b40de8ae50fa13095531af4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 8 Sep 2023 14:23:19 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(crud.py):=20change=20HTTP=20?= =?UTF-8?q?status=20code=20from=20304=20to=20status.HTTP=5F304=5FNOT=5FMOD?= =?UTF-8?q?IFIED=20for=20better=20readability=20and=20consistency=20?= =?UTF-8?q?=E2=9C=A8=20feat(crud.py):=20add=20support=20for=20updating=20u?= =?UTF-8?q?ser=20profile=20image=20in=20the=20update=5Fuser=20function=20?= =?UTF-8?q?=E2=9C=A8=20feat(test=5Fuser.py):=20add=20test=20case=20for=20u?= =?UTF-8?q?pdating=20user=20profile=20image=20in=20the=20test=5Fpatch=5Fus?= =?UTF-8?q?er=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/services/database/models/user/crud.py | 7 ++++--- tests/test_user.py | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/services/database/models/user/crud.py b/src/backend/langflow/services/database/models/user/crud.py index 93d5dd801..abc79f49f 100644 --- a/src/backend/langflow/services/database/models/user/crud.py +++ b/src/backend/langflow/services/database/models/user/crud.py @@ -1,13 +1,12 @@ from datetime import datetime, timezone from typing import Union from uuid import UUID -from fastapi import Depends, HTTPException +from fastapi import Depends, HTTPException, status from langflow.services.database.models.user.user import User, UserUpdate from langflow.services.utils import get_session from sqlalchemy.exc import IntegrityError from sqlmodel import Session - from sqlalchemy.orm.attributes import flag_modified @@ -37,7 +36,9 @@ def update_user( changed = True if not changed: - raise HTTPException(status_code=304, detail="Nothing to update") + raise HTTPException( + status_code=status.HTTP_304_NOT_MODIFIED, detail="Nothing to update" + ) user_db.updated_at = datetime.now(timezone.utc) flag_modified(user_db, "updated_at") diff --git a/tests/test_user.py b/tests/test_user.py index 4d99c5c9c..4f2307624 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -163,6 +163,14 @@ def test_patch_user(client, active_user, logged_in_headers): f"/api/v1/users/{user_id}", json=update_data.dict(), headers=logged_in_headers ) assert response.status_code == 304, response.json() + update_data = UserUpdate( + profile_image="new_image", + ) + + response = client.patch( + f"/api/v1/users/{user_id}", json=update_data.dict(), headers=logged_in_headers + ) + assert response.status_code == 200, response.json() def test_patch_reset_password(client, active_user, logged_in_headers):