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


Python base.Database类代码示例

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


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

示例1: test_add_torrent

 def test_add_torrent(self):
     cleanup = Cleanup()
     session = Database.create_sqlalchemy_session_push(cleanup)
     
     user.User.add_user_account(session=session, user_id="uuuu0", password="pppp0")
     self.assertEqual(1,HiFile._database.add_torrent(session,"uuuu0","0123456789012345678901234567890123456789","name",123))
     self.assertEqual(2,HiFile._database.add_torrent(session,"uuuu0","0123456789012345678901234567890123456789","name",123))
     self.assertEqual(3,HiFile._database.add_torrent(session,"uuuu0","0123456789012345678901234567890123456789","name",123))
     
     self.assertEqual(HiFile._database.list_user_torrent(session,"uuuu0"),[ \
         { \
             "torrent_id":3, \
             "user_id":"uuuu0", \
             "info_hash_bin":"0123456789012345678901234567890123456789", \
             "name":"name", \
             "size":123, \
         }, \
         { \
             "torrent_id":2, \
             "user_id":"uuuu0", \
             "info_hash_bin":"0123456789012345678901234567890123456789", \
             "name":"name", \
             "size":123, \
         }, \
         { \
             "torrent_id":1, \
             "user_id":"uuuu0", \
             "info_hash_bin":"0123456789012345678901234567890123456789", \
             "name":"name", \
             "size":123, \
         }, \
     ])
     
     self.assertEqual(HiFile._database.list_user_torrent(session,"uuuu1"),[])
开发者ID:luzi82,项目名称:HiSocial,代码行数:34,代码来源:hifile.py

示例2: clean

def clean():
    trace_up("Clean database")
    db = Database.connect_mysqldb()
    dirty = True
    while dirty:
        dirty = False
        db.query("SHOW TABLES")
        result = db.store_result()
        while True:
            row = result.fetch_row()
            if row == None:break
            if len(row)==0:break
            dirty = True
            for i in row:
                table_name = i[0]
                trace("Remove table: "+table_name)
                try:
                    db.query("DROP TABLE `"+table_name+"`")
                except _mysql_exceptions.IntegrityError:
                    trace("fail, retry later")
    db.commit()
    db.close()
    trace_down("done")
    
    trace_up("Clean filesystem")
    if os.path.isdir(core_config.DATA_FOLDER):
        data_folder=os.listdir(core_config.DATA_FOLDER)
        for i in data_folder:
            shutil.rmtree(core_config.DATA_FOLDER+"/"+i)
    trace_down("done")
开发者ID:luzi82,项目名称:HiSocial,代码行数:30,代码来源:_reset.py

示例3: test_owner

 def test_owner(self):
     cleanup = Cleanup()
     session = Database.create_sqlalchemy_session_push(cleanup)
     
     self.assertTrue(User.check_user_account_exist(session,_testcommon.OWNER_USERNAME))
     self.assertTrue(User.check_user_account_password(session,_testcommon.OWNER_USERNAME,_testcommon.OWNER_PASSWORD))
     self.assertTrue(UserGroup.get_group(session,_testcommon.OWNER_USERNAME),["owner"])
     self.assertTrue(Permission.get_user_permission(session, _testcommon.OWNER_USERNAME, "admin"))
开发者ID:luzi82,项目名称:HiSocial,代码行数:8,代码来源:user_reset.py

示例4: test_check_user_password

 def test_check_user_password(self):
     Session = sessionmaker(bind=Database.create_sqlalchemy_engine())
     session = Session()
     User.add_user_account(session=session, user_id="apple", password="apple_pass")
     self.assertTrue(User.check_user_account_password(session=session, user_id="apple", password="apple_pass"))
     self.assertFalse(User.check_user_account_password(session=session, user_id="apple", password="xxx"))
     self.assertFalse(User.check_user_account_password(session=session, user_id="xxx", password="xxx"))
     session.close()
开发者ID:luzi82,项目名称:HiSocial,代码行数:8,代码来源:User.py

示例5: test_get_name

 def test_get_name(self):
     cleanup = Cleanup()
     session = Database.create_sqlalchemy_session()
     cleanup.push(session.close)
     
     self.assertEqual(None, Group.get_name(session,"asdf"))
     Group.add(session,"asdf","qwer")
     self.assertEqual("qwer", Group.get_name(session,"asdf"))
开发者ID:luzi82,项目名称:HiSocial,代码行数:8,代码来源:Group.py

示例6: test_remove_user

    def test_remove_user(self):
        cleanup = Cleanup()
        session = Database.create_sqlalchemy_session_push(cleanup)

        self.assertFalse(User.check_user_account_exist(session=session, user_id="apple"))
        User.add_user_account(session=session, user_id="apple", password="apple_pass")
        self.assertTrue(User.check_user_account_exist(session=session, user_id="apple"))
        User.remove_user_account(session=session, user_id="apple")
        self.assertFalse(User.check_user_account_exist(session=session, user_id="apple"))
开发者ID:luzi82,项目名称:HiSocial,代码行数:9,代码来源:User.py

示例7: build

def build(install_config):
    if install_config != None:
        cleanup = Cleanup()
        session = Database.create_sqlalchemy_session_push(cleanup)
        
        Group.add(session, "owner", "Owner")
        GroupPermission.set(session, "owner", "admin", 99999999, True)

        User.add_user_account(session, install_config.OWNER_USERNAME, install_config.OWNER_PASSWORD)
        UserGroup.join(session, install_config.OWNER_USERNAME, "owner")
        session.commit()
