Пример #1
0
    def test_cm(self):
        cookie = test_login.login()
        common_url = conf.ReadConfig().getloginConfigValue('url')
        jsondatas = ['data']
        for i in range(int(get.get_nrows('cm')) - 1):
            #读取jsonpath
            jsonpathexcel = get.get_jsonpath('cm', i + 1)

            # 判断是否执行
            if int(get.get_data('cm', i + 1, 4)) == 1:
                login_url = get.get_data('cm', i + 1, 2)
                url = common_url + login_url
                data = get.get_formdata('cm', i + 1, jsondatas[-1])
                header = {
                    "Content-Type": "application/x-www-form-urlencoded",
                    "Cookie": cookie
                }
                global r
                print url
                if get.get_data('cm', i + 1, 3) == 'post':
                    r = requests.post(url=url, headers=header, data=data)
                    time_consume = r.elapsed.microseconds

                    if checkall.checkall('cm', i + 1, r.status_code,
                                         r.content) == 'pass':
                        set.set_result(2, i + 1, 'pass')
                    elif checkall.checkall('cm', i + 1, r.status_code,
                                           r.content) == 'fail':
                        set.set_result(2, i + 1, 'fail')

                    if jsonpathexcel != '':
                        jsondata = getjson.get_rcontent(
                            json.loads(r.content), jsonpathexcel)
                        jsondatas.append(jsondata)
                    set.set_statuscode(2, i + 1, r.status_code)
                    set.set_content(2, i + 1, r.content.decode('UTF-8'))
                    set.set_sql(2, i + 1, checkdb.check('cm', i + 1)[1])

                elif get.get_data('cm', i + 1, 3) == 'get':
                    r = requests.get(url=url, headers=header, data=data)

                    if checkall.checkall('cm', i + 1, r.status_code,
                                         r.content) == 'pass':
                        set.set_result(2, i + 1, 'pass')
                    elif checkall.checkall('cm', i + 1, r.status_code,
                                           r.content) == 'fail':
                        set.set_result(2, i + 1, 'fail')

                    if jsonpathexcel != '':
                        jsondata = getjson.get_rcontent(
                            json.loads(r.content), jsonpathexcel)
                        jsondatas.append(jsondata)
                    set.set_statuscode(2, i + 1, r.status_code)
                    set.set_content(2, i + 1, r.content.decode('UTF-8'))
                    set.set_sql(2, i + 1, checkdb.check('cm', i + 1)[1])
                    set.set_time(2, i + 1, str(time_consume))

            elif int(get.get_data('cm', i + 1, 4)) == 0:
                print 'not execute'
                set.set_result(2, i + 1, 'not execute')
Пример #2
0
    def test_pd(self):
        cookie = test_login.login()
        common_url = conf.ReadConfig().getloginConfigValue('url')

        for i in range(int(get.get_nrows('pd')) - 1):
            # 判断是否执行
            if int(get.get_data('pd', i + 1, 4)) == 1:
                login_url = get.get_data('pd', i + 1, 2)
                url = common_url + login_url
                data = get.get_formdata('pd', i + 1)
                header = {
                    "Content-Type": "application/x-www-form-urlencoded",
                    "Cookie": cookie
                }
                global r
                print url
                if get.get_data('pd', i + 1, 3) == 'post':
                    r = requests.post(url=url, headers=header, data=data)

                    if checkall.checkall('pd', i + 1, r.status_code,
                                         r.content) == 'pass':
                        set.set_result(1, i + 1, 'pass')
                    elif checkall.checkall('pd', i + 1, r.status_code,
                                           r.content) == 'fail':
                        set.set_result(1, i + 1, 'fail')

                    set.set_statuscode(1, i + 1, r.status_code)
                    set.set_content(1, i + 1, r.content.decode('UTF-8'))
                    set.set_sql(1, i + 1, checkdb.check('pd', i + 1)[1])

                elif get.get_data('pd', i + 1, 3) == 'get':
                    r = requests.get(url=url, headers=header, data=data)

                    if checkall.checkall('pd', i + 1, r.status_code,
                                         r.content) == 'pass':
                        set.set_result(1, i + 1, 'pass')
                    elif checkall.checkall('pd', i + 1, r.status_code,
                                           r.content) == 'fail':
                        set.set_result(1, i + 1, 'fail')

                    set.set_statuscode(1, i + 1, r.status_code)
                    set.set_content(1, i + 1, r.content.decode('UTF-8'))
                    set.set_sql(1, i + 1, checkdb.check('pd', i + 1)[1])

            elif int(get.get_data('pd', i + 1, 4)) == 0:
                print 'not execute'
                set.set_result(1, i + 1, 'not execute')
Пример #3
0
def login():
    common_url = conf.ReadConfig().getloginConfigValue('url')
    login_url = get.get_data('login', 1, 2)
    url = common_url + login_url
    data = json.loads(get.get_data('login', 1, 6))
    header = get.get_data('login', 1, 7)
    global r
    print url
    # 判断是否执行
    if int(get.get_data('login', 1, 4)) == 1:
        if get.get_data('login', 1, 3) == 'post':
            r = requests.post(url=url, data=data, headers=header)
            if checkall.checkall('login', 1, r.status_code,
                                 r.content) == 'pass':
                set.set_result(0, 1, 'pass')
            elif checkall.checkall('login', 1, r.status_code,
                                   r.content) == 'fail':
                set.set_result(0, 1, 'fail')

        elif get.get_data('login', 1, 3) == 'get':
            r = requests.get(url=url, data=data, headers=header)

            if checkall.checkall('login', 1, r.status_code,
                                 r.content) == 'pass':
                set.set_result(0, 1, 'pass')
            elif checkall.checkall('login', 1, r.status_code,
                                   r.content) == 'fail':
                set.set_result(0, 1, 'fail')

    elif int(get.get_data('login', 1, 4)) == 0:
        print 'not execute'
        set.set_result(0, 1, 'not execute')

    #写status_code和content
    set.set_statuscode(0, 1, r.status_code)
    set.set_content(0, 1, r.content)

    cookie = "WQSESSIONID=" + "".join(r.cookies["WQSESSIONID"])
    print cookie
    return cookie