def testFileCopy(self): write_str = 'Temp file' source_file = mkTempFile(write_str) fp = FileProcess() target_file = fp.copyFile(source_file, ext='.txt') full_target_path = fp.fullPath(target_file) s = getFileContent(full_target_path) self.assertEquals(s, write_str) (_, ext) = os.path.splitext(target_file) self.assertEquals(ext, '.txt') os.unlink(source_file)
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()
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 set_event_listner(target, value, oldvalue, initiator): if oldvalue: full_path = FileProcess.fullPath(oldvalue) if (os.path.isfile(full_path)): os.unlink(full_path)