当前位置: 首页>>代码示例>>Python>>正文


Python site_helper.getDBHelper函数代码示例

本文整理汇总了Python中site_helper.getDBHelper函数的典型用法代码示例。如果您正苦于以下问题:Python getDBHelper函数的具体用法?Python getDBHelper怎么用?Python getDBHelper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getDBHelper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_delete

 def test_delete(self):
     '''delete的同时要删除相关数据'''
     category_model = self.model
     model_model = Model()
     new_category_id = category_model.insert(test_helper.storage({'title':'cat1'}))
     new_model_id = model_model.insert(test_helper.storage({'Categoryid':new_category_id}))
     inserted_model = getDBHelper().fetchOne('select * from '+model_model.table_name+' where '+model_model.primary_key+'=%s',new_model_id)
     self.assertTrue(inserted_model is not None)
     category_model.delete(new_category_id)
     inserted_model = getDBHelper().fetchOne('select * from '+model_model.table_name+' where '+model_model.primary_key+'=%s',new_model_id)
     self.assertTrue(inserted_model is None)
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:11,代码来源:TestCategory.py

示例2: test_insert

    def test_insert(self):
        '''插入的数据, 如果type表中没有相关数据, 要先插入type'''
        content_model = self.model
        data = test_helper.storage({'page':'brand-list', 'content':'brandshow', 'model_name':'Brand', 'model_id':1, })

        exists_content = getDBHelper().fetchOne("select * from PageContentType where page='brand-list' and content='brandshow' ")
        self.assertEqual(exists_content, None)

        new_id = content_model.insert(data)

        exists_content = getDBHelper().fetchOne("select * from PageContentType where page='brand-list' and content='brandshow' ")
        self.assertEqual(exists_content.model_name, 'Brand')
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:12,代码来源:TestPageContent.py

示例3: test_update

 def test_update(self):
     '''Image的update函数只能更新数据库表的值,而不创建、删除或修改图片文件。 '''
     image_model = self.image_model
     data = test_helper.storage({'imagefile':{'value':'image_file_content','filename':'c://my files/sdjl.png'},'itemtype':'AImage','itemid':1017,'alt':' image alt ',})
     new_image_id = image_model.insert(data)
     update_data = test_helper.storage({'imagefile':{'value':'image_file_content2','filename':'c://my files/sdjl2.png'},'itemtype':'AImage2','itemid':10172,'alt':' image alt2 ',})
     image_model.update(new_image_id,update_data)
     updated_image = site_helper.getDBHelper().fetchOne('select uri,itemtype,itemid,alt from '+image_model.table_name+' where '+image_model.primary_key+'=%s',new_image_id)
     self.assertEqual(updated_image.itemtype,'AImage2')
     self.assertEqual(updated_image.itemid,10172)
     self.assertEqual(updated_image.alt,' image alt2 ') # don't strip
     self.assertEqual(updated_image.uri,'%s%d.png' % (site_helper.config.UPLOAD_IMAGE_URL, new_image_id)) # has the old image uri
     self.assertTrue(not os.path.exists(site_helper.config.UPLOAD_IMAGE_PATH+'/%d.png' % (new_image_id+1))) # don't create new image file
     new_image2 = site_helper.getDBHelper().fetchOne('select uri,itemtype,itemid,alt from '+image_model.table_name+' where '+image_model.primary_key+'=%s',new_image_id+1)
     self.assertTrue(new_image2 is None) # don't insert new image data
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:15,代码来源:TestImage.py

示例4: test_getImageid

 def test_getImageid(self):
     imglink_model = self.model
     image_model = Image()
     data = test_helper.storage({'imagefile':{'value':'imagefile_content', 'filename':'c://sdjl/lyh.png'}})
     new_imglink_id = imglink_model.insert(data) # insert imglink
     new_image_id = getDBHelper().fetchFirst('select max('+image_model.primary_key+') from '+image_model.table_name)
     self.assertEqual(imglink_model.getImageid(new_imglink_id), new_image_id)
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:7,代码来源:TestImgLink.py

