def testDefThumb(self): it = ImageType(ImageType.TARGET_NONE) it.max_thumb_height = 345 it.max_thumb_width = 234 session.add(it) session.commit() ret = it.mkDefThumb() self.assertEquals(ret, True) self.assert_(it.def_thumb_path) fp = FileProcess() self.assertNotEquals(it.def_thumb_path[0], '/') info = ImageInfo(fp.fullPath(it.def_thumb_path)) self.assertEquals(info.is_image(), True) self.assertEquals(info.height, 345) self.assertEquals(info.width, 234) session.delete(it) session.commit()
def testAddImageToDb(self): it = ImageType(ImageType.TARGET_NONE) it.max_thumb_height = 50 it.max_thumb_width = 150 it.base_dir = 'b/a' it.transform_type = ImageTransform.STD session.add(it) img = Image(it) ret = img.uploadFromFile(fileInTestDir('img/test.jpg')) self.assert_(ret) session.add(img) session.commit() old_thumb_path = img.thumb_path old_image_path = img.image_path self.assert_(os.path.isfile(FileProcess.fullPath(img.thumb_path))) self.assert_(os.path.isfile(FileProcess.fullPath(img.image_path))) split_p = img.thumb_path.split(os.path.sep) self.assert_('b' in split_p) self.assert_('a' in split_p) self.assert_('img' in split_p) split_p = img.image_path.split(os.path.sep) self.assert_('b' in split_p) self.assert_('a' in split_p) self.assert_('img' in split_p) self.assert_(img.thumb_width <= 150) self.assert_(img.thumb_height <= 50) self.assertEquals(img.content_type, ImageInfo.JPEG) self.assertEquals(img.image_width, 418) self.assertEquals(img.image_height, 604) ret = img.uploadFromFile(fileInTestDir('img/test.jpg')) self.assert_(ret) self.assert_(not os.path.isfile(FileProcess.fullPath(old_thumb_path))) self.assert_(not os.path.isfile(FileProcess.fullPath(old_image_path))) session.delete(img) session.delete(it) session.commit()