From d792b61722f6266c63b7e0c28080c592630e993f Mon Sep 17 00:00:00 2001 From: Ashvin <76151462+ashvinctrl@users.noreply.github.com> Date: Mon, 15 Jun 2026 19:37:49 +0530 Subject: [PATCH] test(gallery): point delete-ordering tests at the tmp image dir (#4300) The two delete-ordering tests did monkeypatch.chdir(tmp_path) and wrote the image under tmp_path/data/generated_images, but DATA_DIR (and therefore gallery_routes.GALLERY_IMAGE_DIR) is always an absolute path, so the delete resolver pointed at the repo's real data dir and ignored the chdir. test_file_removed_on_successful_delete therefore failed on dev (the file at the tmp path was never the one being removed), and test_file_kept_when_commit_fails passed only by accident. Set GALLERY_IMAGE_DIR to the seeded tmp dir via monkeypatch so both tests exercise the real path and pass deterministically. --- tests/test_gallery_delete_file_ordering.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_gallery_delete_file_ordering.py b/tests/test_gallery_delete_file_ordering.py index 03e0ef73e..468a2e7c4 100644 --- a/tests/test_gallery_delete_file_ordering.py +++ b/tests/test_gallery_delete_file_ordering.py @@ -41,8 +41,10 @@ def _seed(tmp_path): def test_file_kept_when_commit_fails(tmp_path, monkeypatch): - monkeypatch.chdir(tmp_path) SessionLocal = _seed(tmp_path) + # GALLERY_IMAGE_DIR is an absolute path fixed at import, so a chdir can't + # redirect the delete; point the resolver at the seeded tmp dir directly. + monkeypatch.setattr(gallery_routes, "GALLERY_IMAGE_DIR", tmp_path / "data" / "generated_images") monkeypatch.setattr(gallery_routes, "get_current_user", lambda r: "alice") # A session whose commit always fails, to simulate a DB error mid-delete. @@ -67,8 +69,8 @@ def test_file_kept_when_commit_fails(tmp_path, monkeypatch): def test_file_removed_on_successful_delete(tmp_path, monkeypatch): - monkeypatch.chdir(tmp_path) SessionLocal = _seed(tmp_path) + monkeypatch.setattr(gallery_routes, "GALLERY_IMAGE_DIR", tmp_path / "data" / "generated_images") monkeypatch.setattr(gallery_routes, "get_current_user", lambda r: "alice") monkeypatch.setattr(gallery_routes, "SessionLocal", SessionLocal)