示例#1
0
 def get_response(self,
                  resource_name,
                  index=0,
                  input_json=None,
                  opened_file=None):
     method = self.xml.get_method(resource_name)
     com = CommonMethod()
     url = com.get_endpoints(self.name, self.name,
                             resource_name)  #参数:sup b2c login
     Log().info(
         "=================================%s=============================="
         % resource_name)
     Log().info("Url: %s" % url)
     if input_json is None:
         if self.xml.is_dependence_exist(resource_name, index):
             input_json = self.replace_input_values(resource_name, index)
         else:
             input_json = self.get_input(resource_name, index)
     Log().info("输入: %s" % input_json)
     # 获取结果
     if method == "Mul":
         response = self.run.post_multipart_form_data(
             url, input_json, opened_file)
     else:
         response = self.run.get_json_and_status(method, url, input_json)
         print('response====================:', response)
     return response
示例#2
0
 def get_expected_list_c5(self, resource_name, index=0):
     """
     :param resource_name:
     :param index:
     :return: [1, 3, 33]
     """
     # 期望结果列表
     expected_list = self.xml.get_compare_c5(resource_name, index)[1]
     # sql列表
     sql_list = self.xml.get_compare_c5(resource_name, index)[2]
     com = CommonMethod()
     sql_result = {}
     # 执行sql,得到结果集(字典)
     for e in sql_list.items():
         key = e[0]
         sql = e[1]
         result = com.search_one_from_db(sql, self.name)
         sql_result[key] = result
     # 获取最终各期望结果的值(列表)
     result = []
     for item in expected_list:
         k = item.split(':')[0]
         field_name = item.split(':')[1]
         value = sql_result[k][field_name]
         result.append(value)
     return result
示例#3
0
 def get_actual_list_c4(self, resource_name, index=0):
     """
     :param resource_name:
     :param index:
     :return: {'sup_user_id': 67951, 'login_name': 'wumeng', 'user_status': 1}
     """
     # 获取XML中的field name列表
     actual_list = self.xml.get_compare_c4(resource_name, index)[0]
     # xml中sql列表
     sql_list = self.xml.get_compare_c4(resource_name, index)[2]
     com = CommonMethod()
     sql_result = {}
     # 执行sql,得到结果集
     for e in sql_list.items():
         key = e[0]
         sql = e[1]
         result = com.search_one_from_db(sql, self.name)
         sql_result[key] = result
     # 存储字典格式的实际结果
     result = dict()
     # 将查询到的结果转化成字典
     for item in actual_list:
         k = item.split(':')[0]
         # 字段名称
         field_name = item.split(':')[1]
         # 字段值
         value = sql_result[k][field_name]
         result[field_name] = value
     return result
示例#4
0
 def get_compare_result_c3(self, resource_name, json_response, index=0):
     """
     :param resource_name:
     :param json_response:
     :param index:
     :return:
             Pass --> (True, '')
             Failed --> (False, "字段:'code'的实际结果:'1'不等于期望结果:'11'; 字段:'branchId'在返回的Response中不存在;")
     """
     # 实际结果
     actual_list = self.get_actual_list_c3(resource_name, json_response,
                                           index)
     # 期望结果
     expected_list = self.get_expected_list_c3(resource_name, index)
     com = CommonMethod()
     result = True
     msg = ''
     # 循环对比每一个字段的值
     for i in range(len(actual_list)):
         actual_result = list(actual_list.values())[i]
         field_name = list(actual_list.keys())[i]
         # 先判断该节点是否存在,若不存在,设置result为False,并添加msg
         if actual_result is False:
             result = False
             msg = msg + u"字段:'%s'在返回的Response中不存在; " % field_name
         else:
             # 循环对比每个字段的值
             if com.compare_list(actual_result, expected_list[i]) is False:
                 result = False
                 msg = msg + "字段:'%s'的实际结果列表:%s与期望列表:%s不一致;" % (
                     field_name, actual_result, expected_list[i])
     return result, msg
示例#5
0
 def get_expected_list_c3(self, resource_name, index=0):
     """
     :param resource_name:
     :param index:
     :return: {'result': [true, false, true], 'amount': [315, 317, 2802], 'branchId': ['STD', 'FDG', 'FZ1']}
     """
     # 获取XML中的expected列表
     expected_list = self.xml.get_compare_c3(resource_name, index)[1]
     # 获取XML中的SQL列表
     sql_list = self.xml.get_compare_c3(resource_name, index)[2]
     com = CommonMethod()
     sql_result = {}
     # 执行sql,得到结果集
     for e in sql_list.items():
         key = e[0]
         sql = e[1]
         result = com.search_all_from_db(sql, self.name)
         sql_result[key] = result
     # 获取最终各期望结果的值,类型为列表,元素也是列表,每个列表是对应的字段的值
     result = []
     for item in expected_list:
         k = item.split(':')[0]
         field_name = item.split(':')[1]
         value = sql_result[k][field_name]
         result.append(value)
     return result
