def test_nonstandardPW(self): ''' 非标注密码 :return: ''' self.redis.flushdb() ''' 密码过长 ''' un = 'Shawn' pw = ''.join(['1' for i in range(user.ACCOUNT_MAX_SIZE+1)]) try: err = '能够生成过 长 的密码!!' u = User.createNewUser(un, pw) raise ValueError(err) except : errInfo = traceback.format_exc() if err in errInfo: raise ValueError(errInfo) un = 'Shawn' pw = ''.join(['1' for i in range(user.ACCOUNT_MIN_SIZE-1)]) try: err = '能够生成过 短 的密码!!' u = User.createNewUser(un, pw) raise ValueError(err) except: errInfo = traceback.format_exc() if err in errInfo: raise ValueError(errInfo)
def test_addUserGroup(self): ''' 测试 给用户添加用户组 :return: ''' ''' 清空数据库 ''' self.redis.flushdb() ''' 生成测试用户 ''' un = 'test01' pw = '123456' user = User.createNewUser(un, pw) ''' 生成测试用户组 ''' ugn = 'testUG01' ug = UserGroup.createNewUserGroup(ugn) print 'ug->', id(ug), ug ''' 添加用户组 ''' user.addUserGroup(ug) ug = UserGroup.obj(name=ugn) print 'ug->', id(ug), ug ''' 添加用户组 ''' if ug not in user.userGroups: raise ValueError('添加 用户组失败') ''' 移除用户组 ''' user.removeUserGroup(ug) if ug in user.userGroups: raise ValueError('移除 用户组失败')
def test_createSameNameUer(self): ''' 尝试生成同名用户 :return: ''' self.redis.flushdb() username, password = '******', 'bbb222' u = User.createNewUser(username, password) try: u = User.createNewUser(username, password) except: errInfo = traceback.format_exc() if user.NEW_ACCOUNT_ERR_NOT_UNIQUE in errInfo: print '不能创建重名账户...' else: raise errInfo
def test_render_user_list(self): ''' 渲染 用户列表 :return: ''' # self.redis.flushdb() user = User.obj(username=User.rootAccount) if not user: User.createRoot() user = User.obj(username=User.rootAccount) un = 'test1' pw = '123456' User.createNewUser(un, pw) views = Views(user) views.render_user_list(ModifUser) views.html('user_list')