Пример #1
0
	def test_rename(self):
		instance = self.create_image_instance(size=(128, 128))
		path1 = instance.image.path
		thumbnail = generate_thumbnail(instance.image, size=(32, 32))
		path1_thumbnail = thumbnail.path
		path1_thumbnail_url = thumbnail.url
		path1_thumbnail_size = thumbnail.size
		instance.pk = 2
		instance.save()
		instance = ImageFieldModel.objects.get(pk=instance.pk)
		path2 = instance.image.path
		thumbnail = generate_thumbnail(instance.image, size=(32, 32))
		path2_thumbnail = thumbnail.path
		path2_thumbnail_url = thumbnail.url
		path2_thumbnail_size = thumbnail.size

		self.assertNotEquals(path1, path2)
		self.assertNotEquals(path1_thumbnail_url, path2_thumbnail_url)
		self.assertEquals(path1_thumbnail_size, path2_thumbnail_size)
		self.assertFalse(os.path.exists(path1))
		self.assertFalse(os.path.exists(path1_thumbnail))
		self.assertTrue(os.path.exists(path2))
		self.assertTrue(os.path.exists(path2_thumbnail))

		self.destroy_image_instance(instance)
Пример #2
0
    def test_rename(self):
        instance = self.create_image_instance(size=(128, 128))
        path1 = instance.image.path
        thumbnail = generate_thumbnail(instance.image, size=(32, 32))
        path1_thumbnail = thumbnail.path
        path1_thumbnail_url = thumbnail.url
        path1_thumbnail_size = thumbnail.size
        instance.pk = 2
        instance.save()
        instance = ImageFieldModel.objects.get(pk=instance.pk)
        path2 = instance.image.path
        thumbnail = generate_thumbnail(instance.image, size=(32, 32))
        path2_thumbnail = thumbnail.path
        path2_thumbnail_url = thumbnail.url
        path2_thumbnail_size = thumbnail.size

        self.assertNotEqual(path1, path2)
        self.assertNotEqual(path1_thumbnail_url, path2_thumbnail_url)
        self.assertEqual(path1_thumbnail_size, path2_thumbnail_size)
        self.assertFalse(os.path.exists(path1))
        self.assertFalse(os.path.exists(path1_thumbnail))
        self.assertTrue(os.path.exists(path2))
        self.assertTrue(os.path.exists(path2_thumbnail))

        self.destroy_image_instance(instance)
Пример #3
0
	def test_reupload(self):
		instance = self.create_image_instance(size=(128, 128))
		path1 = instance.image.path
		path1_thumbnail = generate_thumbnail(instance.image, size=(32, 32)).path

		instance = ImageFieldModel.objects.get(pk=instance.pk)
		image = create_image(size=(128, 128), filetype='jpeg', basename='new')
		instance.image = SimpleUploadedFile(image.name, image.read())
		instance.save()

		path2 = instance.image.path
		path2_thumbnail = generate_thumbnail(instance.image, size=(32, 32)).path

		self.assertNotEquals(path1, path2)
		self.assertNotEquals(path1_thumbnail, path2_thumbnail)
		self.assertFalse(os.path.exists(path1))
		self.assertFalse(os.path.exists(path1_thumbnail))
		self.assertTrue(os.path.exists(path2))
		self.assertTrue(os.path.exists(path2_thumbnail))

		self.destroy_image_instance(instance)
Пример #4
0
    def test_reupload(self):
        instance = self.create_image_instance(size=(128, 128))
        path1 = instance.image.path
        path1_thumbnail = generate_thumbnail(instance.image,
                                             size=(32, 32)).path

        instance = ImageFieldModel.objects.get(pk=instance.pk)
        image = create_image(size=(128, 128), filetype='jpeg', basename='new')
        instance.image = SimpleUploadedFile(image.name, image.read())
        instance.save()

        path2 = instance.image.path
        path2_thumbnail = generate_thumbnail(instance.image,
                                             size=(32, 32)).path

        self.assertNotEqual(path1, path2)
        self.assertNotEqual(path1_thumbnail, path2_thumbnail)
        self.assertFalse(os.path.exists(path1))
        self.assertFalse(os.path.exists(path1_thumbnail))
        self.assertTrue(os.path.exists(path2))
        self.assertTrue(os.path.exists(path2_thumbnail))

        self.destroy_image_instance(instance)