2022-08-09 19:17:24 +00:00
|
|
|
import math
|
2010-01-28 15:09:17 +00:00
|
|
|
import os.path
|
2010-02-22 23:52:37 +00:00
|
|
|
|
2015-04-27 04:15:41 +00:00
|
|
|
from django.contrib.admin.sites import AdminSite
|
2010-01-28 15:09:17 +00:00
|
|
|
from django.test import TestCase
|
2014-01-10 11:16:08 +00:00
|
|
|
from django.test.utils import override_settings
|
2022-08-09 19:17:24 +00:00
|
|
|
from django.urls import reverse
|
|
|
|
|
from PIL import Image, ImageChops
|
2010-02-22 23:52:37 +00:00
|
|
|
|
2015-04-27 04:15:41 +00:00
|
|
|
from avatar.admin import AvatarAdmin
|
2013-09-13 15:59:52 +00:00
|
|
|
from avatar.conf import settings
|
2010-03-11 13:58:33 +00:00
|
|
|
from avatar.models import Avatar
|
2017-11-09 22:18:05 +00:00
|
|
|
from avatar.signals import avatar_deleted
|
2022-08-09 19:17:24 +00:00
|
|
|
from avatar.templatetags import avatar_tags
|
|
|
|
|
from avatar.utils import get_primary_avatar, get_user_model
|
2010-01-28 15:09:17 +00:00
|
|
|
|
|
|
|
|
|
2017-11-10 09:16:05 +00:00
|
|
|
class AssertSignal:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.signal_sent_count = 0
|
|
|
|
|
self.avatar = None
|
|
|
|
|
self.user = None
|
|
|
|
|
self.sender = None
|
|
|
|
|
self.signal = None
|
|
|
|
|
|
|
|
|
|
def __call__(self, user, avatar, sender, signal):
|
|
|
|
|
self.user = user
|
|
|
|
|
self.avatar = avatar
|
|
|
|
|
self.sender = sender
|
|
|
|
|
self.signal = signal
|
|
|
|
|
self.signal_sent_count += 1
|
2010-01-28 15:09:17 +00:00
|
|
|
|
|
|
|
|
|
2010-03-11 13:58:33 +00:00
|
|
|
def upload_helper(o, filename):
|
|
|
|
|
f = open(os.path.join(o.testdatapath, filename), "rb")
|
2022-07-16 20:50:05 +00:00
|
|
|
response = o.client.post(
|
|
|
|
|
reverse("avatar_add"),
|
|
|
|
|
{
|
|
|
|
|
"avatar": f,
|
|
|
|
|
},
|
|
|
|
|
follow=True,
|
|
|
|
|
)
|
2010-03-11 13:58:33 +00:00
|
|
|
f.close()
|
|
|
|
|
return response
|
2010-01-28 15:09:17 +00:00
|
|
|
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2017-07-11 19:54:41 +00:00
|
|
|
def root_mean_square_difference(image1, image2):
|
|
|
|
|
"Calculate the root-mean-square difference between two images"
|
2022-07-16 20:50:05 +00:00
|
|
|
diff = ImageChops.difference(image1, image2).convert("L")
|
2017-07-11 19:54:41 +00:00
|
|
|
h = diff.histogram()
|
2022-07-16 21:18:09 +00:00
|
|
|
sq = (value * (idx**2) for idx, value in enumerate(h))
|
2017-07-11 19:54:41 +00:00
|
|
|
sum_of_squares = sum(sq)
|
|
|
|
|
rms = math.sqrt(sum_of_squares / float(image1.size[0] * image1.size[1]))
|
|
|
|
|
return rms
|
|
|
|
|
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2017-07-11 19:54:41 +00:00
|
|
|
class AvatarTests(TestCase):
|
2010-01-28 15:09:17 +00:00
|
|
|
def setUp(self):
|
2013-08-01 11:12:49 +00:00
|
|
|
self.testdatapath = os.path.join(os.path.dirname(__file__), "data")
|
2022-07-16 20:50:05 +00:00
|
|
|
self.user = get_user_model().objects.create_user(
|
|
|
|
|
"test", "lennon@thebeatles.com", "testpassword"
|
|
|
|
|
)
|
2010-01-28 15:09:17 +00:00
|
|
|
self.user.save()
|
2022-07-16 20:50:05 +00:00
|
|
|
self.client.login(username="test", password="testpassword")
|
2015-04-27 04:15:41 +00:00
|
|
|
self.site = AdminSite()
|
2010-01-28 15:09:17 +00:00
|
|
|
Image.init()
|
|
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_admin_get_avatar_returns_different_image_tags(self):
|
|
|
|
|
self.test_normal_image_upload()
|
|
|
|
|
self.test_normal_image_upload()
|
2015-04-27 04:15:41 +00:00
|
|
|
primary = Avatar.objects.get(primary=True)
|
|
|
|
|
old = Avatar.objects.get(primary=False)
|
|
|
|
|
|
|
|
|
|
aa = AvatarAdmin(Avatar, self.site)
|
|
|
|
|
primary_link = aa.get_avatar(primary)
|
|
|
|
|
old_link = aa.get_avatar(old)
|
|
|
|
|
|
|
|
|
|
self.assertNotEqual(primary_link, old_link)
|
|
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_non_image_upload(self):
|
2010-03-11 13:58:33 +00:00
|
|
|
response = upload_helper(self, "nonimagefile")
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2022-07-16 20:50:05 +00:00
|
|
|
self.assertNotEqual(response.context["upload_avatar_form"].errors, {})
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_normal_image_upload(self):
|
2010-03-11 13:58:33 +00:00
|
|
|
response = upload_helper(self, "test.png")
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.redirect_chain), 1)
|
2022-07-16 20:50:05 +00:00
|
|
|
self.assertEqual(response.context["upload_avatar_form"].errors, {})
|
2010-02-25 11:54:15 +00:00
|
|
|
avatar = get_primary_avatar(self.user)
|
2016-01-19 16:00:34 +00:00
|
|
|
self.assertIsNotNone(avatar)
|
|
|
|
|
self.assertEqual(avatar.user, self.user)
|
|
|
|
|
self.assertTrue(avatar.primary)
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_image_without_wrong_extension(self):
|
2010-03-11 13:58:33 +00:00
|
|
|
# use with AVATAR_ALLOWED_FILE_EXTS = ('.jpg', '.png')
|
|
|
|
|
response = upload_helper(self, "imagefilewithoutext")
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.redirect_chain), 0) # Redirect only if it worked
|
2022-07-16 20:50:05 +00:00
|
|
|
self.assertNotEqual(response.context["upload_avatar_form"].errors, {})
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_image_with_wrong_extension(self):
|
2010-03-11 13:58:33 +00:00
|
|
|
# use with AVATAR_ALLOWED_FILE_EXTS = ('.jpg', '.png')
|
|
|
|
|
response = upload_helper(self, "imagefilewithwrongext.ogg")
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.redirect_chain), 0) # Redirect only if it worked
|
2022-07-16 20:50:05 +00:00
|
|
|
self.assertNotEqual(response.context["upload_avatar_form"].errors, {})
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_image_too_big(self):
|
2010-03-11 13:58:33 +00:00
|
|
|
# use with AVATAR_MAX_SIZE = 1024 * 1024
|
|
|
|
|
response = upload_helper(self, "testbig.png")
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.redirect_chain), 0) # Redirect only if it worked
|
2022-07-16 20:50:05 +00:00
|
|
|
self.assertNotEqual(response.context["upload_avatar_form"].errors, {})
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_default_url(self):
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.get(
|
|
|
|
|
reverse(
|
|
|
|
|
"avatar_render_primary",
|
|
|
|
|
kwargs={
|
|
|
|
|
"user": self.user.username,
|
|
|
|
|
"size": 80,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
loc = response["Location"]
|
|
|
|
|
base_url = getattr(settings, "STATIC_URL", None)
|
2010-02-22 23:48:22 +00:00
|
|
|
if not base_url:
|
|
|
|
|
base_url = settings.MEDIA_URL
|
|
|
|
|
self.assertTrue(base_url in loc)
|
2013-09-13 15:59:52 +00:00
|
|
|
self.assertTrue(loc.endswith(settings.AVATAR_DEFAULT_URL))
|
2010-02-25 11:54:15 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_non_existing_user(self):
|
2010-02-25 11:54:15 +00:00
|
|
|
a = get_primary_avatar("nonexistinguser")
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(a, None)
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_there_can_be_only_one_primary_avatar(self):
|
2022-08-09 19:17:24 +00:00
|
|
|
for _ in range(1, 10):
|
2016-01-19 16:00:34 +00:00
|
|
|
self.test_normal_image_upload()
|
2010-03-11 13:58:33 +00:00
|
|
|
count = Avatar.objects.filter(user=self.user, primary=True).count()
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(count, 1)
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_delete_avatar(self):
|
|
|
|
|
self.test_normal_image_upload()
|
2010-03-11 13:58:33 +00:00
|
|
|
avatar = Avatar.objects.filter(user=self.user)
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(len(avatar), 1)
|
2017-11-10 09:16:05 +00:00
|
|
|
receiver = AssertSignal()
|
2017-11-09 22:18:05 +00:00
|
|
|
avatar_deleted.connect(receiver)
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.post(
|
|
|
|
|
reverse("avatar_delete"),
|
|
|
|
|
{
|
|
|
|
|
"choices": [avatar[0].id],
|
|
|
|
|
},
|
|
|
|
|
follow=True,
|
|
|
|
|
)
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.redirect_chain), 1)
|
2010-03-11 13:58:33 +00:00
|
|
|
count = Avatar.objects.filter(user=self.user).count()
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(count, 0)
|
2017-11-10 09:16:05 +00:00
|
|
|
self.assertEqual(receiver.user, self.user)
|
|
|
|
|
self.assertEqual(receiver.avatar, avatar[0])
|
|
|
|
|
self.assertEqual(receiver.sender, Avatar)
|
|
|
|
|
self.assertEqual(receiver.signal_sent_count, 1)
|
2013-08-01 11:12:49 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_delete_primary_avatar_and_new_primary(self):
|
|
|
|
|
self.test_there_can_be_only_one_primary_avatar()
|
2010-03-11 13:58:33 +00:00
|
|
|
primary = get_primary_avatar(self.user)
|
|
|
|
|
oid = primary.id
|
2022-07-16 20:50:05 +00:00
|
|
|
self.client.post(
|
|
|
|
|
reverse("avatar_delete"),
|
|
|
|
|
{
|
|
|
|
|
"choices": [oid],
|
|
|
|
|
},
|
|
|
|
|
)
|
2010-03-11 13:58:33 +00:00
|
|
|
primaries = Avatar.objects.filter(user=self.user, primary=True)
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(len(primaries), 1)
|
|
|
|
|
self.assertNotEqual(oid, primaries[0].id)
|
2010-03-11 13:58:33 +00:00
|
|
|
avatars = Avatar.objects.filter(user=self.user)
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(avatars[0].id, primaries[0].id)
|
2010-03-11 13:58:33 +00:00
|
|
|
|
2016-01-19 16:00:34 +00:00
|
|
|
def test_change_avatar_get(self):
|
|
|
|
|
self.test_normal_image_upload()
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.get(reverse("avatar_change"))
|
2016-01-19 16:00:34 +00:00
|
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2022-07-16 20:50:05 +00:00
|
|
|
self.assertIsNotNone(response.context["avatar"])
|
2016-01-19 16:00:34 +00:00
|
|
|
|
|
|
|
|
def test_change_avatar_post_updates_primary_avatar(self):
|
|
|
|
|
self.test_there_can_be_only_one_primary_avatar()
|
|
|
|
|
old_primary = Avatar.objects.get(user=self.user, primary=True)
|
|
|
|
|
choice = Avatar.objects.filter(user=self.user, primary=False)[0]
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.post(
|
|
|
|
|
reverse("avatar_change"),
|
|
|
|
|
{
|
|
|
|
|
"choice": choice.pk,
|
|
|
|
|
},
|
|
|
|
|
)
|
2016-01-19 16:00:34 +00:00
|
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
|
new_primary = Avatar.objects.get(user=self.user, primary=True)
|
|
|
|
|
self.assertEqual(new_primary.pk, choice.pk)
|
|
|
|
|
# Avatar with old primary pk exists but it is not primary anymore
|
2022-07-16 20:50:05 +00:00
|
|
|
self.assertTrue(
|
|
|
|
|
Avatar.objects.filter(
|
|
|
|
|
user=self.user, pk=old_primary.pk, primary=False
|
|
|
|
|
).exists()
|
|
|
|
|
)
|
2016-01-19 16:00:34 +00:00
|
|
|
|
|
|
|
|
def test_too_many_avatars(self):
|
2022-08-09 19:17:24 +00:00
|
|
|
for _ in range(0, settings.AVATAR_MAX_AVATARS_PER_USER):
|
2016-01-19 16:00:34 +00:00
|
|
|
self.test_normal_image_upload()
|
2013-08-01 11:12:49 +00:00
|
|
|
count_before = Avatar.objects.filter(user=self.user).count()
|
2010-03-11 13:58:33 +00:00
|
|
|
response = upload_helper(self, "test.png")
|
|
|
|
|
count_after = Avatar.objects.filter(user=self.user).count()
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.redirect_chain), 0) # Redirect only if it worked
|
2022-07-16 20:50:05 +00:00
|
|
|
self.assertNotEqual(response.context["upload_avatar_form"].errors, {})
|
2013-08-01 11:33:14 +00:00
|
|
|
self.assertEqual(count_before, count_after)
|
2010-02-25 12:00:37 +00:00
|
|
|
|
2022-07-16 20:50:05 +00:00
|
|
|
@override_settings(AVATAR_THUMB_FORMAT="png")
|
2016-02-11 21:36:19 +00:00
|
|
|
def test_automatic_thumbnail_creation_RGBA(self):
|
2014-01-10 11:16:08 +00:00
|
|
|
upload_helper(self, "django.png")
|
|
|
|
|
avatar = get_primary_avatar(self.user)
|
2022-07-16 20:50:05 +00:00
|
|
|
image = Image.open(
|
|
|
|
|
avatar.avatar.storage.open(
|
|
|
|
|
avatar.avatar_name(settings.AVATAR_DEFAULT_SIZE), "rb"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(image.mode, "RGBA")
|
2014-01-10 11:16:08 +00:00
|
|
|
|
2016-02-11 21:36:19 +00:00
|
|
|
def test_automatic_thumbnail_creation_CMYK(self):
|
2014-01-10 11:16:08 +00:00
|
|
|
upload_helper(self, "django_pony_cmyk.jpg")
|
|
|
|
|
avatar = get_primary_avatar(self.user)
|
2022-07-16 20:50:05 +00:00
|
|
|
image = Image.open(
|
|
|
|
|
avatar.avatar.storage.open(
|
|
|
|
|
avatar.avatar_name(settings.AVATAR_DEFAULT_SIZE), "rb"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(image.mode, "RGB")
|
2016-02-09 15:42:29 +00:00
|
|
|
|
2017-07-11 19:54:41 +00:00
|
|
|
def test_thumbnail_transpose_based_on_exif(self):
|
|
|
|
|
upload_helper(self, "image_no_exif.jpg")
|
|
|
|
|
avatar = get_primary_avatar(self.user)
|
2022-07-16 20:50:05 +00:00
|
|
|
image_no_exif = Image.open(
|
|
|
|
|
avatar.avatar.storage.open(
|
|
|
|
|
avatar.avatar_name(settings.AVATAR_DEFAULT_SIZE), "rb"
|
|
|
|
|
)
|
|
|
|
|
)
|
2017-07-11 19:54:41 +00:00
|
|
|
|
|
|
|
|
upload_helper(self, "image_exif_orientation.jpg")
|
|
|
|
|
avatar = get_primary_avatar(self.user)
|
2022-07-16 20:50:05 +00:00
|
|
|
image_with_exif = Image.open(
|
|
|
|
|
avatar.avatar.storage.open(
|
|
|
|
|
avatar.avatar_name(settings.AVATAR_DEFAULT_SIZE), "rb"
|
|
|
|
|
)
|
|
|
|
|
)
|
2017-07-11 19:54:41 +00:00
|
|
|
|
|
|
|
|
self.assertLess(root_mean_square_difference(image_with_exif, image_no_exif), 1)
|
|
|
|
|
|
2016-02-11 21:36:19 +00:00
|
|
|
def test_has_avatar_False_if_no_avatar(self):
|
|
|
|
|
self.assertFalse(avatar_tags.has_avatar(self.user))
|
|
|
|
|
|
|
|
|
|
def test_has_avatar_False_if_not_user_model(self):
|
|
|
|
|
self.assertFalse(avatar_tags.has_avatar("Look, I'm a string"))
|
|
|
|
|
|
|
|
|
|
def test_has_avatar_True(self):
|
|
|
|
|
upload_helper(self, "test.png")
|
|
|
|
|
|
|
|
|
|
self.assertTrue(avatar_tags.has_avatar(self.user))
|
|
|
|
|
|
|
|
|
|
def test_avatar_tag_works_with_username(self):
|
|
|
|
|
upload_helper(self, "test.png")
|
|
|
|
|
avatar = get_primary_avatar(self.user)
|
|
|
|
|
|
|
|
|
|
result = avatar_tags.avatar(self.user.username)
|
|
|
|
|
|
|
|
|
|
self.assertIn('<img src="{}"'.format(avatar.avatar_url(80)), result)
|
2017-01-17 14:39:42 +00:00
|
|
|
self.assertIn('width="80" height="80" alt="test" />', result)
|
2016-02-11 21:36:19 +00:00
|
|
|
|
|
|
|
|
def test_avatar_tag_works_with_user(self):
|
|
|
|
|
upload_helper(self, "test.png")
|
|
|
|
|
avatar = get_primary_avatar(self.user)
|
|
|
|
|
|
|
|
|
|
result = avatar_tags.avatar(self.user)
|
|
|
|
|
|
|
|
|
|
self.assertIn('<img src="{}"'.format(avatar.avatar_url(80)), result)
|
2017-01-17 14:39:42 +00:00
|
|
|
self.assertIn('width="80" height="80" alt="test" />', result)
|
2016-02-11 21:36:19 +00:00
|
|
|
|
|
|
|
|
def test_avatar_tag_works_with_custom_size(self):
|
|
|
|
|
upload_helper(self, "test.png")
|
|
|
|
|
avatar = get_primary_avatar(self.user)
|
|
|
|
|
|
|
|
|
|
result = avatar_tags.avatar(self.user, 100)
|
|
|
|
|
|
|
|
|
|
self.assertIn('<img src="{}"'.format(avatar.avatar_url(100)), result)
|
2017-01-17 14:39:42 +00:00
|
|
|
self.assertIn('width="100" height="100" alt="test" />', result)
|
2016-02-11 21:36:19 +00:00
|
|
|
|
2017-01-17 15:44:38 +00:00
|
|
|
def test_avatar_tag_works_with_kwargs(self):
|
|
|
|
|
upload_helper(self, "test.png")
|
|
|
|
|
avatar = get_primary_avatar(self.user)
|
|
|
|
|
|
|
|
|
|
result = avatar_tags.avatar(self.user, title="Avatar")
|
2022-07-16 20:50:05 +00:00
|
|
|
html = (
|
|
|
|
|
'<img src="{}" width="80" height="80" alt="test" title="Avatar" />'.format(
|
|
|
|
|
avatar.avatar_url(80)
|
|
|
|
|
)
|
|
|
|
|
)
|
2017-02-02 10:28:09 +00:00
|
|
|
self.assertInHTML(html, result)
|
2017-01-17 15:44:38 +00:00
|
|
|
|
2016-08-17 15:08:45 +00:00
|
|
|
def test_default_add_template(self):
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.get("/avatar/add/")
|
|
|
|
|
self.assertContains(response, "Upload New Image")
|
|
|
|
|
self.assertNotContains(response, "ALTERNATE ADD TEMPLATE")
|
2016-08-17 15:08:45 +00:00
|
|
|
|
2022-07-16 20:50:05 +00:00
|
|
|
@override_settings(AVATAR_ADD_TEMPLATE="alt/add.html")
|
2016-08-17 15:08:45 +00:00
|
|
|
def test_custom_add_template(self):
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.get("/avatar/add/")
|
|
|
|
|
self.assertNotContains(response, "Upload New Image")
|
|
|
|
|
self.assertContains(response, "ALTERNATE ADD TEMPLATE")
|
2016-08-17 15:08:45 +00:00
|
|
|
|
|
|
|
|
def test_default_change_template(self):
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.get("/avatar/change/")
|
|
|
|
|
self.assertContains(response, "Upload New Image")
|
|
|
|
|
self.assertNotContains(response, "ALTERNATE CHANGE TEMPLATE")
|
2016-08-17 15:08:45 +00:00
|
|
|
|
2022-07-16 20:50:05 +00:00
|
|
|
@override_settings(AVATAR_CHANGE_TEMPLATE="alt/change.html")
|
2016-08-17 15:08:45 +00:00
|
|
|
def test_custom_change_template(self):
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.get("/avatar/change/")
|
|
|
|
|
self.assertNotContains(response, "Upload New Image")
|
|
|
|
|
self.assertContains(response, "ALTERNATE CHANGE TEMPLATE")
|
2016-08-17 15:08:45 +00:00
|
|
|
|
|
|
|
|
def test_default_delete_template(self):
|
2022-08-10 02:17:08 +00:00
|
|
|
upload_helper(self, "test.png")
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.get("/avatar/delete/")
|
|
|
|
|
self.assertContains(response, "like to delete.")
|
|
|
|
|
self.assertNotContains(response, "ALTERNATE DELETE TEMPLATE")
|
2016-08-17 15:08:45 +00:00
|
|
|
|
2022-07-16 20:50:05 +00:00
|
|
|
@override_settings(AVATAR_DELETE_TEMPLATE="alt/delete.html")
|
2016-08-17 15:08:45 +00:00
|
|
|
def test_custom_delete_template(self):
|
2022-07-16 20:50:05 +00:00
|
|
|
response = self.client.get("/avatar/delete/")
|
|
|
|
|
self.assertNotContains(response, "like to delete.")
|
|
|
|
|
self.assertContains(response, "ALTERNATE DELETE TEMPLATE")
|
2017-02-02 10:28:09 +00:00
|
|
|
|
2016-02-09 15:42:29 +00:00
|
|
|
# def testAvatarOrder
|
|
|
|
|
# def testReplaceAvatarWhenMaxIsOne
|
|
|
|
|
# def testHashFileName
|
|
|
|
|
# def testHashUserName
|
|
|
|
|
# def testChangePrimaryAvatar
|
|
|
|
|
# def testDeleteThumbnailAndRecreation
|
|
|
|
|
# def testAutomaticThumbnailCreation
|