diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index 406f6e18..25cd73a9 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -399,7 +399,9 @@ def _after_post_update( def _before_post_delete( _mapper: Any, _connection: Any, post: model.Post) -> None: if post.post_id: - image_hash.delete_image(post.post_id) + image_hash.delete_image(str(post.post_id)) + files.delete(get_post_content_path(post)) + files.delete(get_post_thumbnail_path(post)) def _sync_post_content(post: model.Post) -> None: @@ -686,12 +688,14 @@ def merge_posts( merge_favorites(source_post.post_id, target_post.post_id) merge_relations(source_post.post_id, target_post.post_id) - delete(source_post) - - db.session.flush() - + content = None if replace_content: content = files.get(get_post_content_path(source_post)) + + delete(source_post) + db.session.flush() + + if content is not None: update_post_content(target_post, content) diff --git a/server/szurubooru/tests/api/test_post_deleting.py b/server/szurubooru/tests/api/test_post_deleting.py index e35a4488..85744ad1 100644 --- a/server/szurubooru/tests/api/test_post_deleting.py +++ b/server/szurubooru/tests/api/test_post_deleting.py @@ -1,12 +1,14 @@ from unittest.mock import patch + import pytest + from szurubooru import api, db, model, errors -from szurubooru.func import posts, tags, snapshots +from szurubooru.func import posts, snapshots @pytest.fixture(autouse=True) def inject_config(config_injector): - config_injector({'privileges': {'posts:delete': model.User.RANK_REGULAR}}) + config_injector({'secret': 'secret', 'data_dir': '', 'privileges': {'posts:delete': model.User.RANK_REGULAR}}) def test_deleting(user_factory, post_factory, context_factory): diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index e296ec0a..c5570f0e 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -1,7 +1,9 @@ -import os -from unittest.mock import patch from datetime import datetime +from unittest.mock import patch + +import os import pytest + from szurubooru import db, model from szurubooru.func import ( posts, users, comments, tags, images, files, util, image_hash) @@ -936,6 +938,6 @@ def test_merge_posts_replaces_content( assert posts.try_get_post_by_id(source_post.post_id) is None post = posts.get_post_by_id(target_post.post_id) assert post is not None - assert os.path.exists(source_path) + assert not os.path.exists(source_path) assert os.path.exists(target_path1) assert not os.path.exists(target_path2) diff --git a/server/szurubooru/tests/model/test_post.py b/server/szurubooru/tests/model/test_post.py index f35e2751..2fffd87b 100644 --- a/server/szurubooru/tests/model/test_post.py +++ b/server/szurubooru/tests/model/test_post.py @@ -1,7 +1,15 @@ from datetime import datetime + +import pytest + from szurubooru import db, model +@pytest.fixture(autouse=True) +def inject_config(config_injector): + config_injector({'secret': 'secret', 'data_dir': ''}) + + def test_saving_post(post_factory, user_factory, tag_factory): user = user_factory() tag1 = tag_factory() diff --git a/server/szurubooru/tests/model/test_tag.py b/server/szurubooru/tests/model/test_tag.py index 07bbc0e5..9121f91c 100644 --- a/server/szurubooru/tests/model/test_tag.py +++ b/server/szurubooru/tests/model/test_tag.py @@ -1,7 +1,15 @@ from datetime import datetime + +import pytest + from szurubooru import db, model +@pytest.fixture(autouse=True) +def inject_config(config_injector): + config_injector({'secret': 'secret', 'data_dir': ''}) + + def test_saving_tag(tag_factory): sug1 = tag_factory(names=['sug1']) sug2 = tag_factory(names=['sug2'])