mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
Remove former profile image upon new upload (#381)
* Remove former profile image upon new upload * Fix test
This commit is contained in:
parent
fad2f8da59
commit
52e5e9da5d
@ -105,10 +105,7 @@ async def update_user_image(
|
|||||||
|
|
||||||
app_dirs.USER_DIR.joinpath(id).mkdir(parents=True, exist_ok=True)
|
app_dirs.USER_DIR.joinpath(id).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
try:
|
[x.unlink() for x in app_dirs.USER_DIR.joinpath(id).glob("profile_image.*")]
|
||||||
[x.unlink() for x in app_dirs.USER_DIR.join(id).glob("profile_image.*")]
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
dest = app_dirs.USER_DIR.joinpath(id, f"profile_image.{extension}")
|
dest = app_dirs.USER_DIR.joinpath(id, f"profile_image.{extension}")
|
||||||
|
|
||||||
|
@ -47,8 +47,13 @@ def api_routes():
|
|||||||
|
|
||||||
|
|
||||||
@fixture(scope="session")
|
@fixture(scope="session")
|
||||||
def test_image():
|
def test_image_jpg():
|
||||||
return TEST_DATA.joinpath("test_image.jpg")
|
return TEST_DATA.joinpath("images", "test_image.jpg")
|
||||||
|
|
||||||
|
|
||||||
|
@fixture(scope="session")
|
||||||
|
def test_image_png():
|
||||||
|
return TEST_DATA.joinpath("images", "test_image.png")
|
||||||
|
|
||||||
|
|
||||||
@fixture(scope="session")
|
@fixture(scope="session")
|
||||||
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
BIN
tests/data/images/test_image.png
Normal file
BIN
tests/data/images/test_image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@ -1,6 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
from mealie.core.config import app_dirs
|
||||||
from mealie.schema.user import UserOut
|
from mealie.schema.user import UserOut
|
||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
from tests.app_routes import AppRoutes
|
from tests.app_routes import AppRoutes
|
||||||
@ -84,3 +86,25 @@ def test_delete_user(api_client: TestClient, api_routes: AppRoutes, token):
|
|||||||
response = api_client.delete(api_routes.users_id(2), headers=token)
|
response = api_client.delete(api_routes.users_id(2), headers=token)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_user_image(
|
||||||
|
api_client: TestClient, api_routes: AppRoutes, test_image_jpg: Path, test_image_png: Path, token
|
||||||
|
):
|
||||||
|
response = api_client.post(
|
||||||
|
api_routes.users_id_image(2), files={"profile_image": test_image_jpg.open("rb")}, headers=token
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
response = api_client.post(
|
||||||
|
api_routes.users_id_image(2), files={"profile_image": test_image_png.open("rb")}, headers=token
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
directory = app_dirs.USER_DIR.joinpath("2")
|
||||||
|
assert directory.joinpath("profile_image.png").is_file()
|
||||||
|
|
||||||
|
# Old profile images are removed
|
||||||
|
assert 1 == len([file for file in directory.glob("profile_image.*") if file.is_file()])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user