示例5: test_setItemID

 def test_setItemID(self):
     image_model = self.image_model
     data = test_helper.storage({'imagefile':{'value':'image_file_content','filename':'c://my files/sdjl.png'},'itemtype':'AImage','itemid':1017,'alt':' image alt ',})
     new_image_id = image_model.insert(data)
     image_model.setItemID(new_image_id,801)
     new_image = site_helper.getDBHelper().fetchOne('select uri,itemtype,itemid,alt from '+image_model.table_name+' where '+image_model.primary_key+'=%s',new_image_id)
     self.assertEqual(new_image.itemid, 801)
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:7,代码来源:TestImage.py

示例6: rebulidTestDataBase

def rebulidTestDataBase():
    from tool import init_database
    assert sh.config.DB_DATABASE.endswith('_test'), u'你使用正式数据库来测试?'
    db = sh.getDBHelper()
    for table_name in db.fetchSomeFirst('show tables', ignore_assert=True):
        db.executeQuery('DROP TABLE %s' % table_name)
    init_database.initTables()
开发者ID:ajiexw,项目名称:zarkpy,代码行数:7,代码来源:test.py

示例7: __getTotal

 def __getTotal(self, select):
     db = sh.getDBHelper()
     if " group by " in select.lower():
         return len(db.fetchSomeFirst(select))
     else:
         form_key = " from " if " from " in select else " FROM "
         return db.fetchFirst("select count(*) from " + select.partition(form_key)[2])
开发者ID:kevinhao,项目名称:zarkpy,代码行数:7,代码来源:ReportForms.py

示例8: POST

    def POST(self):
        i = web.input()
        subject = i.get('subject', '').encode('utf-8','ignore').replace('"','')
        from_addr = i.get('from_addr', '').encode('utf-8','ignore').replace('"','')
        to = i.get('to', '').encode('utf-8','ignore')
        content = i.get('content', '').encode('utf-8','ignore')
        now = time.localtime()

        #content_file_name = os.path.join(CONTENT_DIR, '%d_%d_%d_%d_%d_%d' % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec) )

        #f = open(content_file_name,'w')
        #f.write(content)
        #f.close()

        if i.get('to_all','') == 'on':
            db = site_helper.getDBHelper()
            receivers = [i.email for i in db.fetchSome('select email from User')]
        else:
            receivers = [i.strip().replace('"','') for i in to.split('\n')]
        
        #sends = []
        for receiver in receivers:
            if receiver:
                #sends.append('mail -r "%s" -s "%s" "%s" < %s' % (from_addr, subject, receiver, content_file_name))
                try:
                    self.send_html_email(from_addr, receiver, subject, content)
                except SMTPRecipientsRefused:
                    pass
        #os.system('\n'.join(sends))

        return page_helper.refresh()
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:31,代码来源:SendMail.py

示例9: test_getInstance

 def test_getInstance(self):
     '''ModelFactory可以根据class名和新表名动态生成新model,此新model类似继承了class,但使用了新的table_name, 因此它会链接另外一个数据表,而和原class的数据互不影响。'''
     test_helper.dropTable('your_table')
     new_image = ModelFactory.getInstance('Image','your_table')
     self.assertTrue(isinstance(new_image, model.Image))
     self.assertTrue(not site_helper.getDBHelper().isTableExists('your_table'))
     self.assertEqual(new_image.table_name, 'your_table')
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:7,代码来源:TestFactory.py

示例10: test_getAll

 def test_getAll(self):
     '''getAll函数返回的数据要包含uri属性,表示图片的uri'''
     imglink_model = self.model
     image_model = Image()
     data = test_helper.storage({'imagefile':{'value':'imagefile_content', 'filename':'c://sdjl/lyh.png'}})
     new_imglink_id = imglink_model.insert(data) # insert imglink
     new_imglinks = imglink_model.getAll()
     new_image_id = getDBHelper().fetchFirst('select max('+image_model.primary_key+') from '+image_model.table_name)
     self.assertEqual(new_imglinks[0].uri, site_helper.config.UPLOAD_IMAGE_URL+'%d.png' % new_image_id)
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:9,代码来源:TestImgLink.py