示例#6
0
 def get_expected_list_c2(self, resource_name, index=0):
     """
     :param resource_name:
     :param index:
     :return: [1, 'Testing', false]
     """
     # 获取XML中的expected列表
     expected_list = self.xml.get_compare_c2(resource_name, index)[1]
     # 获取XML中的SQL列表
     sql_list = self.xml.get_compare_c2(resource_name, index)[2]
     com = CommonMethod()
     sql_result = {}
     # 执行sql,得到结果集,结果集类型为列表,每个元素为字典
     for e in sql_list.items():
         key = e[0]
         sql = e[1]
         result = com.search_one_from_db(sql, self.name)
         sql_result[key] = result
     # 获取最终各期望结果的值,类型为列表,每个元素为每个字段对应的值
     result = []
     for item in expected_list:
         k = item.split(':')[0]
         field_name = item.split(':')[1]
         value = sql_result[k][field_name]
         # 如果是浮点型,需要做数据处理,去掉小数点后面多余的0
         if isinstance(value, (Decimal, float, int)):
             value = [str(value), int(value)][int(value) == value]
         result.append(value)
     return result
示例#7
0
 def write_back_values(self, resource_name, json_response, index=0):
     write_back_list = self.xml.get_write_back(resource_name, index)
     com = CommonMethod()
     for item in write_back_list:
         json_path = item[1]
         node_path = item[3]
         # 解析json path,获取response中对应的值
         value = com.jsonpath_parse(json_response, json_path)
         # print(value)
         # 将获取的值写入对应节点
         self.xml.modify_write_back(node_path, str(value))
示例#8
0
 def replace_input_values(self, resource_name, index=0):
     com = CommonMethod()
     dependence_list = self.xml.get_dependence(resource_name, index)
     dependence_resource = dependence_list[0]
     dependence_test_index = int(dependence_list[1])
     # 获取dependence的数据
     dependence = self.get_write_back_values(dependence_resource,
                                             dependence_test_index)
     # 获取input json
     input_json = self.get_input(resource_name, index)
     # 替换各json path对应的字段值
     for item in dependence_list[2].items():
         replace_field_name = item[0]
         json_path = item[1]
         new_value = dependence[replace_field_name]
         # 替换input json对应的值
         input_json = com.modify_json_value(input_json, json_path,
                                            new_value)
     return input_json
示例#9
0
 def test_05_batchDeleteCart(self):
     """测试删除购物车列表中某个客户购物车,删除3个客户中第一个客户的购物车"""
     name = "batchDeleteCart"
     # global add_to_cart
     # if all(add_to_cart) is False:
     #     unittest.TestCase.skipTest(self, "加购物车的测试用例,即test_01_addToCart运行失败,故跳过此测试用例")
     result = self.com.get_result(name)
     self.assertEqual(True, result[0], result[1])
     # # =======检查购物车中该客户的商品数量应该为0===============
     # # 获取购物车该客户的商品数量
     rs = self.com.get_response('custCartDetail')
     # 检查返回结果中cartAmount是否为0
     cart_amount = CommonMethod().jsonpath_parse(rs[0], "$..cartAmount")
     self.assertEqual(0, cart_amount[0], '该客户购物车数量不为0')
示例#10
0
 def get_actual_list_c8(self, resource_name, json_response, index=0):
     """
     :param resource_name:
     :param json_response:
     :param index:
     :return: {'code': [67951], 'consigneeAdd': [ 'a','b'], 'custFlag': [true]}
     """
     # json path 列表
     json_path_list = self.xml.get_compare_c8(resource_name, index)[0]
     result = dict()
     # 循环获取各字段的名称和值,并保存到字典result中
     for path in json_path_list:
         # 字段名
         field_name = path.split('.')[-1]
         # 字段值
         value = CommonMethod().jsonpath_parse(json_response, path)
         # 将字段名称和值加入result
         result[field_name] = value
     return result
