def test_role_update_roleName_success(self): '''修改角色''' roleName_update = random.choice(['老板', '高级管理']) response = CreateRole().update_role(self.roleId, roleName_update, self.menuJson) self.logger.info('修改角色返回状态码:{0}'.format(response)) self.logger.info('修改角色返回结果是:{0}'.format(response.json())) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['code'], 0)
def setUp(self): self.logger = Log() self.logger.info( '########################### TestRoleUpdate START ###########################' ) self.roleName = random.choice(['管理', '财务', '调度', '测试']) self.logger.info('新增角色的名称是:{0}'.format(self.roleName)) self.menuJson = '[{"menuName":"首页","menuCode":10000},{"menuName":"首页-运单查询","menuCode":10001},{"menuName":"首页-运单查询-运输中运单","menuCode":10002},{"menuName":"首页-运单查询-昨日新增运单","menuCode":10003},{"menuName":"首页-运单查询-本月累计运单","menuCode":10004},{"menuName":"首页-运单支付","menuCode":10005},{"menuName":"首页-运单支付-待审批的运单","menuCode":10006},{"menuName":"首页-运单支付-尾款运费待支付","menuCode":10007},{"menuName":"首页-我的账户","menuCode":10008},{"menuName":"首页-我的账户-已申请笔数","menuCode":10009},{"menuName":"首页-我的账户-申请提款金额(元)","menuCode":10010}]' self.roleId = CreateRole().create_role(self.roleName, self.menuJson)
def test_role_create_success(self): '''新增角色''' roleName = random.choice(['管理', '财务', '调度', '测试']) self.logger.info('新增角色的名称是:{0}'.format(roleName)) menuJson = '[{"menuName":"首页","menuCode":10000},{"menuName":"首页-运单查询","menuCode":10001},{"menuName":"首页-运单查询-运输中运单","menuCode":10002},{"menuName":"首页-运单查询-昨日新增运单","menuCode":10003},{"menuName":"首页-运单查询-本月累计运单","menuCode":10004},{"menuName":"首页-运单支付","menuCode":10005},{"menuName":"首页-运单支付-待审批的运单","menuCode":10006},{"menuName":"首页-运单支付-尾款运费待支付","menuCode":10007},{"menuName":"首页-我的账户","menuCode":10008},{"menuName":"首页-我的账户-已申请笔数","menuCode":10009},{"menuName":"首页-我的账户-申请提款金额(元)","menuCode":10010}]' roleId = CreateRole().create_role(roleName, menuJson) role_list = RoleSelect().role_select( roleName=roleName).json()['content']['dataList'] if role_list != []: L = [] for loan in role_list: L.append(str((loan['roleId']))) self.assertIn(roleId, L, 'Role created fail!') else: self.logger.error('Please check the results of Role for empty')
def create_user(self,roleName,menuJson,name,userName,mobile,isLoginApp,carType): '''新增账号''' try: #选择角色 role_list = RoleCompanyGet().role_company_get().json()['content'] if role_list == []: roleId = CreateRole().create_role(roleName,menuJson) self.logger.info('公司没有角色时新增角色,新增角色名称是:{0}'.format(roleName)) else: roleId = random.choice(role_list)['roleId'] self.logger.info('新增账号的角色ID是:{0}'.format(roleId)) #选择项目数据权限 projectId = CreateProject().project_data_permission_choice() #新增账号 response = UserCreate().user_create(roleId,name,userName,mobile,isLoginApp,projectId,carType) if response.json()['code'] == 0: return response.json()['content'],roleId # 需求变动(已删除的子账号不能再新建) # elif response.json()['code'] == 9110028: # user_list = UserSelect().user_select().json()['content']['dataList'] # for user in user_list: # if user['userName'] == userName: # UserDelete().user_delete(user['loginId']) # userId = UserCreate().user_create(roleId,name,userName,mobile,isLoginApp,projectId,carType).json()['content'] # return userId,roleId # elif response.json()['code'] == 9110029: # user_list = UserSelect().user_select().json()['content']['dataList'] # for user in user_list: # if user['mobile'] == mobile: # UserDelete().user_delete(user['loginId']) # userId = UserCreate().user_create(roleId,name,userName,mobile,isLoginApp,projectId,carType).json()['content'] # return userId,roleId elif response.json()['code'] == 9110028: sql = 'DELETE FROM YD_APP_APPROVAL_USER WHERE userName = \'{0}\' and partnerNo = \'{1}\''.format( userName,self.config['partnerNo']) self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'], user=self.config['db_user'], passwd=self.config['db_passwd'], dbname=self.config['db_dbname'], charset=self.config['db_charset']) print(sql) self.DBUtil.execute_sql(sql) userId = UserCreate().user_create(roleId, name, userName, mobile, isLoginApp, projectId, carType ).json()[ 'content'] return userId, roleId elif response.json()['code'] == 9110029: sql = 'DELETE FROM YD_APP_APPROVAL_USER WHERE mobile = \'{0}\' and partnerNo = \'{1}\''.format(mobile, self.config['partnerNo']) self.DBUtil = DBUtil(host=self.config['db_host'], port=self.config['db_port'], user=self.config['db_user'], passwd=self.config['db_passwd'], dbname=self.config['db_dbname'], charset=self.config['db_charset']) print(sql) self.DBUtil.execute_sql(sql) print(sql) userId = UserCreate().user_create(roleId, name, userName, mobile, isLoginApp, projectId, carType ).json()['content'] return userId, roleId else: self.logger.info('新增账号返回错误:{0}'.format(response.json())) return None,None except Exception as e: self.logger.error('新增账号发生异常:{0}'.format(e)) return None