示例11: test_update

    def test_update(self):
        '''update时如果有imagefile,则新建图片数据与文件给imglink,且不删除老数据与文件'''
        imglink_model = self.model
        image_model = Image()
        data = test_helper.storage({'imagefile':{'value':'imagefile_content', 'filename':'c://sdjl/lyh.png'}})

        new_imglink_id = imglink_model.insert(data) # insert imglink
        first_image_id = getDBHelper().fetchFirst('select max('+image_model.primary_key+') from '+image_model.table_name)

        imglink_model.update(new_imglink_id, data) # update imglink
        second_image = getDBHelper().fetchOne('select * from '+image_model.table_name+' where '+image_model.primary_key+'=%s', first_image_id+1)

        self.assertTrue(second_image is not None)
        self.assertTrue(os.path.exists(site_helper.config.UPLOAD_IMAGE_PATH+'/%d.png' % (second_image.get(image_model.primary_key))))

        first_image = getDBHelper().fetchOne('select * from '+image_model.table_name+' where '+image_model.primary_key+'=%s', first_image_id)
        self.assertTrue(first_image is not None)
        self.assertTrue(os.path.exists(site_helper.config.UPLOAD_IMAGE_PATH+'/%d.png' % (first_image.get(image_model.primary_key))))
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:18,代码来源:TestImgLink.py

示例12: test_delete

    def test_delete(self):
        '''删除的时候要级联删除MakeupHasAttribute'''
        makeup_model = self.model
        data = test_helper.storage({'name':'面膜', 'enname':'mianmo', 'brand':'sdjlbrand', 'category':'good', 'score':'5.5', 'attributeids':[10,1,1017], 'release_time':'2011-10-17', 'intro':'haobao','cover_url':'/img/makeupreserve/cover/1.jpg' })

        new_makeup_id = makeup_model.insert(data)
        makeup_model.delete(new_makeup_id)
        db_helper = getDBHelper()
        self.assertEqual(db_helper.fetchSome('select * from MakeupHasAttribute where Makeupid=%s', new_makeup_id), [])
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:9,代码来源:TestMakeup.py

示例13: test_update_saveimage

 def test_update_saveimage(self):
     '''更新的时候要替换原来的图片文件'''
     makeup_model = self.model
     db_helper = getDBHelper()
     data = test_helper.storage({'name':'面膜', 'cover_url':'/img/makeupreserve/cover/1.jpg' })
     data.imagefile = site_helper.storage({'filename':'c://sdjl.jpg', 'value':'liuyonghui'})
     new_makeup_id  = makeup_model.insert(data)
     data.imagefile = site_helper.storage({'filename':'c://wx.jpg', 'value':'wangxuan'})
     makeup_model.update(new_makeup_id, data)
     self.assertEqual(open('%s%d.jpg' % (site_helper.config.MAKEUP_COVER_PATH, new_makeup_id)).read().strip(), 'wangxuan')
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:10,代码来源:TestMakeup.py

示例14: test_getModelidsByTypeid

    def test_getModelidsByTypeid(self):
        content_model = self.model
        data = test_helper.storage({'page':'brand-list', 'content':'brandshow', 'model_name':'Brand', 'model_id':1, })

        new_id = content_model.insert(data)
        type_id = getDBHelper().fetchFirst("select PageContentTypeid from PageContentType")

        contents = content_model.getModelidsByTypeid(type_id)
        self.assertEqual(len(contents), 1)
        self.assertEqual(contents[0], 1)
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:10,代码来源:TestPageContent.py

示例15: test_insert

 def test_insert(self):
     '''保存图片, 验证加密方式, 生日格式'''
     user_model = self.model
     data = test_helper.storage({'username':'sdjl', 'email':'[email protected]', 'password':'sdjllyh', 'birthday':'1985-10-17'})
     data.imagefile = site_helper.storage({'filename':'sdjl.jpg', 'value':'shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!'})
     new_id   = user_model.insert(data)
     new_user = getDBHelper().fetchOne('select * from '+user_model.table_name+' where '+user_model.primary_key+'=%s',new_id)
     self.assertEqual(new_user.password, 'dab61a7c59b7d5f2e9fd22c85f6aa03c') # 不允许改变加密方式
     self.assertEqual(new_user.cover_url, '%s%d.jpg' % (site_helper.config.USER_COVER_URL, new_id)) # 保存图片
     self.assertEqual(open('%s%d.jpg' % (site_helper.config.USER_COVER_PATH, new_id)).read().strip(), 'shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!shuai!')
     self.assertEqual(new_user.birthday, date(1985,10,17) )
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:11,代码来源:TestUser.py


注:本文中的site_helper.getDBHelper函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。