开发者ID:luzi82,项目名称:HiSocial,代码行数:11,代码来源:_reset.py

示例8: test_api

    def test_api(self):
        cleanup = Cleanup()
        session = Database.create_sqlalchemy_session_push(cleanup)

        c = session.query(TrackerManager.XBT_FILES).count();
        self.assertEqual(c, 0)
        
        TrackerManager.add_hash(session, "01234567890123456789")
        
        c = session.query(TrackerManager.XBT_FILES).count();
        self.assertEqual(c, 1)
        
开发者ID:luzi82,项目名称:HiSocial,代码行数:11,代码来源:TrackerManager.py

示例9: test_session

 def test_session(self):
     cleanup = Cleanup()
     session = Database.create_sqlalchemy_session_push(cleanup)
     
     c = session.query(TrackerManager.XBT_FILES).count();
     self.assertEqual(c, 0)
     
     session.add(TrackerManager.XBT_FILES(info_hash="01234567890123456789",mtime=0,ctime=0))
     session.flush()
     
     c = session.query(TrackerManager.XBT_FILES).count();
     self.assertEqual(c, 1)
开发者ID:luzi82,项目名称:HiSocial,代码行数:12,代码来源:TrackerManager.py

示例10: command_guest_change_user_account_password

def command_guest_change_user_account_password(txt_user_id, txt_old_password, txt_new_password):
    cleanup = Cleanup()
    session = Database.create_sqlalchemy_session_push(cleanup)
    
    if not User.check_user_account_password(session, txt_user_id, txt_old_password):
        return hs_plugin.fail(reason="auth")
    
    User.change_password(session, txt_user_id, txt_new_password)
    session.commit()
    cleanup.clean_all();

    return hs_plugin.ok()
开发者ID:luzi82,项目名称:HiSocial,代码行数:12,代码来源:_hisocial.py

示例11: test_rename

    def test_rename(self):
        cleanup = Cleanup()
        session = Database.create_sqlalchemy_session()
        cleanup.push(session.close)
        
        Group.add(session,"asdf","qwer")
        self.assertEqual("qwer", Group.get_name(session,"asdf"))
        self.assertNotEqual("zxcv", Group.get_name(session,"asdf"))
        self.assertTrue(Group.rename(session,"asdf","zxcv"))
        self.assertEqual("zxcv", Group.get_name(session,"asdf"))
        self.assertNotEqual("qwer", Group.get_name(session,"asdf"))

        self.assertFalse(Group.rename(session,"xxx","xxx"))
开发者ID:luzi82,项目名称:HiSocial,代码行数:13,代码来源:Group.py

示例12: command_guest_generate_user_login_token

def command_guest_generate_user_login_token(txt_user_id, txt_password):
    '''
    Generate admin token
    '''
    cleanup = Cleanup()
    session = Database.create_sqlalchemy_session_push(cleanup)

    if not User.check_user_account_password(session, txt_user_id, txt_password):
        return hs_plugin.fail(reason="auth")

    cleanup.clean_all();

    token = UserLoginToken.generate_user_login_token(txt_user_id)
    
    return hs_plugin.ok(value=token)
开发者ID:luzi82,项目名称:HiSocial,代码行数:15,代码来源:_hisocial.py

示例13: command_user_remove_user_account

def command_user_remove_user_account(txtf_user_token, txt_user_id):
    cleanup = Cleanup()
    session = Database.create_sqlalchemy_session_push(cleanup)
    
    if not Permission.get_user_permission(session, txtf_user_token, "admin"):
        return hs_plugin.fail(reason="permission")
    
    if not User.check_user_account_exist(session, txt_user_id):
        return hs_plugin.fail(reason="user_id")
    
    User.remove_user_account(session, txt_user_id)
    session.commit()
    cleanup.clean_all();

    return hs_plugin.ok()
开发者ID:luzi82,项目名称:HiSocial,代码行数:15,代码来源:_hisocial.py

示例14: command_user_create_user_account

def command_user_create_user_account(txtf_user_token,txt_user_id, txt_password):
    cleanup = Cleanup()
    session = Database.create_sqlalchemy_session_push(cleanup)
    
    if not Permission.get_user_permission(session, txtf_user_token, "admin"):
        return hs_plugin.fail(reason="permission")
    
    if User.check_user_account_exist(session, txt_user_id):
        return hs_plugin.fail(reason=FAIL_REASON_USER_EXIST)

    User.add_user_account(session, txt_user_id, txt_password)
    
    session.commit()
    cleanup.clean_all();
    
    return hs_plugin.ok()
开发者ID:luzi82,项目名称:HiSocial,代码行数:16,代码来源:_hisocial.py

示例15: command_human_create_user_account

def command_human_create_user_account(txtf_turing_turing,env_ip,txt_user_id, txt_password):

    cleanup = Cleanup()
    session = Database.create_sqlalchemy_session_push(cleanup)

    if(User.check_user_account_exist(session, txt_user_id)):
        return hs_plugin.fail(reason=FAIL_REASON_USER_EXIST)
    
    User.add_user_account(session, txt_user_id, txt_password)
    
    session.commit()
    cleanup.clean_all();

    token = UserLoginToken.generate_user_login_token(txt_user_id)
    
    return hs_plugin.ok({"user_login_token":token})
开发者ID:luzi82,项目名称:HiSocial,代码行数:16,代码来源:_hisocial.py


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