def test_update_image(self):
        user = create_user("dojo")
        wall = self.wall_service.create_wall(user)

        image_data = get_django_file("ubuntu_grunge_800x600.jpg")

        old_image = self.image_service.create_image(user, wall, image_data, 0, 0)

        image_data = WallImage(
            id=old_image.id, x=4.2, y=2.2, z=2, rotation=22.2, width=500, height=700, title="I am swimming in the woods"
        )
        image_data.wall_id = wall.id

        updater = create_user("updater")
        image = self.image_service.update_image(updater, image_data)
        image = self.image_service.get_image(user, image.id)

        self.assertIsInstance(image, WallImage)
        self.assertEqual(image.created_by, user)
        self.assertEqual(image.updated_by, updater)
        self.assertEqual(image.created_date, old_image.created_date)

        self.assertEqual(image.image_file.name, old_image.image_file.name)

        self.assertEqual(image.width, 500)
        self.assertEqual(image.height, 700)
        self.assertEqual(image.x, 4.2)
        self.assertEqual(image.y, 2.2)
        self.assertEqual(image.rotation, 22.2)
        self.assertEqual(image.title, "I am swimming in the woods")

        self.assertIsInstance(image.thumbnail, ImageFile)
        self.assertTrue(hasattr(image, "thumbnail"))
        self.assertEqual(image.thumbnail.width, 500)
        self.assertEqual(image.thumbnail.height, 700)
示例#2
0
    def create_image(self, user, wall, image_file, x, y):
        """
        Create list of images
        :param user: User instance
        :param wall: Wall instance
        :param image_file: image file instance
        :param x: X coordinate
        :param y: Y coordinate
        """
        self.check_is_upload_allowed(wall_id=wall.id)
        image = WallImage()
        try:
            image = WallImage()
            self.__update_image_system_data(user, image, wall, image_file)

            base_z = WallImage.objects.filter(wall=wall).aggregate(Max('z')).values().pop() or 0

            image.z = base_z + 1
            image.x = x
            image.y = y

            image.width = self.DEFAULT_WIDTH
            image.height = self.DEFAULT_HEIGHT
#            print "Init: %sx%s" % (str(image.width), str(image.height))
            image.save()

            image.width, image.height = self._get_geometry(image.image_file)
#            print "Geometry: %sx%s" % (str(image.width), str(image.height))

            self._add_dynamics(image)
            image.width = image.thumbnail.width
            image.height = image.thumbnail.height
#            print "Th: %sx%s" % (str(image.width), str(image.height))
            image.save()
        except IOError, e:
            # This is the broken image case
            # delete should also remove the file?
            image.delete()
            raise e
示例#3
0
 def fork_image(self, user, forked_wall, source_image):
     forked_image = WallImage(wall=forked_wall, image_file=source_image.image_file)
     self.__update_image_user_data(forked_image, source_image)
     self.__update_image_system_data(user, forked_image, forked_wall, source_image.image_file)
     forked_image.save()
     return forked_image