Exemple #1
0
    def test_store(self):
        """store successfully stores and deletes avatar"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'pass123')

        test_image = Image.new("RGBA", (100, 100), 0)
        store.store_avatar(test_user, test_image)

        # Assert that avatar was stored
        avatar_dir = store.get_existing_avatars_dir(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertTrue(avatar.exists())
            self.assertTrue(avatar.isfile())

        # Delete avatar and assert its gone
        store.delete_avatar(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertFalse(avatar.exists())

        # Override new avatar and test that it was changed
        store.store_avatar(test_user, test_image)
        store.store_new_avatar(test_user, test_image)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertTrue(avatar.exists())
            self.assertTrue(avatar.isfile())

        # Delete avatar
        store.delete_avatar(test_user)
    def test_store(self):
        """store successfully stores and deletes avatar"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'pass123')

        test_image = Image.new("RGBA", (100, 100), 0)
        store.store_avatar(test_user, test_image)

        # Assert that avatar was stored
        avatar_dir = store.get_existing_avatars_dir(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertTrue(avatar.exists())
            self.assertTrue(avatar.isfile())

        # Delete avatar and assert its gone
        store.delete_avatar(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertFalse(avatar.exists())

        # Override new avatar and test that it was changed
        store.store_avatar(test_user, test_image)
        store.store_new_avatar(test_user, test_image)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertTrue(avatar.exists())
            self.assertTrue(avatar.isfile())

        # Delete avatar
        store.delete_avatar(test_user)
Exemple #3
0
def crop_source_image(user, source, crop):
    image = Image.open(store.avatar_file_path(user, source))
    crop = crop_string_to_dict(image, crop)

    crop_dimensions = [int(d * crop['ratio']) for d in crop['source']]
    cropped_image = image.crop(crop_dimensions)

    store.store_avatar(user, cropped_image)
    if source == 'tmp':
        store.store_original_avatar(user)

    return crop
def crop_source_image(user, source, crop):
    image = Image.open(store.avatar_file_path(user, source))
    crop = crop_string_to_dict(image, crop)

    crop_dimensions = [int(d * crop['ratio']) for d in crop['source']]
    cropped_image = image.crop(crop_dimensions)

    store.store_avatar(user, cropped_image)
    if source == 'tmp':
        store.store_original_avatar(user)

    return crop
Exemple #5
0
    def test_store(self):
        """store successfully stores and deletes avatar"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'pass123')

        test_image = Image.new("RGBA", (100, 100), 0)
        store.store_avatar(test_user, test_image)

        # Assert that avatar was stored
        avatar_dir = store.get_existing_avatars_dir(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertTrue(avatar.exists())
            self.assertTrue(avatar.isfile())

        # Delete avatar and assert its gone
        store.delete_avatar(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertFalse(avatar.exists())

        # Override new avatar and test that it was changed
        store.store_avatar(test_user, test_image)
        store.store_new_avatar(test_user, test_image)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertTrue(avatar.exists())
            self.assertTrue(avatar.isfile())

        # Compute avatar hash
        test_user.avatar_hash = store.get_avatar_hash(test_user)
        self.assertEqual(len(test_user.avatar_hash), 8)
        test_user.save(update_fields=['avatar_hash'])

        # Get avatar tokens
        tokens = store.get_user_avatar_tokens(test_user)
        self.assertEqual(tokens[tokens['org']], 'org')
        self.assertEqual(tokens[tokens['tmp']], 'tmp')

        # Delete avatar
        store.delete_avatar(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertFalse(avatar.exists())
Exemple #6
0
    def test_store(self):
        """store successfully stores and deletes avatar"""
        User = get_user_model()
        test_user = User.objects.create_user('Bob', '*****@*****.**', 'pass123')

        test_image = Image.new("RGBA", (100, 100), 0)
        store.store_avatar(test_user, test_image)

        # Assert that avatar was stored
        avatar_dir = store.get_existing_avatars_dir(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertTrue(avatar.exists())
            self.assertTrue(avatar.isfile())

        # Delete avatar and assert its gone
        store.delete_avatar(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertFalse(avatar.exists())

        # Override new avatar and test that it was changed
        store.store_avatar(test_user, test_image)
        store.store_new_avatar(test_user, test_image)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertTrue(avatar.exists())
            self.assertTrue(avatar.isfile())

        # Compute avatar hash
        test_user.avatar_hash = store.get_avatar_hash(test_user)
        self.assertEqual(len(test_user.avatar_hash), 8)
        test_user.save(update_fields=['avatar_hash'])

        # Get avatar tokens
        tokens = store.get_user_avatar_tokens(test_user)
        self.assertEqual(tokens[tokens['org']], 'org')
        self.assertEqual(tokens[tokens['tmp']], 'tmp')

        # Delete avatar
        store.delete_avatar(test_user)
        for size in settings.MISAGO_AVATARS_SIZES:
            avatar = Path('%s/%s_%s.png' % (avatar_dir, test_user.pk, size))
            self.assertFalse(avatar.exists())
Exemple #7
0
def crop_source_image(user, source, crop):
    image = Image.open(store.avatar_file_path(user, source))
    crop = clean_crop(image, crop)

    min_size = max(settings.MISAGO_AVATARS_SIZES)
    if image.size[0] == min_size and image.size[0] == image.size[1]:
        cropped_image = image
    else:
        upscale = 1.0 / crop['zoom']
        cropped_image = image.crop((
            int(round(crop['x'] * upscale * -1, 0)),
            int(round(crop['y'] * upscale * -1, 0)),
            int(round((crop['x'] - min_size) * upscale * -1, 0)),
            int(round((crop['y'] - min_size) * upscale * -1, 0)),
        ))

    store.store_avatar(user, cropped_image)
    if source == 'tmp':
        store.store_original_avatar(user)

    return crop
Exemple #8
0
def crop_source_image(user, source, crop):
    image = Image.open(store.avatar_file_path(user, source))
    crop = clean_crop(image, crop)

    min_size = max(settings.MISAGO_AVATARS_SIZES)
    if image.size[0] == min_size and image.size[0] == image.size[1]:
        cropped_image = image
    else:
        upscale = 1.0 / crop["zoom"]
        cropped_image = image.crop(
            (
                int(round(crop["x"] * upscale * -1, 0)),
                int(round(crop["y"] * upscale * -1, 0)),
                int(round((crop["x"] - min_size) * upscale * -1, 0)),
                int(round((crop["y"] - min_size) * upscale * -1, 0)),
            )
        )

    store.store_avatar(user, cropped_image)
    if source == "tmp":
        store.store_original_avatar(user)

    return crop