示例#11
0
 def get_actual_list_c6(self, resource_name, json_response, index=0):
     """
     :param resource_name:
     :param json_response:
     :param index:
     :return: {'code': ["abc"], 'branchId': ['aa', 'ba, 'ca'], 'custId': ['aav', 'bbv', 'ccv']}
     """
     # 从xml文件拿到实际结果的json path 列表
     json_path_list = self.xml.get_compare_c6(resource_name, index)[0]
     result = dict()
     # 循环获取各字段的名称和值,并保存到字典result中
     for path in json_path_list:
         # 字段名称
         field_name = path.split('.')[-1]
         # 字段值
         value = CommonMethod().jsonpath_parse(json_response, path)
         # 将字段名称和值加入result
         result[field_name] = value
     return result
示例#12
0
 def test_06_MobileNextCart(self):
     """测试提交订单进入配送确认, 提交三个客户中第二个客户的所有商品"""
     name = "MobileNextCart"
     # global cart_detail
     # if all(cart_detail) is False:
     #     unittest.TestCase.skipTest(self, "获取购物车商品明细的测试用例,即test_03_custCartDetail未运行或运行失败,故跳过此测试用例")
     cm = CommonMethod()
     # 先检查该客户购物车的状态,是否全部校验通过
     rs = self.com.get_response('getCartStatus')
     status = cm.jsonpath_parse(rs[0], "$..erpCheckStatus")
     # status = [1,1,0]
     if all(status) is False:
         # 若不是全部通过,则等待15秒
         sleep(15)
         # 再次检查status
         rs = self.com.get_response('getCartStatus')
         status = cm.jsonpath_parse(rs[0], "$..erpCheckStatus")
         # status = [0,1,0]
         # print(status)
         if all(status):
             # 如果全部通过
             result = self.com.get_result(name)
             self.assertEqual(True, result[0], result[1])
         elif all(status) is False and any(status):
             # 如果有部分商品通过了校验
             # 获取response
             response = self.com.get_response(name)
             # 因只有部分商品通过校验,故不检查具体的数量
             # 1. 检查code
             code = cm.jsonpath_parse(response[0], "$.code")
             self.assertEqual(1, code[0], 'code的实际结果‘%s’不等于期望结果:‘1’' % code)
             # 2. 检查success
             success = cm.jsonpath_parse(response[0], "$.data.success")
             self.assertEqual(True, success[0],
                              'success的实际结果‘%s’不等于期望结果:‘True’' % success)
             # 3. 检查data.count的值大于0
             count = cm.jsonpath_parse(response[0], "$.data.count")
             self.assertGreater(count[0], 0, 'count的实际结果‘%s’不大于0’' % count)
         else:
             # 无任何商品通过校验,跳过此测试用例
             unittest.TestCase.skipTest(self, "三个测试商品均未通过购物车校验,故跳过此测试用例")
     else:
         result = self.com.get_result(name)
         self.assertEqual(True, result[0], result[1])
示例#13
0
 def get_actual_list_c1(self, resource_name, json_response, index=0):
     """
     :param resource_name:
     :param json_response:
     :param index:
     :return: {'code': [1], 'msg': ['Testing'], 'branchId':['FDG','FDG,'FDG']}
     """
     # 从xml文件拿到实际结果的json path 列表
     json_path_list = self.xml.get_compare_c1(resource_name, index)[0]
     # 定义一个空字典,用来存实际结果,key为字段名,value为该字段在返回的response中的值
     result = dict()
     # 循环获取各字段的名称和值,并保存到字典result中
     for path in json_path_list:
         # 字段名
         field_name = path.split('.')[-1]
         # 值
         value = CommonMethod().jsonpath_parse(json_response, path)
         # 将字段名和值加入result字典中
         result[field_name] = value
     return result
示例#14
0
 def get_actual_list_c3(self, resource_name, json_response, index=0):
     """
     :param resource_name:
     :param json_response:
     :param index:
     :return: [['a','b','c'],[1,2,3,],[true,false,true]]
     """
     # 从xml文件拿到实际结果的json path 列表
     json_path_list = self.xml.get_compare_c3(resource_name, index)[0]
     # 定义一个空字典,用来存实际结果,key为字段名,value为该字段在返回的response中的值
     result = dict()
     # 循环获取各字段的名称和值,并保存到字典result中
     for path in json_path_list:
         # 字段名
         field_name = path.split('.')[-1]
         # 值
         value = CommonMethod().jsonpath_parse(json_response, path)
         # 将字段名和值加入字典result
         result[field_name] = value
     return result