mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-05-08 15:44:45 +00:00
Merge b187e21fb1 into 12e4745f29
This commit is contained in:
commit
58c09c8a1d
3 changed files with 17 additions and 4 deletions
|
|
@ -210,7 +210,10 @@ def remove_avatar_images(instance=None, delete_main_avatar=True, **kwargs):
|
|||
path, filename = os.path.split(base_filepath)
|
||||
# iterate through resized avatars directories and delete resized avatars
|
||||
resized_path = os.path.join(path, "resized")
|
||||
resized_widths, _ = instance.avatar.storage.listdir(resized_path)
|
||||
try:
|
||||
resized_widths, _ = instance.avatar.storage.listdir(resized_path)
|
||||
except FileNotFoundError:
|
||||
resized_widths = []
|
||||
for width in resized_widths:
|
||||
resized_width_path = os.path.join(resized_path, width)
|
||||
resized_heights, _ = instance.avatar.storage.listdir(resized_width_path)
|
||||
|
|
|
|||
|
|
@ -50,8 +50,6 @@ SITE_ID = 1
|
|||
|
||||
SECRET_KEY = "something-something"
|
||||
|
||||
ROOT_URLCONF = "tests.urls"
|
||||
|
||||
STATIC_URL = "/site_media/static/"
|
||||
|
||||
AVATAR_ALLOWED_FILE_EXTS = (".jpg", ".png")
|
||||
|
|
@ -59,5 +57,4 @@ AVATAR_MAX_SIZE = 1024 * 1024
|
|||
AVATAR_MAX_AVATARS_PER_USER = 20
|
||||
AVATAR_AUTO_GENERATE_SIZES = [51, 62, (33, 22), 80]
|
||||
|
||||
|
||||
MEDIA_ROOT = os.path.join(SETTINGS_DIR, "../test-media")
|
||||
|
|
|
|||
|
|
@ -217,6 +217,19 @@ class AvatarTests(TestCase):
|
|||
self.assertEqual(receiver.sender, Avatar)
|
||||
self.assertEqual(receiver.signal_sent_count, 1)
|
||||
|
||||
def test_delete_avatar_without_resized_directory(self):
|
||||
self.test_normal_image_upload()
|
||||
avatar = Avatar.objects.get(user=self.user)
|
||||
resized_path = os.path.join(
|
||||
self.testmediapath,
|
||||
os.path.dirname(avatar.avatar.name),
|
||||
"resized",
|
||||
)
|
||||
if os.path.exists(resized_path):
|
||||
rmtree(resized_path)
|
||||
avatar.delete()
|
||||
self.assertEqual(Avatar.objects.filter(user=self.user).count(), 0)
|
||||
|
||||
def test_delete_primary_avatar_and_new_primary(self):
|
||||
self.test_there_can_be_only_one_primary_avatar()
|
||||
primary = get_primary_avatar(self.user)
|
||||
|
|
|
|||
Loading…
Reference in a new issue