コード例 #1
0
    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 test_fork_wall(self):
        user = create_user("goga")
        source_wall = self.wall_service.create_wall(user=user)

        image_file = get_django_file("ubuntu_grunge_800x600.jpg")
        self.image_service.create_image(user, source_wall, image_file, 0, 0)
        image_file = get_django_file("ubuntu_portrait.jpg")
        self.image_service.create_image(user, source_wall, image_file, 100, 200)
        wall_data = Wall(id=source_wall.id, title="Hello babies")
        source_wall = self.wall_service.update_wall(user, wall_data)

        forker = create_user("forker")
        forked_wall = self.wall_service.fork_wall(forker, source_wall.id)

        self.assertNotEqual(source_wall.id, forked_wall.id)
        self.assertEqual(source_wall.title, forked_wall.title)
        self.assertEqual(source_wall.owner.id, user.id)
        self.assertEqual(forked_wall.owner.id, forker.id)

        source_images = self.image_service.get_wall_images(user, source_wall.id)
        forked_images = self.image_service.get_wall_images(forker, forked_wall.id)
        self.assertEqual(len(source_images), len(forked_images))

        for i in xrange(len(source_images)):
            self.assertNotEqual(source_images[i].wall.id, forked_images[i].wall.id)
            self.assertNotEqual(source_images[i].id, forked_images[i].id)
            self.assertNotEqual(source_images[i].created_by.id, forked_images[i].created_by.id)

            self.assertEqual(source_images[i].x, forked_images[i].x)
            self.assertEqual(source_images[i].y, forked_images[i].y)
            self.assertEqual(source_images[i].width, forked_images[i].width)
            self.assertEqual(source_images[i].height, forked_images[i].height)
            self.assertEqual(source_images[i].image_file.name, forked_images[i].image_file.name)
コード例 #3
0
ファイル: test_wall_facade.py プロジェクト: aert/lemidora
    def test_upload_images(self):
        user = create_user('dojo')
        wall = self.wall_service.create_wall(user)

        images = [
            get_django_file('ubuntu_grunge_800x600.jpg'),
            get_django_file('lviv_photo_portrait.jpg'),
            get_django_file('ubuntu_grunge_800x600.png'),
            get_django_file('01.gif'),
            get_django_file(u"very_long_name_very_longvery_Привiт Чуваки! Cлава Українi !long_name_very_long.gif"),
        ]

        self.facade.upload_images(user, wall.hash, 10, 200, images)

        images = self.image_service.get_wall_images(user, wall.id)
        self.assertEqual(len(images), 5)
        self.assertEqual(images[0].x, 10)
        self.assertEqual(images[0].y, 200)
        self.assertTrue('ubuntu_grunge_800x600.jpg' in images[0].image_file.name)

        self.assertEqual(images[1].x, 10 + WallImageService.DEFAULT_X_OFFSET)
        self.assertEqual(images[1].y, 200 + WallImageService.DEFAULT_Y_OFFSET)
        self.assertTrue('lviv_photo_portrait.jpg' in images[1].image_file.name)

        self.assertEqual(images[2].x, 10 + WallImageService.DEFAULT_X_OFFSET * 2)
        self.assertEqual(images[2].y, 200 + WallImageService.DEFAULT_Y_OFFSET * 2)
        self.assertTrue('ubuntu_grunge_800x600.png' in images[2].image_file.name)

        self.assertEqual(images[3].x, 10 + WallImageService.DEFAULT_X_OFFSET * 3)
        self.assertEqual(images[3].y, 200  + WallImageService.DEFAULT_Y_OFFSET * 3)
        self.assertTrue('01.gif' in images[3].image_file.name)

        self.assertEqual(images[4].x, 10 + WallImageService.DEFAULT_X_OFFSET * 4)
        self.assertEqual(images[4].y, 200  + WallImageService.DEFAULT_Y_OFFSET * 4)
        self.assertTrue(u"very_long_name_very_longvery_Привiт Чуваки! Cлава Українi !long_name_very_long.gif" in images[4].image_file.name)
コード例 #4
0
    def test_create_wall(self):
        user = create_user("goga")
        wall = self.wall_service.create_wall(user=user)

        self.assertIsInstance(wall, Wall)
        self.assertIsNotNone(wall.hash)
        self.assertEqual(wall.owner, user)
コード例 #5
0
ファイル: test_wall_facade.py プロジェクト: aert/lemidora
    def test_delete_image(self):
        user = create_user('dojo')
        wall = self.wall_service.create_wall(user)

        image_data = get_django_file('ubuntu_grunge_800x600.jpg')
        image = self.image_service.create_image(user, wall, image_data, 0, 0)

        self.facade.delete_image(user, wall.hash, image.id)
        self.assertRaises(WallImage.DoesNotExist, self.image_service.get_image, user, image.id)
コード例 #6
0
    def test_update_wall(self):
        user = create_user("goga")
        wall = self.wall_service.create_wall(user=user)

        wall_data = Wall(id=wall.id, title="Hello babies")
        wall = self.wall_service.update_wall(user, wall_data)

        db_wall = self.wall_service.get_wall(user, wall.id)

        self.assertIsInstance(wall, Wall)
        self.assertIsNotNone(wall.hash)
        self.assertEqual(db_wall.owner, user)
        self.assertEqual(db_wall.title, "Hello babies")
