예제 #1
0
 def assertJsonNotNone(self, json_path, json_data):
     result = jsonpath.jsonpath(json_data, json_path)
     record(
         "\njsonpath : '%s'\nget\n'%s'\nfrom\nresult" %
         (json_path, pformat(result)), "json get")
     record("except something", "except not None")
     assert result and result[0]
예제 #2
0
 def assertJsonResponseIn(self, json_path, json_data):
     result = jsonpath.jsonpath(json_data, json_path)
     record(
         "\njsonpath : '%s'\nget\n'%s'\nfrom\nresult" %
         (json_path, pformat(result)), "json get")
     """jsonpath能在json中取到值"""
     assert result
     assert result[0]
예제 #3
0
 def assertJsonMessageContain(self, json_path, json_data, value):
     flag = False
     result = jsonpath.jsonpath(json_data, json_path)
     record(
         "\njsonpath : '%s'\nget\n'%s'\nfrom\nresult" %
         (json_path, pformat(result)), "json get")
     record("except %s" % value, "except: ")
     assert result
     for i in result:
         if value in i.lower():
             flag = True
     assert flag
예제 #4
0
 def assertJsonResponseEqual(self, json_path, json_data, value):
     result = jsonpath.jsonpath(json_data, json_path)
     result = [None] if not result else result
     if "[" not in json_path:
         result = result[0]
     record("\njsonpath : '%s'\nget\n'%s'\nfrom\nresult" %
            (json_path, pformat(result)),
            title="拿到的值")
     record("except %s" % value, title="期望的值")
     """Jsonpath取到的值与value一致"""
     if not result and not value:
         pass
     else:
         self.assertEqual(value, result)
예제 #5
0
 def send_request(self, query_name, variables, has_typename=True):
     query = graphql_query.get_query(query_name, has_typename)
     self.graphql_client.url = self.base_url + "?" + query_name
     result = self.graphql_client(query, variables)
     self.result = result
     try:
         record(self.graphql_client.url, "发送的url")
         record(self.headers, "发送的headers")
         record(pformat(variables), "发送的参数")
         record(pformat(result), "返回的结果")
     except KeyError as e:
         print(e)
     return self
예제 #6
0
    def upload(self, files_name: list):
        files_num = len(files_name)
        # operation 的参数
        file_list = [None for i in range(files_num)]
        # map 的参数
        file_dict = {}
        for i in range(files_num):
            file_dict[str(i + 1)] = ["variables.files.%s" % i]
        self.variables = {
            "operations": (None,
                           json.dumps({
                               "query":
                               graphql_query.get_query(self.api_name),
                               "variables": {
                                   "files": file_list
                               },
                               "operationName":
                               "uploadFiles"
                           })),
            "map": (None, json.dumps(file_dict)),
        }
        # 每个file对应的值
        file_map = {}
        for i in range(files_num):
            file_name = files_name[i]
            file_tuple = {
                str(i + 1): (file_name, find_test_file(file_name),
                             self.get_type(file_name))
            }
            self.variables.update(**file_tuple)

        encode_data = encode_multipart_formdata(self.variables)
        data = encode_data[0]
        self.user.update_headers(**{"Content-Type": encode_data[1]})
        self.result = requests.post(self.user.base_url,
                                    headers=self.user.headers,
                                    data=data).json()
        record(self.result, "上传文件结果")
        return self.result
예제 #7
0
 def assertJsonCountEqual(self, json_path, json_data, num):
     result = jsonpath.jsonpath(json_data, json_path)
     record(
         "\njsonpath : '%s'\nget\n'%s'\nfrom\nresult" %
         (json_path, pformat(result)), "json get")
     if not result:
         count = 0
     else:
         count = len(result)
     record("get numbers %s" % count, "get numbers:")
     record("except %s" % num, "except numbers:")
     assert count == num
예제 #8
0
 def __init__(self, login=None):
     self.base_url = config.get_web_information('url')
     self.platform_url = config.get_web_information('platform_url')
     self.headers = {"Content-Type": "application/json"}
     self.graphql_client = HTTPEndpoint(self.base_url, self.headers)
     self.result = None
     self.num = 0
     self.id = None
     if login:
         try:
             self.login(login)
         except Exception as e:
             record(e)
             record(login)
             record("登录错误")