def test_反测_失败添加品牌节点_年龄组结束值小于90(self, depend_nodeInfo): with allure.step('准备用例入参'): brandName = testdata.random_node_brandName() ageGroups = [(0, 89)] with allure.step('接口请求'): res_info = api.bns_node_addBrand( parentAreaCode=depend_nodeInfo["firstPartnerData"]["areaCode"], brandName=brandName, ageGroups=ageGroups) # res_data = JsonHelper.parseJson_by_objectpath(res_info, "$.response_data.data") with allure.step('校验:接口响应信息'): with allure.step('校验:接口状态码'): actual_code = JsonHelper.parseJson_by_objectpath( res_info, "$.response_data.code") actual_msg = JsonHelper.parseJson_by_objectpath( res_info, "$.response_data.message") expect_code = 5028 expect_msg = "年龄分组不能断层" self.assert_actual_equal_expect("接口业务码", actual_code, expect_code) self.assert_actual_equal_expect("接口message", actual_msg, expect_msg)
def test_正测_新建销售订单提交审批(self): # with allure.step('准备用例入参'): with allure.step('接口请求'): api_admin.bns_new_so_add() api_admin.bns_so_submitSaleOrder() res_info = api_admin.bns_so_saleOrderApprove() with allure.step('校验:接口响应信息'): with allure.step('校验:接口状态码'): actual_code = JsonHelper.parseJson_by_objectpath(res_info, "$.retCode") actual_msg = JsonHelper.parseJson_by_objectpath(res_info, "$.retMsg") expect_code = 200 expect_msg = "操作成功!" self.assert_actual_equal_expect("接口业务码", actual_code, expect_code) self.assert_actual_equal_expect("接口业务码", actual_msg, expect_msg) with allure.step('校验:关联业务'): # 每个关联业务写成一个step pass with allure.step('清理用例'): pass
def test_正测_失败添加品牌节点_节点名称已使用(self, depend_nodeInfo): ageGroups = [(0, 90)] with allure.step('接口请求'): res_info = api.bns_node_addBrand( parentAreaCode=depend_nodeInfo["thirdPartnerData"]["areaCode"], brandName=depend_nodeInfo["brandData"]["brandName"], ageGroups=ageGroups) with allure.step('校验:接口响应信息'): with allure.step('校验:接口状态码'): actual_code = JsonHelper.parseJson_by_objectpath( res_info, "$.response_data.code") expect_code = 5013 self.assert_actual_equal_expect("接口业务码", actual_code, expect_code)
def test_正测_成功编辑IOT设备_编辑设备条码(self, 待编辑_IOT设备信息): with allure.step('准备用例入参'): deviceId = 待编辑_IOT设备信息["deviceId"] deviceType = 待编辑_IOT设备信息["deviceType"] manufacturerType = 待编辑_IOT设备信息["manufacturerType"] deviceCode = 待编辑_IOT设备信息["deviceCode"] deviceBarCode = testdata.random_iotDevice_deviceBarCode() hardwareVersion = 待编辑_IOT设备信息["hardwareVersion"] lensType = 待编辑_IOT设备信息["lensType"] with allure.step('接口请求'): res_info = api_admin.bns_iotDevice_edit( deviceid=deviceId, deviceType=deviceType, manufacturerType=manufacturerType, deviceCode=deviceCode, deviceBarCode=deviceBarCode, hardwareVersion=hardwareVersion, lensType=lensType, ) with allure.step('校验:接口响应信息'): with allure.step('校验:接口状态码'): expect_code = 0 actual_code = JsonHelper.parseJson_by_objectpath( res_info, "$.response_data.code") self.assert_actual_equal_expect("接口业务码", actual_code, expect_code) with allure.step('校验:关联业务'): with allure.step('校验: 设备详情接口'): actual_value = api_admin.bns_iotDevice_detail( deviceId=deviceId) expect_value = deviceBarCode self.assert_actual_contain_expect("编辑后的值被[设备详情接口]包含", actual_value, expect_value) with allure.step('校验: 设备列表接口'): actual_value = api_admin.bns_iotDevice_list( pageNo=1, pageSize=20, deviceCodeOrBar=deviceCode) expect_value = deviceBarCode self.assert_actual_contain_expect("编辑后的值被[设备列表接口]包含", actual_value, expect_value)
def test_正测_失败添加一级合作方_节点名称已使用(self, depend_nodeInfo): with allure.step('接口请求'): res_info = api.bns_node_addFirstPartner( partnerName=depend_nodeInfo["name"], ) with allure.step('校验:接口响应信息'): with allure.step('校验:接口状态码'): actual_code = JsonHelper.parseJson_by_objectpath( res_info, "$.response_data.code") expect_code = 5013 self.assert_actual_equal_expect("接口业务码", actual_code, expect_code)
def depend_iotDevice_info(): with allure.step("前置条件1: 注册IOT设备"): info = public_api_admin.scn_publicDevice_add() deviceCode = info["deviceCode"] with allure.step("前置条件2: 启用设备"): iot_api_admin.bns_iotDevice_enable(deviceCodeList=[deviceCode]) list_info = iot_api_admin.bns_iotDevice_list( deviceCodeOrBar=deviceCode) deviceId = JsonHelper.parseJson_by_objectpath(list_info, "$..*[@.id]")[0] yield info with allure.step("清理前置条件:审批下架设备申请"): iot_api_admin.scn_iotDevice_apply(deviceId) with allure.step("在公共服务中删除设备"): public_api_admin.bns_publicDevice_delete(deviceCode)
def test_反测_失败添加楼层节点_节点名称已使用(self, depend_nodeInfo): with allure.step('准备用例入参'): parentAreaCode = depend_nodeInfo["shopData"]["areaCode"] floorName = depend_nodeInfo["floorData"]["floorName"] with allure.step('接口请求'): res_info = api.bns_node_addFloor( parentAreaCode=parentAreaCode, floorName=floorName, ) with allure.step('校验:接口响应信息'): with allure.step('校验:接口状态码'): actual_code = JsonHelper.parseJson_by_objectpath( res_info, "$.response_data.code") expect_code = 5013 self.assert_actual_equal_expect("接口业务码", actual_code, expect_code)
def test_反测_失败查看设备详情_设备ID不存在(self): with allure.step('准备用例入参'): deviceId = "99999999" with allure.step('接口请求'): res_info = api_admin.bns_iotDevice_detail(deviceId=deviceId, ) with allure.step('校验:接口响应信息'): with allure.step('校验:接口状态码'): actual_code = JsonHelper.parseJson_by_objectpath( res_info, "$.response_data.code") expect_code = -4 self.assert_actual_equal_expect("接口业务码", actual_code, expect_code)
def test_正测_成功添加设备_绑定在抓拍子节点(self, 关联_IOT设备信息, 关联_抓拍子节点_进店, 关联_门店节点): with allure.step('准备用例入参'): mallAreaCode = 关联_门店节点["areaCode"] deviceCodeOrBar = 关联_IOT设备信息["deviceCode"] deviceName = testdata.random_device_deviceName() areaCodesList = [关联_抓拍子节点_进店["areaCode"]] with allure.step('接口请求'): res_info = api_admin.bns_device_add( mallAreaCode=mallAreaCode, deviceCodeOrBar=deviceCodeOrBar, deviceName=deviceName, areaCodesList=areaCodesList, ) with allure.step('校验:接口响应信息'): with allure.step('校验:添加设备接口状态码'): expect_code = 0 actual_code = JsonHelper.parseJson_by_objectpath( res_info, "$.response_data.code") self.assert_actual_equal_expect("接口业务码", actual_code, expect_code) with allure.step('校验:设备列表接口'): actual_value = api_admin.bns_device_list( pageNo=1, pageSize=10, deviceCodeOrBar=deviceCodeOrBar) expect_value = deviceCodeOrBar self.assert_actual_contain_expect("绑定设备后的值被[设备列表接口]包含", actual_value, expect_value) with allure.step('解绑设备'): api_admin.bns_device_umount(deviceCode=deviceCodeOrBar, areaCode=关联_抓拍子节点_进店["areaCode"])
def scn_node_addLogic(self, headers=None, parentAreaCode=None, nodeName=None, logicTypeId=None, skipTime=None, skipType=None, res_accurate=False, business_exception=False): ''' :param headers: :param parentAreaCode: 添加节点的上级节点编码 :param nodeName: 添加节点的名称 :param logicTypeId: 数据处理逻辑类型id :param skipTime: 门店去重时间(秒) :param skipType: 去重时间类型(-1表示自定义,0表示门店去重时间) :param res_accurate: :param business_exception: :return: ''' # 参数化 if nodeName is None: nodeName = gen_bnsData.random_node_nodeName() #skipType为0时为取门店去重时间,即skipTime取门店去重时间 if skipType is None: skipType = 0 # 发送业务请求 res_json = self.bns_node_addLogic(headers=headers, parentAreaCode=parentAreaCode, nodeName=nodeName, logicTypeId=logicTypeId, skipTime=skipTime, skipType=skipType, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId") areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode") areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType") nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel") # 精确返回的内容 if res_accurate: pass # return deviceCode # 全部信息返回 info_dict = dict() if areaId is not None: info_dict.setdefault('areaId', areaId) if areaCode is not None: info_dict.setdefault('areaCode', areaCode) if areaType is not None: info_dict.setdefault('areaType', areaType) if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel) if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode) if nodeName is not None: info_dict.setdefault('nodeName', nodeName) if logicTypeId is not None: info_dict.setdefault('logicTypeId', logicTypeId) if skipTime is not None: info_dict.setdefault('skipTime', skipTime) if skipType is not None: info_dict.setdefault('skipType', skipType) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:添加抓拍子节点") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:添加抓拍子节点")
def scn_node_addBrand(self, parentAreaCode=None,headers=None, brandName=None, ageGroups=None, res_accurate=False, business_exception=False): """ 添加品牌节点 :param parentAreaCode:上级区域编码 :param headers: :param brandName:品牌名称 :param ageGroups: 年龄分组,例:[(0,2),(3,5),(5,90)] :param res_accurate: :param business_exception: :return: """ # 参数化 if brandName is None: brandName = gen_bnsData.random_node_brandName() if ageGroups is None: ageGroups = [(0,90)] # 发送业务请求 res_json = self.bns_node_addBrand(headers=headers, parentAreaCode=parentAreaCode, brandName=brandName, ageGroups=ageGroups) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 收集响应信息:输入信息或返回信息中提取 areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId") areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode") areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType") nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel") # 精确返回的内容 if res_accurate: return areaCode # 全部信息返回 info_dict = dict() if areaId is not None: info_dict.setdefault('areaId', areaId) if areaCode is not None: info_dict.setdefault('areaCode', areaCode) if areaType is not None: info_dict.setdefault('areaType', areaType) if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel) if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode) if brandName is not None: info_dict.setdefault('brandName', brandName) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:添加品牌") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:添加品牌")
def scn_iotUser_add_techSupoort(self, headers=None, userEmail=None, userName=None, userPhone=None, res_accurate=False, business_exception=False): ''' 功能:IOT添加一个技术支持人员 :param headers: :param userEmail: 邮箱 :param userName: 姓名 :param userPhone: 手机号 :return: ''' # 参数化 if userEmail is None: userEmail = gen_bnsData.random_iotUser_userEmail() if userName is None: userName = gen_bnsData.random_iotUser_userName() if userPhone is None: userPhone = gen_bnsData.random_iotUser_userPhone() roleIdsList = [3] # 发送业务请求 res_json = self.bns_iotUser_add( headers=headers, userEmail=userEmail, userName=userName, userPhone=userPhone, roleIdsList=roleIdsList, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 userId = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.data.userId") # 获取密码 password_by_md5 = get_md5Password_from_mysql_in_iot(userPhone) # 精确返回的内容 if res_accurate: return userPhone # 全部信息返回 info_dict = dict() info_dict.setdefault('userId', userId) info_dict.setdefault('userPassword', password_by_md5) if userEmail is not None: info_dict.setdefault('userEmail', userEmail) if userName is not None: info_dict.setdefault('userName', userName) if userPhone is not None: info_dict.setdefault('userPhone', userPhone) if roleIdsList is not None: info_dict.setdefault('roleIdsList', roleIdsList) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath( res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:添加员工") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:添加员工")
def scn_device_auth(self, deviceCode, data=None, headers=None, res_accurate=False, business_exception=False): ''' :param headers: :param deviceCode: 设备编码 :param data: 数据加密 :param res_accurate: :param business_exception: :return: ''' # 参数化 deviceCode = deviceCode json_dict = { "equno": deviceCode, "time": TimeHelper.get_time_from_timestamp(), "randCode": StringHelper.random_string(16) } publicKey = utils.get_publicKey_from_mysql(deviceCode) # RSA加密方法 rsa = utils.RSA() data = rsa.rsa_pubkey_encrypt(publicKey, json.dumps(json_dict)) # 发送业务请求 res_json = self.bns_device_auth( headers=headers, deviceCode=deviceCode, data=data, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.resultCode") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 data = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data") res = rsa.rsa_pubkey_decrypt(publicKey, data) # 解密接口返回的信息 # 精确返回的内容 if res_accurate: pass # return deviceCode # 全部信息返回 info_dict = json.loads(res) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath( res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:设备鉴权") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:设备鉴权")
def scn_node_addShop(self, headers=None, parentAreaCode=None, shopName=None, province=None, city=None, district=None, clerkSim=None, clerkSimType=None, customerSim=None, customerSimType=None, groupId=None, repeatDate=None, skipTime=None, trailSkipTime=None, res_accurate=False, business_exception=False): ''' :param headers: :param parentAreaCode: 添加门店的上级节点区域编码 :param shopName: 添加门店的名称 :param province: 省 :param city: 市 :param district: 县/区 :param clerkSim: 店员相似度阈值 :param clerkSimType: 店员相似度选择(-1表示自定义,0表示低,1表示中,2表示高) :param customerSim: 顾客相似度阈值 :param customerSimType: 顾客相似度选择(-1表示自定义,0表示低,1表示中,2表示高) :param groupId: 门店分组编码 :param repeatDate: 回头客范围(天) :param skipTime: 门店去重时间(秒) :param trailSkipTime: 门店轨迹去重时间(秒) :param res_accurate: :param business_exception: :return: ''' # 参数化 if shopName is None: shopName = gen_bnsData.random_node_shopName() if province is None or city is None or district is None: province, city, district = gen_bnsData.get_random_addNode_mallAddr() if clerkSimType is None: clerkSimType = 1 if customerSimType is None: customerSimType = 1 if repeatDate is None: repeatDate = 30 if skipTime is None: skipTime = 3600 if trailSkipTime is None: trailSkipTime = 3600 if shopName is None: shopName = gen_bnsData.random_node_shopName() # 发送业务请求 res_json = self.bns_node_addShop(headers=headers, parentAreaCode=parentAreaCode, shopName=shopName, province=province, city=city, district=district, clerkSim=clerkSim, clerkSimType=clerkSimType, customerSim=customerSim, customerSimType=customerSimType, groupId=groupId, repeatDate=repeatDate, skipTime=skipTime, trailSkipTime=trailSkipTime, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 5013 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 精确返回的内容 areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId") areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode") areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType") nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel") if res_accurate: return areaCode # 全部信息返回 info_dict = dict() if areaId is not None: info_dict.setdefault('areaId', areaId) if areaCode is not None: info_dict.setdefault('areaCode', areaCode) if areaType is not None: info_dict.setdefault('areaType', areaType) if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel) if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode) if shopName is not None: info_dict.setdefault('shopName', shopName) if clerkSim is not None: info_dict.setdefault('clerkSim', clerkSim) if clerkSimType is not None: info_dict.setdefault('clerkSimType', clerkSimType) if customerSim is not None: info_dict.setdefault('customerSim', customerSim) if customerSimType is not None: info_dict.setdefault('customerSimType', customerSimType) if groupId is not None: info_dict.setdefault('groupId', groupId) if repeatDate is not None: info_dict.setdefault('repeatDate', repeatDate) if skipTime is not None: info_dict.setdefault('skipTime', skipTime) if trailSkipTime is not None: info_dict.setdefault('trailSkipTime', trailSkipTime) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:添加门店") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:添加门店")
def scn_node_list(self, headers=None, parentAreaCode=None, name=None, nodeLevel=None, pageNo=None, pageSize=None, res_accurate=False, business_exception=False): """ 获取抓拍列表 :param headers: :param parentAreaCode: 上级节点编码 :param name: 节点名称 :param nodeLevel: 节点等级 :param pageNo: 页码 :param pageSize: 每页展示数量 :param res_accurate: :param business_exception: :return: """ # 参数化 if pageNo is None: pageNo = 1 if pageSize is None: pageSize = 10 # 发送业务请求 res_json = self.bns_node_list(headers=headers, parentAreaCode=parentAreaCode, name=name, nodeLevel=nodeLevel, pageNo=pageNo, pageSize=pageSize, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 精确返回的内容 if res_accurate: pass # return deviceCode # 全部信息返回 info_dict = dict() return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:区域列表") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:区域列表")
def scn_publicDevice_add(self, headers=None, deviceType=None, manufacturerType=None, deviceCode=None, deviceBarCode=None, hardwareVersion=None, lensType=None, res_accurate=False, business_exception=False): # 参数化: 默认是店计瑞为,编码长度14,条码长度10 if deviceType is None: deviceType = 0 if manufacturerType is None: manufacturerType = 0 if deviceCode is None: deviceCode = gen_bnsData.random_publicDevice_deviceCode(14) if deviceBarCode is None: deviceBarCode = gen_bnsData.random_publicDevice_deviceBarCode(10) if hardwareVersion is None: hardwareVersion = gen_bnsData.random_publicDevice_hardwareVersion() if lensType is None: lensType = gen_bnsData.random_publicDevice_lensType() # 发送业务请求 res_json = self.bns_publicDevice_add(headers=headers, deviceType=deviceType, manufacturerType=manufacturerType, deviceCode=deviceCode, deviceBarCode=deviceBarCode, hardwareVersion=hardwareVersion, lensType=lensType, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 list_info = self.bns_publicDevice_list(pageNo=1, pageSize=20, deviceCode=deviceCode) enale = JsonHelper.parseJson_by_objectpath(list_info, "$..*[@.enable]", res_firstOne=True) deviceRegDatetime = JsonHelper.parseJson_by_objectpath(list_info, "$..*[@.createTime]", res_firstOne=True) # 精确返回的内容 if res_accurate: pass # 全部信息返回 info_dict = dict() if enale is not None: info_dict.setdefault('enale', enale) if deviceRegDatetime is not None: info_dict.setdefault('deviceRegDatetime', deviceRegDatetime) if deviceType is not None: info_dict.setdefault('deviceType', deviceType) if manufacturerType is not None: info_dict.setdefault('manufacturerType', manufacturerType) if deviceCode is not None: info_dict.setdefault('deviceCode', deviceCode) if deviceBarCode is not None: info_dict.setdefault('deviceBarCode', deviceBarCode) if hardwareVersion is not None: info_dict.setdefault('hardwareVersion', hardwareVersion) if lensType is not None: info_dict.setdefault('lensType', lensType) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:公共服务注册设备") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:公共服务注册设备")
def test_基本的数据处理流程_会员注册及识别(self, api_technicalSupport, 关联_抓拍子节点_进店, 关联_设备绑定节点): with allure.step('前置条件:模拟设备上报一张人脸图片'): gen_devData.simulate_device_upload_pic( 关联_设备绑定节点["deviceCodeOrBar"], score=1.2) with allure.step('店客云及技术支持:查看访客列表'): res = api_technicalSupport.scn_snap_visit_list( areaCode=关联_抓拍子节点_进店["areaCode"], expected_value=1) visitor_count = JsonHelper.parseJson_by_objectpath( res, "count($..*[@.userType is 0])") AllureHelper.assert_equal("访客列表普客人数", 1, visitor_count) with allure.step('店客云及技术支持:注册人脸为会员'): faceId = JsonHelper.parseJson_by_objectpath(res, "$..*['faceId']", res_firstOne=True) imagePath = JsonHelper.parseJson_by_objectpath( res, "$..*['featureImageUrl']", res_firstOne=True) shopAreaCode = JsonHelper.parseJson_by_objectpath( res, "$..*['mallCode']", res_firstOne=True) api_technicalSupport.scn_member_add(mallareaCode=shopAreaCode, imagePath=imagePath, faceId=faceId) with allure.step('店客云及技术支持:查看访客列表'): userType = 0 i = 0 while userType == 0 and i < 20: res = api_technicalSupport.scn_snap_visit_list( areaCode=关联_抓拍子节点_进店["areaCode"], expected_value=1) userType = JsonHelper.parseJson_by_objectpath( res, "$..*['userType']", res_firstOne=True) i += 1 time.sleep(1) member_count = JsonHelper.parseJson_by_objectpath( res, "count($..*[@.userType is 1])", res_allowNone=True) AllureHelper.assert_equal("访客列表会员人数", 1, member_count) with allure.step('前置条件:去重时间内模拟设备上报同一张人脸图片'): gen_devData.simulate_device_upload_pic( 关联_设备绑定节点["deviceCodeOrBar"], score=1.2) with allure.step('店客云及技术支持:查看抓拍列表'): i = 0 while member_count < 2 and i < 20: res = api_technicalSupport.scn_snap_list( areaCodesList=[关联_抓拍子节点_进店["areaCode"]], expected_value=1) member_count = JsonHelper.parseJson_by_objectpath( res, "count($..*[@.userType is 1])", res_allowNone=True) i += 1 time.sleep(1) AllureHelper.assert_equal("抓拍列表会员人数", 2, member_count) with allure.step('店客云及技术支持:查看访客列表'): res = api_technicalSupport.scn_snap_visit_list( areaCode=关联_抓拍子节点_进店["areaCode"], expected_value=1) member_count = JsonHelper.parseJson_by_objectpath( res, "count($..*[@.userType is 1])", res_allowNone=True) AllureHelper.assert_equal("访客列表会员人数", 1, member_count)
def test_基本权限操作流程_运营用户多权限(self, 关联_门店节点, 关联_门店节点2): with allure.step('超级管理员:创建账号A,关联所有角色权限(技术支持,数据修正,安装人员)'): api_admin = Api() userName = gen_bnsData.random_operateUser_userName() userPhone = gen_bnsData.random_operateUser_userPhone() roleId = fixed_bnsData.operateUserId.techSupport.value areaCodesList = ["0000"] roleId2 = fixed_bnsData.operateUserId.data_correct.value areaCodesList2 = [关联_门店节点["areaCode"]] roleId3 = fixed_bnsData.operateUserId.installation_person.value areaCodesList3 = [关联_门店节点2["areaCode"]] res_json = api_admin.bns_operateUser_add( userName=userName, userPhone=userPhone, roleId=roleId, areaCodesList=areaCodesList, roleId2=roleId2, areaCodesList2=areaCodesList2, roleId3=roleId3, areaCodesList3=areaCodesList3) with allure.step("校验: 业务状态码是否正确"): actual_code = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.code") AllureHelper.assert_equal("业务状态码", actual_code, 0) with allure.step('超级管理员:获取创建账号A对应UserID及账号密码'): userInfo = api_admin.bns_operateUser_list(userInfo=userPhone) userId_A = JsonHelper.parseJson_by_objectpath( userInfo, "$..*[@.id]", res_firstOne=True) password_by_md5 = get_md5Password_from_mysql_in_mall(userPhone) with allure.step('登录账号A校验:包含安装人员角色的账号不可登录'): res = dkyj.BusinessApi.bns_user_login(userName=userPhone, userPasswd=password_by_md5) with allure.step("校验: 业务状态码是否正确"): actual_code = JsonHelper.parseJson_by_objectpath( res, "$.response_data.code") expect_code = 2037 AllureHelper.assert_equal("业务状态码", actual_code, expect_code) with allure.step("校验: 提示信息是否正确"): actual_msg = JsonHelper.parseJson_by_objectpath( res, "$.response_data.message") expect_msg = "安装人员仅允许在APP登录" AllureHelper.assert_equal("提示信息", actual_msg, expect_msg) with allure.step('超级管理员:创建账号B,关联所有角色权限(技术支持,数据修正)'): userName = gen_bnsData.random_operateUser_userName() userPhone = gen_bnsData.random_operateUser_userPhone() roleId = fixed_bnsData.operateUserId.techSupport.value areaCodesList = ["0000"] roleId2 = fixed_bnsData.operateUserId.data_correct.value areaCodesList2 = [关联_门店节点["areaCode"]] res_json = api_admin.bns_operateUser_add( userName=userName, userPhone=userPhone, roleId=roleId, areaCodesList=areaCodesList, roleId2=roleId2, areaCodesList2=areaCodesList2) with allure.step("校验: 业务状态码是否正确"): actual_code = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.code") AllureHelper.assert_equal("业务状态码", actual_code, 0) with allure.step('超级管理员:获取创建账号B对应UserID及账号密码'): userInfo = api_admin.bns_operateUser_list(userInfo=userPhone) userId_B = JsonHelper.parseJson_by_objectpath( userInfo, "$..*[@.id]", res_firstOne=True) password_by_md5 = get_md5Password_from_mysql_in_mall(userPhone) with allure.step('步骤: 登录账号B及修改密码为Dj123456'): api_operateUser = Api(username=userPhone, password=password_by_md5) api_operateUser.bns_operateUser_modifyPassword( oldPasswordMd5=password_by_md5, newPassword="******") api_operateUser = Api(username=userPhone, password="******") res = api_operateUser.bns_operateUser_getUserRoleList() with allure.step('校验: 账号B关联的角色权限ID列表'): userRoleId_list = JsonHelper.parseJson_by_objectpath( res, "$..*['roleId']") expect_userRoleId_list = [2, 3] AllureHelper.assert_equal("角色权限ID列表", sorted(userRoleId_list), expect_userRoleId_list) userId_techSupport = JsonHelper.parseJson_by_objectpath( res, "$..*[@.'roleId' is 2].id", res_firstOne=True) userId_data_correct = JsonHelper.parseJson_by_objectpath( res, "$..*[@.'roleId' is 3].id", res_firstOne=True) with allure.step('步骤: 选择账号B,切换技术支持角色'): res = api_operateUser.bns_operateUser_changeUserRole( userId=userId_techSupport) with allure.step("校验: 业务状态码是否正确"): actual_code = JsonHelper.parseJson_by_objectpath( res, "$.response_data.code") AllureHelper.assert_equal("业务状态码", actual_code, 0) with allure.step('校验: 技术支持角色权限'): # TODO:待完成技术支持权限功能校验 pass with allure.step('步骤: 选择账号B,切换数据修正角色'): res = api_operateUser.bns_operateUser_changeUserRole( userId=userId_data_correct) with allure.step("校验: 业务状态码是否正确"): actual_code = JsonHelper.parseJson_by_objectpath( res, "$.response_data.code") AllureHelper.assert_equal("业务状态码", actual_code, 0) with allure.step('校验: 数据修正角色权限'): # TODO:待完成数据修正权限功能校验 pass with allure.step('数据清理: 删除账号A'): api_admin_new = Api() res = api_admin_new.bns_operateUser_delete(userId=userId_A) actual_code = JsonHelper.parseJson_by_objectpath( res, "$.response_data.code") AllureHelper.assert_equal("业务状态码", actual_code, 0) with allure.step('数据清理: 删除账号B'): res = api_admin_new.bns_operateUser_delete(userId=userId_B) actual_code = JsonHelper.parseJson_by_objectpath( res, "$.response_data.code") AllureHelper.assert_equal("业务状态码", actual_code, 0)
def bns_po_oa_submit(self): self.order = JsonHelper.parseJson_by_objectpath( self.bns_po_list(), "$.retEntity..fpurchaseOrderId")[0] data_test = { "xyPurchaseOrderSkuVOList": [{ "fpurchaseOrderSkuId": 15763, "fpurchaseOrderId": self.order, "fskuId": "118905004", "fbrandLabel": 1, "fpurchaseAmount": 20, "ftaxRate": 0, "ftaxIncluded": 1000000, "ftaxIncludedUnit": 1000000, "fwarehousingCost": 1000000, "fwarehousingCostUnit": 1000000, "taxIncluded": 1, "warehousingCost": 1, "shareCost": None, "totalAmountOfTaxOriginalCurrency": 20, "notTotalAmountOfTaxOriginalCurrency": 20, "amountOfTaxOriginalCurrency": 0, "taxIncludedBaseCurrency": 1, "warehousingCostBaseCurrency": 1, "totalAmountOfTaxBaseCurrency": 20, "notTotalAmountOfTaxBaseCurrency": 20, "amountOfTaxBaseCurrency": 0, "fskuName": "Comotomo可么多么奶瓶婴儿防胀气进口全硅胶奶瓶2*250ml/盒 2*250ml/盒", "fcategoryName": "母婴用品", "fbrandName": "Como tomo", "fbrandNameEng": "", "skuBidNumAndPriceDTO": None, "funit": "瓶盒", "fskuInternationalNo": "886074000043", "fpurchaseOrderSkuChangeId": None, "fdataType": None, "foriginId": 21, "ftaxRateString": "0%" }, { "fpurchaseOrderSkuId": 15762, "fpurchaseOrderId": self.order, "fskuId": "118905006", "fbrandLabel": 0, "fpurchaseAmount": 10, "ftaxRate": 10, "ftaxIncluded": 10000, "ftaxIncludedUnit": 1000000, "fwarehousingCost": 10000, "fwarehousingCostUnit": 1000000, "taxIncluded": 0.01, "warehousingCost": 0.01, "shareCost": None, "totalAmountOfTaxOriginalCurrency": 0.1, "notTotalAmountOfTaxOriginalCurrency": 0.1, "amountOfTaxOriginalCurrency": 0, "taxIncludedBaseCurrency": 0.01, "warehousingCostBaseCurrency": 0.01, "totalAmountOfTaxBaseCurrency": 0.1, "notTotalAmountOfTaxBaseCurrency": 0.1, "amountOfTaxBaseCurrency": 0, "fskuName": "TIGER虎牌 儿童保温杯MBR-T06G 吸管杯国际版 老虎 600ml", "fcategoryName": "母婴用品", "fbrandName": "虎牌", "fbrandNameEng": "TIGER", "skuBidNumAndPriceDTO": None, "funit": "个", "fskuInternationalNo": "4904710424933", "fpurchaseOrderSkuChangeId": None, "fdataType": None, "foriginId": 14, "ftaxRateString": "1%" }, { "fpurchaseOrderSkuId": 15764, "fpurchaseOrderId": self.order, "fskuId": "122305131", "fbrandLabel": 2, "fpurchaseAmount": 30, "ftaxRate": 20, "ftaxIncluded": 2000000, "ftaxIncludedUnit": 1000000, "fwarehousingCost": 1960667, "fwarehousingCostUnit": 1000000, "taxIncluded": 2, "warehousingCost": 1.960667, "shareCost": None, "totalAmountOfTaxOriginalCurrency": 60, "notTotalAmountOfTaxOriginalCurrency": 58.82, "amountOfTaxOriginalCurrency": 1.18, "taxIncludedBaseCurrency": 2, "warehousingCostBaseCurrency": 1.960667, "totalAmountOfTaxBaseCurrency": 60, "notTotalAmountOfTaxBaseCurrency": 58.82, "amountOfTaxBaseCurrency": 1.18, "fskuName": "Technic雪佛兰 ZR1 跑车42093 盒", "fcategoryName": "母婴用品", "fbrandName": "LEGO乐高", "fbrandNameEng": "", "skuBidNumAndPriceDTO": None, "funit": "盒", "fskuInternationalNo": "585015266999", "fpurchaseOrderSkuChangeId": None, "fdataType": None, "foriginId": 9, "ftaxRateString": "2%" }], "xyPurchaseOrderFinanceDO": { "advanceProportion": 100, "advancePayment": 0, "advanceProportionPayment": "100.00% 0.00", "metaphaseProportion": 0, "metaphasePayment": 0, "metaphaseProportionPayment": "", "finalProportion": 0, "finalPayment": 0, "finalProportionPayment": "", "totalAmountOfTaxOriginalCurrency": 100, "notTotalAmountOfTaxOriginalCurrency": 98.04, "amountOfTaxOriginalCurrency": 1.96, "totalAmountOfTaxBaseCurrency": 100, "notTotalAmountOfTaxBaseCurrency": 98.04, "amountOfTaxBaseCurrency": 1.96, "estimatePurchaseCost": 0, "estimatePurchaseCostOfBase": 0, "ffinanceId": 1206, "fcurrencyCode": "CNY", "payMoneyPlanBoList": None, "fexchangeRate": 1000000, "fexchangeRateView": 1, "fpurchaseInvoiceType": 1, "fwhetherAdvancePayment": 1, "fnumberOfSettlement": 1, "fmoneyWay": 1, "fadvancePayment": 1000000, "fadvanceProportion": 10000, "fadvancePaymentClause": 0, "fadvancePaymentClauseStr": "微信", "ftheFirstPayment": 1000000, "ftheFirstProportion": 10000, "ftheFirstPaymentClause": 0, "ftheFirstPaymentClauseStr": "微信", "fmetaphasePayment": None, "fmetaphaseProportion": None, "fmetaphasePaymentClause": 0, "fmetaphasePaymentClauseStr": None, "ffinalPayment": None, "ffinalProportion": None, "ffinalPaymentClause": 0, "ffinalPaymentClauseStr": None, "fadvanceEstimatedTimeOfPayment": get_current_time(), "ftheFirstEstimatedTimeOfPayment": get_current_time(), "fmetaphaseEstimatedTimeOfPayment": None, "ffinalEstimatedTimeOfPayment": None, "festimatePurchaseCost": 0, "fotherPayment": 0 }, "xyPurchaseOrderDeliveryDO": { "fdeliveryId": 1208, "ftransportType": 1, "fdeliveryAddress": "深圳", "fdeliveryDate": get_current_time(day=1) }, "xyPurchaseOrderDO": { "fpurchaseOrderId": self.order, "fbidId": None, "ferpOrderId": "121111", "fsaleOrderId": None, "fsupplierBidTradeId": None, "fcorporateSubjectId": 102, "fsupplierId": 531, "fpurchaseAid": 120, "ffinanceId": 1206, "fdeliveryId": 1208, "fpurchaseDeptName": "测试开发团队", "fsupplierName": "哈哈供应商2", "fsupplierLeader": "图图", "fsupplierLeaderPhone": "13026161548", "fourCompanyName": "深圳市天行云供应链有限公司", "fourCompanyLeader": "刘丽君", "fourCompanyLeaderPhone": "17688546806", "fagreementId": "TXY-PC-HHGYS/191224-001", "fplanType": 1, "ftradeType": 1, "fquotationMethod": "CPT", "fsourceArea": "湖北", "fshelfLife": "36", "fpurchaseOrderStatus": 1, "fclosingReasons": None, "fpurchaseOrderNotes": None, "fsourceAreaName": "湖北", "fautoCreate": 0, "finspection": 0, "forderLabels": 1, "fcreateTime": get_current_time(), "fsupplierBidTradeIdTradeId": None }, "purchasPurchaseOrderAttachmentDOList": [], "restsPurchaseOrderAttachmentDOList": [{ "fattachmentName": "账号.txt", "fattachmentUrl": "M00/00/BB/wKgA316paICALoAbAAACf-Z7Kz4219.txt", "fattachmentSize": 639, "fattachmentType": 0, "fdataType": 0, "fpurchaseBillId": self.order }], "oaComments": None, "fpurchaseOrderChangeId": None, "supplierFileDelete": False, "xyPurchaseOrderContractDO": { "fpurchaseContractId": 1958, "fpurchaseOrderId": self.order, "fagreementId": 220, "fagreementNum": "TXY-PC-HHGYS/191224-001", "fagreementType": 1, "finvoiceType": 1, "fmoneyWay": 1, "fpaymentComment": "三个结算啊大大说", "fcreateTime": None, "fmodifyTime": None }, "poRelationWarehouseInfoBBVoList": None, "paymentRequisitionList": None } data_dev = { "xyPurchaseOrderSkuVOList": [{ "fpurchaseOrderSkuId": 4305, "fpurchaseOrderId": self.order, "fskuId": "118905121", "fbrandLabel": 0, "fpurchaseAmount": 100, "ftaxRate": 10, "ftaxIncluded": 1000000, "ftaxIncludedUnit": 1000000, "fwarehousingCost": 990100, "fwarehousingCostUnit": 1000000, "taxIncluded": 1, "warehousingCost": 0.9901, "shareCost": None, "totalAmountOfTaxOriginalCurrency": 100, "notTotalAmountOfTaxOriginalCurrency": 99.01, "amountOfTaxOriginalCurrency": 0.99, "taxIncludedBaseCurrency": 1, "warehousingCostBaseCurrency": 0.9901, "totalAmountOfTaxBaseCurrency": 100, "notTotalAmountOfTaxBaseCurrency": 99.01, "amountOfTaxBaseCurrency": 0.99, "fskuName": "英国Matchstick Monkey火柴猴牙胶宝宝婴儿咬咬安抚磨牙棒软硅胶—红色 个", "fcategoryName": "母婴用品", "fbrandName": "火柴猴", "fbrandNameEng": "Matchstick Monkey", "skuBidNumAndPriceDTO": None, "funit": "红色", "fskuInternationalNo": "0611901211053", "fpurchaseOrderSkuChangeId": None, "fdataType": None, "foriginId": 8, "ftaxRateString": "1%", "edit": False }, { "fpurchaseOrderSkuId": 4306, "fpurchaseOrderId": self.order, "fskuId": "DL157941907294202", "fbrandLabel": 1, "fpurchaseAmount": 100, "ftaxRate": 0, "ftaxIncluded": 2000000, "ftaxIncludedUnit": 1000000, "fwarehousingCost": 2000000, "fwarehousingCostUnit": 1000000, "taxIncluded": 2, "warehousingCost": 2, "shareCost": None, "totalAmountOfTaxOriginalCurrency": 200, "notTotalAmountOfTaxOriginalCurrency": 200, "amountOfTaxOriginalCurrency": 0, "taxIncludedBaseCurrency": 2, "warehousingCostBaseCurrency": 2, "totalAmountOfTaxBaseCurrency": 200, "notTotalAmountOfTaxBaseCurrency": 200, "amountOfTaxBaseCurrency": 0, "fskuName": "潘多拉项链 彩金", "fcategoryName": "服饰鞋包", "fbrandName": "SWAROVSKI 施华洛世奇", "fbrandNameEng": "", "skuBidNumAndPriceDTO": None, "funit": "**", "fskuInternationalNo": "121221", "fpurchaseOrderSkuChangeId": None, "fdataType": None, "foriginId": 2, "ftaxRateString": "0%", "edit": False }, { "fpurchaseOrderSkuId": 4307, "fpurchaseOrderId": self.order, "fskuId": "GMH02965-J", "fbrandLabel": 2, "fpurchaseAmount": 100, "ftaxRate": 30, "ftaxIncluded": 100000, "ftaxIncludedUnit": 1000000, "fwarehousingCost": 97100, "fwarehousingCostUnit": 1000000, "taxIncluded": 0.1, "warehousingCost": 0.0971, "shareCost": None, "totalAmountOfTaxOriginalCurrency": 10, "notTotalAmountOfTaxOriginalCurrency": 9.71, "amountOfTaxOriginalCurrency": 0.29, "taxIncludedBaseCurrency": 0.1, "warehousingCostBaseCurrency": 0.0971, "totalAmountOfTaxBaseCurrency": 10, "notTotalAmountOfTaxBaseCurrency": 9.71, "amountOfTaxBaseCurrency": 0.29, "fskuName": "悦木之源 蘑菇水200ml 菌菇水 200ml", "fcategoryName": "美妆个护", "fbrandName": "悦木之源", "fbrandNameEng": "", "skuBidNumAndPriceDTO": None, "funit": "悦木之源", "fskuInternationalNo": "717334229594", "fpurchaseOrderSkuChangeId": None, "fdataType": None, "foriginId": 30, "ftaxRateString": "3%", "edit": False }], "xyPurchaseOrderFinanceDO": { "advanceProportion": 100, "advancePayment": 310, "advanceProportionPayment": "100.00% 310.00", "metaphaseProportion": 0, "metaphasePayment": 0, "metaphaseProportionPayment": "", "finalProportion": 0, "finalPayment": 0, "finalProportionPayment": "", "totalAmountOfTaxOriginalCurrency": 310, "notTotalAmountOfTaxOriginalCurrency": 308.72, "amountOfTaxOriginalCurrency": 1.28, "totalAmountOfTaxBaseCurrency": 310, "notTotalAmountOfTaxBaseCurrency": 308.72, "amountOfTaxBaseCurrency": 1.28, "estimatePurchaseCost": 0, "estimatePurchaseCostOfBase": 0, "ffinanceId": 743, "fcurrencyCode": "CNY", "payMoneyPlanBoList": None, "fexchangeRate": 1000000, "fexchangeRateView": 1, "fpurchaseInvoiceType": 0, "fwhetherAdvancePayment": 1, "fnumberOfSettlement": 1, "fmoneyWay": 0, "fadvancePayment": 3100000, "fadvanceProportion": 10000, "fadvancePaymentClause": 0, "fadvancePaymentClauseStr": "微信", "ftheFirstPayment": 3100000, "ftheFirstProportion": 10000, "ftheFirstPaymentClause": 0, "ftheFirstPaymentClauseStr": "微信", "fmetaphasePayment": None, "fmetaphaseProportion": None, "fmetaphasePaymentClause": 0, "fmetaphasePaymentClauseStr": None, "ffinalPayment": None, "ffinalProportion": None, "ffinalPaymentClause": 0, "ffinalPaymentClauseStr": None, "fadvanceEstimatedTimeOfPayment": get_current_time(), "ftheFirstEstimatedTimeOfPayment": get_current_time(), "fmetaphaseEstimatedTimeOfPayment": None, "ffinalEstimatedTimeOfPayment": None, "festimatePurchaseCost": 0, "fotherPayment": 0 }, "xyPurchaseOrderDeliveryDO": { "fdeliveryId": 744, "ftransportType": 1, "fdeliveryAddress": "广东", "fdeliveryDate": get_current_time() }, "xyPurchaseOrderDO": { "fpurchaseOrderId": self.order, "fbidId": None, "fstockUpPlanId": None, "ferpOrderId": "123321456", "fsaleOrderId": None, "fsupplierBidTradeId": None, "fcorporateSubjectId": 102, "fsupplierId": 531, "fpurchaseAid": 120, "ffinanceId": 743, "fdeliveryId": 744, "fpurchaseDeptName": "测试开发团队", "fsupplierName": "哈哈供应商2", "fsupplierLeader": "ben", "fsupplierLeaderPhone": "13264645696", "fourCompanyName": "深圳市天行云供应链有限公司", "fourCompanyLeader": "刘丽君", "fourCompanyLeaderPhone": "17688546806", "fagreementId": "TXY-PC-HHGYS/200311-02", "fplanType": 1, "ftradeType": 1, "fquotationMethod": "CPT", "fsourceArea": "湖北", "fshelfLife": "30", "fpurchaseOrderStatus": 1, "fclosingReasons": None, "fpurchaseOrderNotes": None, "fsourceAreaName": "湖北", "fautoCreate": 0, "finspection": 0, "forderLabels": 1, "fcreateTime": get_current_time(), "fsupplierBidTradeIdTradeId": None }, "purchasPurchaseOrderAttachmentDOList": [], "restsPurchaseOrderAttachmentDOList": [{ "fattachmentName": "账号.txt", "fattachmentUrl": "M00/00/9A/wKgA3l6zsfCAWgohAAACf-Z7Kz4885.txt", "fattachmentSize": "639", "fattachmentType": 0, "fdataType": 0, "fpurchaseBillId": self.order }], "oaComments": None, "fpurchaseOrderChangeId": None, "supplierFileDelete": False, "xyPurchaseOrderContractDO": { "fpurchaseContractId": 336, "fpurchaseOrderId": self.order, "fagreementId": 239, "fagreementNum": "TXY-PC-HHGYS/200311-02", "fagreementType": 0, "finvoiceType": 0, "fmoneyWay": 0, "fpaymentComment": "sfdsdfsddsfdsfdsfdsf", "fcreateTime": None, "fmodifyTime": None }, "poRelationWarehouseInfoBBVoList": None, "paymentRequisitionList": None } if str(get_b2b_host) == "http://192.168.1.227:3003": data = data_dev else: data = data_test response = self.session.post( # TODO: 请确认url是否需要变化!!! url="{}/admin/po/oa/submit".format(get_b2b_host), data=json.dumps(data), headers=self.headers) # self.log.log_info("提交审批采购订单接口请求信息:{}".format(data)) self.log.log_info("提交审批采购订单接口返回信息:{}".format(response.json())) return response.json()
def scn_snap_list(self, headers=None, areaCodesList=None, deviceCode=None, deviceType=None, startAgeInit=None, endAgeInit=None, startDateTime=None, endDateTime=None, faceId=None, memberFaceId=None, sexInit=None, snapType=None, userStatus=None, userType=None, pageNo=None, pageSize=None, res_accurate=False, business_exception=False,expected_value=None): ''' 功能:抓拍列表查询 :param headers: :param areaCodesList: 节点编码 :param deviceCode: 设备编码 :param deviceType: 设备类型 :param startAgeInit: 开始年龄 :param endAgeInit: 结束年龄 :param startDateTime: 开始时间 :param endDateTime: 结束时间 :param faceId: 人脸ID :param sexInit: 性别,男:0,女:1 :param snapType: 抓拍类型,0:人脸;3:头肩;5:无特征人脸;6:低质量 :param userStatus: 客流方向,0:无状态;1:店外徘徊;2:进店;3:店内徘徊;4:出店 :param userType: 客户类型, 0:普通客户;1:会员,2:店员 :param pageNo: 页码 :param pageSize:每页条数 :param res_accurate: :param business_exception: :return: ''' # 参数化 if startDateTime is None: startDateTime = gen_bnsData.random_snap_startDateTime() if endDateTime is None: endDateTime = gen_bnsData.random_snap_endDateTime() if pageNo is None: pageNo = 1 if pageSize is None: pageSize = 20 # 发送业务请求 res_json = self.bns_snap_list(headers=headers, areaCodesList=areaCodesList, deviceCode=deviceCode, deviceType=deviceType, startAgeInit=startAgeInit, endAgeInit=endAgeInit, startDateTime=startDateTime, endDateTime=endDateTime, faceId=faceId, sexInit=sexInit, snapType=snapType, userStatus=userStatus, userType=userType, pageNo=pageNo, pageSize=pageSize,) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 精确返回的内容 if res_accurate: return JsonHelper.parseJson_by_objectpath(res_json, "count($.response_data.data.list)") # 全部信息返回 info_dict = dict() return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:抓拍列表查询") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:抓拍列表查询")
def scn_employee_add(self, mallareaCode, faceId, imagePath, headers=None, employeename=None, phoneNo=None, sex=None, age=None, remark=None, res_accurate=False, business_exception=False): ''' :param headers: :param mallareaCode: 门店编码 :param employeename: 店员姓名 :param phoneNo: 手机号码 :param faceId: 人脸faceId :param imagePath: 图片路径 :param sex: 性别 :param age: 年龄 :param remark: 备注 :param res_accurate: :param business_exception: :return: ''' # 参数化 if employeename is None: employeename = gen_bnsData.random_employee_employeename() if phoneNo is None: phoneNo = StringHelper.get_random_phoneno() if remark is None: remark = gen_bnsData.random_employee_remark() # 发送业务请求 res_json = self.bns_employee_add( headers=headers, mallareaCode=mallareaCode, employeename=employeename, phoneNo=phoneNo, faceId=faceId, imagePath=imagePath, sex=sex, age=age, remark=remark, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 精确返回的内容 if res_accurate: pass # return deviceCode # 全部信息返回 info_dict = dict() if mallareaCode is not None: info_dict.setdefault('mallareaCode', mallareaCode) if employeename is not None: info_dict.setdefault('employeename', employeename) if phoneNo is not None: info_dict.setdefault('phoneNo', phoneNo) if faceId is not None: info_dict.setdefault('faceId', faceId) if imagePath is not None: info_dict.setdefault('imagePath', imagePath) if sex is not None: info_dict.setdefault('sex', sex) if age is not None: info_dict.setdefault('age', age) if remark is not None: info_dict.setdefault('remark', remark) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath( res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:新增店员") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:新增店员")
def scn_node_addCollect(self, headers=None, parentAreaCode=None, nodeName=None, collectTypeId=None, skipTime=None, skipType=None, res_accurate=False, business_exception=False): """ 添加汇总节点 :param headers: :param parentAreaCode: 上级区域编码 :param nodeName: 节点名称 :param collectTypeId: 汇总节点类型 :param skipTime: 门店去重时间 :param skipType:去重时间类型(-1表示自定义,0表示门店去重时间) :param res_accurate: :param business_exception: :return: """ # 参数化 if nodeName is None: nodeName = gen_bnsData.random_node_collectNodeName() if collectTypeId is None: collectTypeId = 1 if skipType is None: skipType = 0 # 发送业务请求 res_json = self.bns_node_addCollect(headers=headers, parentAreaCode=parentAreaCode, nodeName=nodeName, collectTypeId=collectTypeId, skipTime=skipTime, skipType=skipType, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode") areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId") areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType") parentAreaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.parentAreaCode") nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel") # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 精确返回的内容 if res_accurate: return areaCode # 全部信息返回 info_dict = dict() # TODO: 请确认,是否需要接收其他必要信息, 如添加后产生的唯一性标识信息 if areaCode is not None: info_dict.setdefault('areaCode', areaCode) if areaId is not None: info_dict.setdefault('areaId', areaId) if areaType is not None: info_dict.setdefault('areaType', areaType) if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel) if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode) if nodeName is not None: info_dict.setdefault('nodeName', nodeName) if collectTypeId is not None: info_dict.setdefault('collectTypeId', collectTypeId) if skipTime is not None: info_dict.setdefault('skipTime', skipTime) if skipType is not None: info_dict.setdefault('skipType', skipType) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:添加汇总子节点") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:添加汇总子节点")
def scn_node_addThirdPartner(self, headers=None, parentAreaCode=None, partnerName=None, res_accurate=False, business_exception=False): """ 添加三级合作方 :param headers: :param parentAreaCode:上级区域编码 :param partnerName: 合作方名称 :param res_accurate: :param business_exception: :return: """ # 参数化 if partnerName is None: partnerName = gen_bnsData.random_node_thirdPartnerName() # 发送业务请求 res_json = self.bns_node_addThirdPartner(headers=headers, parentAreaCode=parentAreaCode, partnerName=partnerName, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode") areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId") areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType") name = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.name") parentAreaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.parentAreaCode") nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel") # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 精确返回的内容 if res_accurate: return areaCode # 全部信息返回 info_dict = dict() if areaCode is not None: info_dict.setdefault('areaCode', areaCode) if areaId is not None: info_dict.setdefault('areaId', areaId) if areaType is not None: info_dict.setdefault('areaType', areaType) if name is not None: info_dict.setdefault('name', name) if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode) if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:添加三级合作方") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:添加三级合作方")
def test_field_iotDevice_list(self, test_data): first_layer = test_data["first_layer"] sencod_layer = test_data["sencod_layer"] third_layer = test_data["third_layer"] if first_layer: allure.dynamic.epic(first_layer) if sencod_layer: allure.dynamic.feature(sencod_layer) if third_layer: allure.dynamic.story(third_layer) module_key = sys._getframe().f_code.co_name.split("_")[2] test_data = self.parse_csv_param(test_data, module_key) pageNo = test_data["pageNo"] pageSize = test_data["pageSize"] areaCodesList = test_data["areaCodesList"] deviceStatus = test_data["deviceStatus"] deviceCodeOrBar = test_data["deviceCodeOrBar"] deviceType = test_data["deviceType"] manufacturerType = test_data["manufacturerType"] lensType = test_data["lensType"] hardwareVersion = test_data["hardwareVersion"] startDateTime = test_data["startDateTime"] endDateTime = test_data["endDateTime"] with allure.step("步骤: 请求接口"): res_json = api_object_admin.bns_iotDevice_list( pageNo=pageNo, pageSize=pageSize, areaCodesList=areaCodesList, deviceStatus=deviceStatus, deviceCodeOrBar=deviceCodeOrBar, deviceType=deviceType, manufacturerType=manufacturerType, lensType=lensType, hardwareVersion=hardwareVersion, startDateTime=startDateTime, endDateTime=endDateTime, ) with allure.step("步骤: 提取接口的业务状态码"): actual_code = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.code") with allure.step("校验: 业务状态码是否正确"): self.assert_actual_equal_expect("业务状态码", actual_code, test_data["expect_code"]) if test_data["clean_data"]: with allure.step("步骤: 数据清理操作"): # TODO: 调用删除接口 pass generator_objs_list = test_data.get("generator_objs_list") if generator_objs_list: for generator_obj in generator_objs_list: try: generator_obj.__next__() except StopIteration: pass
def scn_node_treeGroup(self, headers=None, parentAreaCode=None, areaType=None, expandAll=None, includeParentNode=None, name=None, nodeLevel=None, provinceCity=None, res_accurate=False, business_exception=False): """ 获取节点树(带节点分组) :param headers: :param parentAreaCode:上级区域编码 :param areaType: 节点类型 :param expandAll: 是否展开所有节点,可选 :param includeParentNode: 是否包含父级节点,可选,默认不包含 :param name: 节点名称 :param nodeLevel: 区域级别 :param provinceCity: 区域位置-省市 :param res_accurate: :param business_exception: :return: """ # 参数化 # if func_param is None: func_param = gen_bnsData.xxx() # 发送业务请求 res_json = self.bns_node_treeGroup(headers=headers, parentAreaCode=parentAreaCode, areaType=areaType, expandAll=expandAll, includeParentNode=includeParentNode, name=name, nodeLevel=nodeLevel, provinceCity=provinceCity, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 精确返回的内容 if res_accurate: pass # return deviceCode # 全部信息返回 info_dict = dict() return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:节点树") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:节点树")
def test_field_node_addShop(self, test_data, depend_nodeInfo): first_layer = test_data["first_layer"] sencod_layer = test_data["sencod_layer"] third_layer = test_data["third_layer"] if first_layer: allure.dynamic.epic(first_layer) if sencod_layer: allure.dynamic.feature(sencod_layer) if third_layer: allure.dynamic.story(third_layer) module_key = sys._getframe().f_code.co_name.split("_")[2] test_data = self.parse_csv_param(test_data, module_key) if test_data["parentAreaCode"] == "d": test_data["parentAreaCode"] = depend_nodeInfo parentAreaCode = test_data["parentAreaCode"] shopName = test_data["shopName"] province = test_data["province"] city = test_data["city"] district = test_data["district"] clerkSim = test_data["clerkSim"] clerkSimType = test_data["clerkSimType"] customerSim = test_data["customerSim"] customerSimType = test_data["customerSimType"] groupId = test_data["groupId"] repeatDate = test_data["repeatDate"] skipTime = test_data["skipTime"] trailSkipTime = test_data["trailSkipTime"] with allure.step("步骤: 请求接口"): res_json = api_object_admin.bns_node_addShop( parentAreaCode=parentAreaCode, shopName=shopName, province=province, city=city, district=district, clerkSim=clerkSim, clerkSimType=clerkSimType, customerSim=customerSim, customerSimType=customerSimType, groupId=groupId, repeatDate=repeatDate, skipTime=skipTime, trailSkipTime=trailSkipTime, ) with allure.step("步骤: 提取接口的业务状态码"): actual_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") with allure.step("校验: 业务状态码是否正确"): self.assert_actual_equal_expect("业务状态码", actual_code, test_data["expect_code"]) if test_data["expect_msg"]: with allure.step("步骤: 提取接口的提示信息"): actual_msg = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.message") with allure.step("校验: 提示信息是否正确"): self.assert_actual_contain_expect("提示信息", actual_msg, test_data["expect_msg"]) if test_data["clean_data"]: with allure.step("步骤: 数据清理操作"): pass generator_objs_list = test_data.get("generator_objs_list") if generator_objs_list: for generator_obj in generator_objs_list: try: generator_obj.__next__() except StopIteration: pass
def positive_check_node(api, res_data): with allure.step("节点详情接口校验"): res_json1 = api.scn_node_detail(areaCode=res_data["areaCode"]) res_data1 = JsonHelper.parseJson_by_objectpath(res_json1, "$.data") AllureHelper.assert_equal("上级节点编码校验", res_data["parentAreaCode"], res_data1["parentAreaCode"]) AllureHelper.assert_equal("节点名称校验", res_data["name"], res_data1["name"]) AllureHelper.assert_equal("节点编码校验", res_data["areaCode"], res_data1["areaCode"]) AllureHelper.assert_equal("节点类型校验", res_data["areaType"], res_data1["areaType"]) AllureHelper.assert_equal("节点等级校验", res_data["nodeLevel"], res_data1["nodeLevel"]) AllureHelper.assert_equal("节点id校验", res_data["areaId"], res_data1["areaId"]) with allure.step("节点列表接口校验"): res_json2 = api.scn_node_list( parentAreaCode=res_data["parentAreaCode"], name=res_data["name"]) res_data2 = JsonHelper.parseJson_by_objectpath(res_json2, "$.data.list[0]") AllureHelper.assert_equal("上级节点编码校验", res_data["parentAreaCode"], res_data2["parentAreaCode"]) AllureHelper.assert_equal("节点编码校验", res_data["areaCode"], res_data2["areaCode"]) AllureHelper.assert_equal("节点名称校验", res_data["name"], res_data2["name"]) AllureHelper.assert_equal("节点类型校验", res_data["areaType"], res_data2["areaType"]) AllureHelper.assert_equal("节点等级校验", res_data["nodeLevel"], res_data2["nodeLevel"]) AllureHelper.assert_equal("节点id校验", res_data["areaId"], res_data2["areaId"]) with allure.step("节点树接口校验"): res_json3 = api.bns_node_tree( parentAreaCode=res_data["parentAreaCode"], nodeLevel=5) res_data3 = JsonHelper.parseJson_by_objectpath( res_json3, "$.response_data.data[@.name is %s][0]" % res_data["name"]) AllureHelper.assert_equal("上级节点编码校验", res_data["parentAreaCode"], res_data3["parentAreaCode"]) AllureHelper.assert_equal("节点名称校验", res_data["name"], res_data3["name"]) AllureHelper.assert_equal("节点编码校验", res_data["areaCode"], res_data3["areaCode"]) AllureHelper.assert_equal("节点类型校验", res_data["areaType"], res_data3["areaType"]) AllureHelper.assert_equal("节点等级校验", res_data["nodeLevel"], res_data3["nodeLevel"]) AllureHelper.assert_equal("节点id校验", res_data["areaId"], res_data3["areaId"]) with allure.step("节点树(有分组)接口校验"): res_json4 = api.bns_node_treeGroup( parentAreaCode=res_data["parentAreaCode"], nodeLevel=5) res_data4 = JsonHelper.parseJson_by_objectpath( res_json4, "$.response_data.data[@.name is %s][0]" % res_data["name"]) AllureHelper.assert_equal("上级节点编码校验", res_data["parentAreaCode"], res_data4["parentAreaCode"]) AllureHelper.assert_equal("节点名称校验", res_data["name"], res_data4["name"]) AllureHelper.assert_equal("节点编码校验", res_data["areaCode"], res_data4["areaCode"]) AllureHelper.assert_equal("节点类型校验", res_data["areaType"], res_data4["areaType"]) AllureHelper.assert_equal("节点等级校验", res_data["nodeLevel"], res_data4["nodeLevel"]) AllureHelper.assert_equal("节点id校验", res_data["areaId"], res_data4["areaId"])
def scn_device_add(self, mallAreaCode, deviceCodeOrBar, areaCodesList, headers=None, deviceName=None, res_accurate=False, business_exception=False): ''' :param headers: :param deviceCodeOrBar: 设备编码/条码 :param deviceName: 设备名称 :param areaCodesList: 挂载节点(区域编码为列表形式) :return: ''' self.set_headers("areaCode", "mallAreaCode") # 参数化 if deviceName is None: deviceName = gen_bnsData.random_device_deviceName() # 发送业务请求 res_json = self.bns_device_add( mallAreaCode=mallAreaCode, headers=headers, deviceCodeOrBar=deviceCodeOrBar, deviceName=deviceName, areaCodesList=areaCodesList, ) # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回 white_list = [200, 201] # 获取当前请求的http状态码 http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code") # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码 if http_code not in white_list: return res_json # 提取业务码 actually_business_code = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.code") # 异常码集合 exception_list = [ # 400004, # 设备类型不合法 ] # 正常业务状态码下, 函数的返回信息 if actually_business_code == 0: # 解析返回信息或调用自定义函数 # 精确返回的内容 if res_accurate: pass # return deviceCode # 全部信息返回 info_dict = dict() if deviceCodeOrBar is not None: info_dict.setdefault('deviceCodeOrBar', deviceCodeOrBar) if deviceName is not None: info_dict.setdefault('deviceName', deviceName) if areaCodesList is not None: info_dict.setdefault('areaCodesList', areaCodesList) return info_dict if info_dict else JsonHelper.parseJson_by_objectpath( res_json, "$.response_data") # 异常业务状态码下(已知异常), 函数的返回信息 elif actually_business_code in exception_list: if business_exception: raise DefinedBusinessException("接口已知业务异常:绑定设备") return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data") # 异常业务状态码下(未知异常), 函数的返回信息 else: raise UndefinedBusinessException("接口未知业务异常:绑定设备")
def test_field_node_addSecondPartner(self, test_data): first_layer = test_data["first_layer"] sencod_layer = test_data["sencod_layer"] third_layer = test_data["third_layer"] if first_layer: allure.dynamic.epic(first_layer) if sencod_layer: allure.dynamic.feature(sencod_layer) if third_layer: allure.dynamic.story(third_layer) module_key = sys._getframe().f_code.co_name.split("_")[2] test_data = self.parse_csv_param(test_data, module_key) parentAreaCode = test_data["parentAreaCode"] partnerName = test_data["partnerName"] with allure.step("步骤: 请求接口"): res_json = api_object_admin.bns_node_addSecondPartner( parentAreaCode=parentAreaCode, partnerName=partnerName, ) with allure.step("步骤: 提取接口的业务状态码"): actual_code = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.code") with allure.step("校验: 业务状态码是否正确"): self.assert_actual_equal_expect("业务状态码", actual_code, test_data["expect_code"]) if test_data["expect_msg"]: with allure.step("步骤: 提取接口的提示信息"): actual_msg = JsonHelper.parseJson_by_objectpath( res_json, "$.response_data.message") with allure.step("校验: 提示信息是否正确"): self.assert_actual_contain_expect("提示信息", actual_msg, test_data["expect_msg"]) if test_data["clean_data"]: with allure.step("步骤: 数据清理操作"): # TODO: 调用删除接口 pass generator_objs_list = test_data.get("generator_objs_list") if generator_objs_list: for generator_obj in generator_objs_list: try: generator_obj.__next__() except StopIteration: pass
def test_field_operateUser_add(self, test_data): first_layer = test_data["first_layer"] sencod_layer = test_data["sencod_layer"] third_layer = test_data["third_layer"] if first_layer: allure.dynamic.epic(first_layer) if sencod_layer: allure.dynamic.feature(sencod_layer) if third_layer: allure.dynamic.story(third_layer) module_key = sys._getframe().f_code.co_name.split("_")[2] test_data = self.parse_csv_param(test_data, module_key) userName = test_data["userName"] userPhone = test_data["userPhone"] roleId = test_data["roleId"] areaCodesList = test_data["areaCodesList"] with allure.step("步骤: 请求接口"): res_json = api_object_admin.bns_operateUser_add( userName=userName, userPhone=userPhone, roleId=roleId, areaCodesList=areaCodesList, ) with allure.step("步骤: 提取接口的业务状态码"): actual_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code") with allure.step("校验: 业务状态码是否正确"): self.assert_actual_equal_expect("业务状态码", actual_code, test_data["expect_code"]) if test_data["expect_msg"]: with allure.step("步骤: 提取接口的提示信息"): actual_msg = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.message") with allure.step("校验: 提示信息是否正确"): self.assert_actual_contain_expect("提示信息", actual_msg, test_data["expect_msg"]) if test_data["clean_data"]: with allure.step("步骤: 数据清理操作"): userInfo = api_object_admin.bns_operateUser_list(userInfo=userPhone) userId = JsonHelper.parseJson_by_objectpath(userInfo, "$..*[@.id]", res_firstOne=True) api_object_admin.bns_operateUser_delete(userId=userId) generator_objs_list = test_data.get("generator_objs_list") if generator_objs_list: for generator_obj in generator_objs_list: try: generator_obj.__next__() except StopIteration: pass