Remove preview image when bookmark is deleted (#989)

This commit is contained in:
Sascha Ißbrücker
2025-02-15 08:26:58 +01:00
committed by GitHub
parent 78608135d9
commit 5e7172d17e
3 changed files with 94 additions and 11 deletions

View File

@@ -1,25 +1,25 @@
import os
import shutil
import tempfile
from django.conf import settings
from django.test import TestCase
from django.test import TestCase, override_settings
from bookmarks.tests.helpers import (
BookmarkFactoryMixin,
)
from bookmarks.services import bookmarks
from bookmarks.tests.helpers import BookmarkFactoryMixin
class BookmarkAssetsTestCase(TestCase, BookmarkFactoryMixin):
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
self.override = override_settings(LD_ASSET_FOLDER=self.temp_dir)
self.override.enable()
def tearDown(self):
temp_files = [
f for f in os.listdir(settings.LD_ASSET_FOLDER) if f.startswith("temp")
]
for temp_file in temp_files:
os.remove(os.path.join(settings.LD_ASSET_FOLDER, temp_file))
self.override.disable()
shutil.rmtree(self.temp_dir)
def setup_asset_file(self, filename):
if not os.path.exists(settings.LD_ASSET_FOLDER):
os.makedirs(settings.LD_ASSET_FOLDER)
filepath = os.path.join(settings.LD_ASSET_FOLDER, filename)
with open(filepath, "w") as f:
f.write("test")