示例#1
0
	def create_image_instance(self, **kwargs):
		image = create_image(**kwargs)

		instance = ImageFieldModel()
		instance.image = SimpleUploadedFile(image.name, image.read())
		instance.save()
		return instance
示例#2
0
    def create_image_instance(self, **kwargs):
        image = create_image(**kwargs)

        instance = ImageFieldModel()
        instance.image = SimpleUploadedFile(image.name, image.read())
        instance.save()
        return instance
示例#3
0
	def test_reupload(self):
		instance = self.create_image_instance(size=(128, 128))
		path1 = instance.image.path
		path1_thumbnail = instance.image_thumbnail.path #pylint: disable=no-member

		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 = instance.image_thumbnail.path #pylint: disable=no-member

		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)