Exemplo n.º 1
0
class HandleHeader(object):
    def __init__(self):
        file_path = os.path.abspath('..') + '/config/header.json'
        self.handle_json = HandleJson(file_path=file_path)

    # 无token的header
    def get_header(self, type):
        header_data = self.handle_json.read_json()
        header_data = header_data['header'][0][type]
        return header_data

    #md5加密的header
    def header_md5(self, type):
        data = self.get_header(type)
        target = data['token']
        md5 = hashlib.md5()
        md5_str = md5.update(target.encoding('utf-8'))
        data['token'] = md5_str
        return data

    # 带token的header
    def get_token_header(self, data):
        header_data = self.handle_json.read_json()
        header_data['AuthToken'] = data
        return header_data
Exemplo n.º 2
0
class HandleCookie(object):
    def __init__(self):
        file_path = os.path.abspath('..') + '/config/cookie.json'
        self.handle_json = HandleJson(file_path=file_path)

    def get_cookie_value(self, cookie_key):
        data = self.handle_json.read_json()
        cookie_data = data[cookie_key]
        return cookie_data

    def write_cookie(self, cookie_key, cookie_data):
        data = self.handle_json.read_json()
        data[cookie_key] = cookie_data
        self.handle_json.write_value(data)
Exemplo n.º 3
0
class HandleResult(object):
    def __init__(self):
        self.handle_json = HandleJson()

    def get_msg(self, key_url, code, file_path=None):
        if file_path == None:
            self.file_path = os.path.abspath(
                '..') + '/config/code_message.json'
        else:
            self.file_path = file_path
        data = self.handle_json.get_data(file_path=self.file_path, key=key_url)
        if data != None:
            for i in data:
                msg = i.get(code)
                if msg != None:
                    return msg
        return None

    def get_result_json(self, key_url, key, file_path=None):
        if file_path == None:
            self.file_path = os.path.abspath(
                '..') + '/config/expect_result.json'
        else:
            self.file_path = file_path
        data = self.handle_json.get_data(file_path=self.file_path, key=key_url)
        if data != None:
            for i in data:
                json_data = i.get(key)
                if json_data != None:
                    return json_data
        return None

    # 校验格式,只比较key
    def handle_result_json(self, dict1, dict2):

        if isinstance(dict1, dict) and isinstance(dict2, dict):
            cmp_dict = DeepDiff(dict1, dict2, ignore_order=True).to_dict()
            if cmp_dict.get('dictionary_item_removed') or cmp_dict.get(
                    'dictionary_item_added') or cmp_dict.get('type_changes'):
                return False
            else:
                return True
        return False
 def response(self, flow):
     if 'meis' in self.request_url:
         response_data = flow.response
         host = self.request_url.split('meis')[0]
         print(host)
         base_url = host[0]
         url = host[1]
         if '?' in host[1]:
             url = url.split('?')[0]
         data = HandleJson().get_value(url)
         print('=========data:', data)
         response_data.set_text(json.dumps(data))
         '''
Exemplo n.º 5
0
 def __init__(self):
     self.handle_json = HandleJson()
# -*- coding:utf-8 -*-
__author__ = "leo"

import os

from util.handle_json import HandleJson

handle_json = HandleJson()
base_path = os.path.dirname(os.getcwd())


def get_cookie_value(cookie_key):
    data = handle_json.read_json(file_name="/config/cookie.json")
    return data[cookie_key]


def write_cookie(data_input, cookie_key):
    data = handle_json.read_json(file_name="/config/cookie.json")
    data[cookie_key] = data_input
    handle_json.write_value(data)


if __name__ == '__main__':
    get_cookie_value()

Exemplo n.º 7
0
 def get_json_value(self, url):
     data = HandleJson().get_value(url, 'user_data.json')
     return data
Exemplo n.º 8
0
 def get_json_values(self):
     data = HandleJson().read_json('user_data.json')
     return data
Exemplo n.º 9
0
 def get_header(self):
     headers = HandleJson().read_json('header.json')
     return headers
Exemplo n.º 10
0
 def __init__(self):
     file_path = os.path.abspath('..') + '/config/header.json'
     self.handle_json = HandleJson(file_path=file_path)
Exemplo n.º 11
0
 def write_cookie(self, data, cookie_key):
     json_data = self.get_cookie_value(cookie_key)
     json_data[cookie_key] = data
     HandleJson().write_value('cookie.json', json_data)
Exemplo n.º 12
0
 def get_cookies(self):
     json_data = HandleJson().read_json('cookie.json')
     return json_data
Exemplo n.º 13
0
 def setUp(self):
     self.data = HandleJson().get_data('/register')