コード例 #7
0
    def test_create_check_limit(self):
        user = create_user("dojo")
        wall = self.wall_service.create_wall(user)

        saved_limit = WallImageService.WALL_UPLOAD_LIMIT
        WallImageService.WALL_UPLOAD_LIMIT = 3

        self.image_service.create_image(user, wall, get_django_file("ubuntu_grunge_800x600.jpg"), 0, 0)
        self.image_service.create_image(user, wall, get_django_file("lviv_photo_portrait.jpg"), 0, 0)
        self.image_service.create_image(user, wall, get_django_file("ubuntu_grunge_800x600.png"), 0, 0)
        self.assertRaises(LimitError, self.image_service.create_image, user, wall, get_django_file("01.gif"), 0, 0)

        WallImageService.WALL_UPLOAD_LIMIT = saved_limit
コード例 #8
0
ファイル: test_wall_facade.py プロジェクト: aert/lemidora
    def test_upload_images_broken(self):
        user = create_user('dojo')
        wall = self.wall_service.create_wall(user)

        images = [
            get_django_file('ubuntu_grunge_800x600.jpg'),
            get_django_file('lviv_broken.jpg'),
            get_django_file('broken_txt.jpg'),
        ]

        self.facade.upload_images(user, wall.hash, 10, 200, images)

        images = self.image_service.get_wall_images(user, wall.id)
        self.assertEqual(len(images), 1)
        self.assertEqual(images[0].x, 10)
        self.assertEqual(images[0].y, 200)
        self.assertTrue('ubuntu_grunge_800x600.jpg' in images[0].image_file.name)
コード例 #9
0
ファイル: test_wall_facade.py プロジェクト: aert/lemidora
    def test_upload_images_check_limit(self):
        user = create_user('dojo')
        wall = self.wall_service.create_wall(user)

        saved_limit = WallImageService.WALL_UPLOAD_LIMIT
        WallImageService.WALL_UPLOAD_LIMIT = 3
        images = [
            get_django_file('ubuntu_grunge_800x600.jpg'),
            get_django_file('lviv_photo_portrait.jpg'),
            get_django_file('ubuntu_grunge_800x600.png'),
            get_django_file('01.gif'),
            get_django_file(u"very_long_name_very_longvery_Привiт Чуваки! Cлава Українi !long_name_very_long.gif"),
            ]

        self.facade.upload_images(user, wall.hash, 10, 200, images)
        images = self.image_service.get_wall_images(user, wall.id)
        self.assertEqual(len(images), 3)

        WallImageService.WALL_UPLOAD_LIMIT = saved_limit
コード例 #10
0
    def test_get_geometry(self):
        user = create_user("dojo")
        wall = self.wall_service.create_wall(user)

        image_data = get_django_file("ubuntu_grunge_800x600.jpg")

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

        width, height = self.image_service._get_geometry(image.image_file)
        self.assertEqual(width, WallImageService.DEFAULT_WIDTH)
        self.assertEqual(height, 240)

        image_data = get_django_file("ubuntu_portrait.jpg")

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

        width, height = self.image_service._get_geometry(image.image_file)
        self.assertEqual(height, WallImageService.DEFAULT_HEIGHT)
        self.assertEqual(width, 242)
コード例 #11
0
    def test_create_image(self):
        user = create_user("dojo")
        wall = self.wall_service.create_wall(user)

        image_file = get_django_file("ubuntu_grunge_800x600.jpg")

        image = self.image_service.create_image(user, wall, image_file, 0, 0)
        image = self.image_service.get_image(user, image.id)

        self.assertIsInstance(image, WallImage)
        self.assertEqual(image.created_by, user)
        self.assertEqual(image.updated_by, user)
        self.assertEqual(image.width, WallImageService.DEFAULT_WIDTH)
        self.assertEqual(image.height, 240)
        self.assertTrue("ubuntu_grunge_800x600.jpg" in image.image_file.name)
        self.assertIsInstance(image.thumbnail, ImageFile)
        self.assertTrue(hasattr(image, "thumbnail"))
        self.assertEqual(image.thumbnail.width, WallImageService.DEFAULT_WIDTH)
        self.assertEqual(image.thumbnail.height, 240)
コード例 #12
0
ファイル: test_wall_facade.py プロジェクト: aert/lemidora
    def test_update_image_full_params_set(self):
        user = create_user('dojo')
        wall = self.wall_service.create_wall(user)

        image_data = get_django_file('ubuntu_grunge_800x600.jpg')
        image = self.image_service.create_image(user, wall, image_data, 0, 0)

        self.facade.update_image(user, wall.hash, image.id, RequestMock(dict(
            x=10, y=20, rotation=200, width=900, height=800, z=-1, title="Hello babies"
        )))
        image = self.image_service.get_image(user, image.id)

        self.assertEqual(image.title, 'Hello babies')
        self.assertEqual(image.x, 10)
        self.assertEqual(image.y, 20)
        self.assertEqual(image.z, -1)
        self.assertEqual(image.rotation, 200)
        self.assertEqual(image.width, 900)
        self.assertEqual(image.height, 800)
        self.assertEqual(image.thumbnail.width, 900)
        self.assertEqual(image.thumbnail.height, 800)