🐛 fix(crud.py): change HTTP status code from 304 to status.HTTP_304_NOT_MODIFIED for better readability and consistency

 feat(crud.py): add support for updating user profile image in the update_user function
 feat(test_user.py): add test case for updating user profile image in the test_patch_user function
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-08 14:23:19 -03:00
commit f95a38a4b5
2 changed files with 12 additions and 3 deletions

View file

@ -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")

View file

@ -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):