def do_upload():
    upload     = request.files.get('upload')
    url = request.forms.get('url')
    content_type =  upload.content_type 
    name, ext = os.path.splitext(upload.filename)
    save_path = '/tmp'
    upload.filename = str(abs(hash(name)))+ ext
    upload.save(save_path,overwrite=True) # appends upload.filename automatically
    fileHandler = FileHandler(5)
    fileId,physicalName = fileHandler.save('/tmp/'+upload.filename ,url)
    return physicalName
class TestHander(unittest.TestCase):
    dbHandler = None;
    fileHandler = None;
    
    def setUp(self):
        self.dbHandler = DBHandler()
        self.fileHandler = FileHandler(5)

    def testFileHanderSave(self,url = 'aa'):
        path = '/tmp/license.txt'
        import os
        if not os.path.isfile(path):
           os.mknod(path)
        fileId,physicalName = self.fileHandler.save(path,url)
        return fileId,physicalName
    
    def testGetFilePathByPhysicalName(self):
        fileId,physicalName = self.testFileHanderSave()
        path = self.fileHandler.getFilePathByDiskName(physicalName)
        print 'path :'+ path
    
    def testGetFiletypeByURL(self):
        url = 'http://www.abc.com'
        self.testFileHanderSave(url)
        print 'file type is :' + self.fileHandler.getTypeByUrl(url)
        
    def testGetFileByID(self):
        fileId,physicalName = self.testFileHanderSave()
        opendFile = self.fileHandler.getFileByID(fileId)
         
    def testGetFiletypeByID(self):
        fileId,physicalName = self.testFileHanderSave()
        print self.fileHandler.getTypeByID(fileId)

    def testGetTotalFileCount(self):
        num = self.fileHandler.getTotalFileCount()
        print "file count : " + str(num)

    def testExecute(self):
        sql = 'select * from files'
        rows = self.dbHandler.excute(sql)