예제 #1
0
 def __init__(self):
     '''日志管理器'''
     self.logger = logging.getLogger(__name__)
     # logger 配置等级
     if Config().get('logging', 'level').upper() not in ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'):
         loglevel = 'INFO'  # 默认日志等级为INFO
     else:
         loglevel = Config().get('logging', 'level').upper()
     self.logger.setLevel(loglevel)
     # logger 输出格式
     # fmt = "[%(asctime)s.%(msecs)03d][%(levelname)s][%(filename)s]%(message)s"
     fmt = "[%(asctime)s.%(msecs)03d][%(levelname)s]%(message)s"
     self.formatter = logging.Formatter(fmt=fmt, datefmt="%Y-%m-%d %H:%M:%S")
     # 判断是否存在handler,避免日志重复打印
     if not self.logger.handlers:
         self.consolelogging()
         # 判断是否打印日志到日志文件
         if Config().get('logging', 'switch') == '0':
             today = time.strftime('%Y%m%d', time.localtime())
             # 按照环境则输出日志文件,test则为服务器,debug为本地
             if Config().get('env', 'env') == 'test':
                 # 测试环境则按照服务器路径输出日志文件
                 file_path1 = 'log_' + today + '.txt'
                 file_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), '../../../Log/', file_path1)
                 self.filelogging(file_path)
             else:
                 # 调试环境,即本地工程,则按照本地路径输出日志文件
                 file_path = os.path.dirname(os.path.dirname(__file__)) + '/Log/log_' + today + '.txt'
                 self.filelogging(file_path)
예제 #2
0
    def setup_class(self):
        self.base = loginAdmin(usr=Config().adminuser, pwd=Config().adminpwd)  # 用同一个登录成功后的session

        addDeleteSql = readYaml(self.yamlfilepath)['data']['savecontNumRule']['deleteSql']  # 删除添加的“自动化新增”规则
        self.db.excute(addDeleteSql)
        # 修改接口数据重置到初始状态
        selectSql = readYaml(self.yamlfilepath)['data']['insertOrUpdateContNum']['resetSql']['selectSql']
        insertSql = readYaml(self.yamlfilepath)['data']['insertOrUpdateContNum']['resetSql']['insertSql']
        updateSql1 = readYaml(self.yamlfilepath)['data']['insertOrUpdateContNum']['resetSql']['updateSql1']
        updateSql2 = readYaml(self.yamlfilepath)['data']['insertOrUpdateContNum']['resetSql']['updateSql2']
        deleteSql = readYaml(self.yamlfilepath)['data']['insertOrUpdateContNum']['resetSql']['deleteSql']
        # 插入数据前先查询数据库里是否有该条记录
        self.db.excute(selectSql)
        if self.db.get_one() == None:  # 没有查到记录时,执行插入
            self.db.excute(insertSql)
        self.db.excute(updateSql1)
        self.db.excute(updateSql2)
        self.db.excute(deleteSql)

        # 修改公司及部门中的编码为null
        resetDeptmentSql = readYaml(self.yamlfilepath)['data']['setupsql']['resetDeptmentSql']
        self.db.excute(resetDeptmentSql)

        # 修改合作车商的编码为null
        resetSpSql = readYaml(self.yamlfilepath)['data']['setupsql']['resetSpSql']
        self.db.excute(resetSpSql)

        # 修改业务类型的编码为null
        resrtProductTypeSql = readYaml(self.yamlfilepath)['data']['setupsql']['resrtProductTypeSql']
        self.db.excute(resrtProductTypeSql)

        # 修改业务来源直客的编码为null
        resrtProductFromSql = readYaml(self.yamlfilepath)['data']['setupsql']['resrtProductFromSql']
        self.db.excute(resrtProductFromSql)
예제 #3
0
    def test_volume(self, case_data):

        for k, v in enumerate(case_dict["test_case"]):  # 遍历用例文件中所有用例的索引和值
            try:
                if case_data == v:
                    # 修改方法的__doc__在下一次调用时生效,此为展示在报告中的用例描述
                    Test_Volume.test_volume.__doc__ = case_dict["test_case"][
                        k + 1]["info"]
            except IndexError:
                pass

        if not self.result["result"]:
            # 查看类变量result的值,如果未False,则前一接口校验错误,此接口标记未失败,节约测试时间
            pytest.xfail("前置接口测试失败,此接口标记为失败")
        time.sleep(case_data["sleep_time"])
        #send_request(_data, _host, _address,_port, _relevance, path, _success)
        code, data = requestSend.send_request(
            case_data, case_dict["testinfo"].get("host"),
            case_dict["testinfo"].get("address"),
            str(case_dict["testinfo"].get("port")), self.relevance, CASE_PATH,
            self.result)
        expected_code = case_data["check"][0]["expected_code"]
        volume_id = data["volume"]["id"]
        self.Assert.assert_code(code, expected_code)
        if case_data["request_type"] == "post":
            self.log.info("保存Volume_id到全局配置文件")
            conf = Config()
            conf.set_conf("test_data", "volume_id", volume_id)
        # 完整校验
        CheckResult.check(case_data["test_name"], case_data["check"][0], code,
                          data, self.relevance, CASE_PATH, self.result)
예제 #4
0
파일: Login.py 프로젝트: hedanhe/ApiTest
def loginWeb(usr=None, pwd=None):
    """
    前台登录
    :param usr:
    :param pwd:
    :return: 返回登录后的session
    """
    base = Base()
    base.server_ip = Config().weburl
    login_api = 'wwwApi/admin/sys/login'
    if usr == None and pwd == None:
        usr, pwd = Config().webuser, Config().webpwd
    else:
        usr, pwd = usr, pwd
    login_data = {'username': usr,
                  'password': pwd,
                  'captcha': '1111'}
    cookies = {'userName': '',
               'userPwd': '',
               'JSESSIONID': '',
               'userSessionId': ''}
    print("本次测试登录账号信息为%s,%s" % (usr, pwd))
    try:
        r = base.sendRequest(login_api, 'POST', data=login_data, cookies=cookies)
        print(r.json())
        assert r.json()['code'] == 200, '前台登录失败'
    except Exception as e:
        raise
    return base
예제 #5
0
파일: Login.py 프로젝트: hedanhe/ApiTest
def loginAdmin(usr=None, pwd=None):
    """
    后台登录
    :param usr:
    :param pwd:
    :return: 返回登录后的session
    """
    base = Base()
    base.server_ip = Config().adminurl
    login_api = 'adminApi/admin/sys/login'
    if usr == None and pwd == None:
        usr, pwd = Config().adminuser, Config().adminpwd
    else:
        usr, pwd = usr, pwd
    login_data = {'username': usr,
                  'password': pwd,
                  'captcha': '1111'}
    # print("本次测试登录账号信息为%s,%s" % (usr, pwd))
    try:
        r = base.sendRequest(login_api, 'POST', data=login_data)
        # print(r.json())
        assert r.json()['code'] == 200, '后台登录失败'
    except Exception as e:
        raise
    return base
예제 #6
0
    def setup_class(self):
        self.base = loginAdmin(usr=Config().adminuser,
                               pwd=Config().adminpwd)  # 用同一个登录成功后的session
        # 删除添加的“自动化新增-按日计息”还款方式
        delteAlreadyExistSql = readYaml(
            self.yamlfilepath)['data']['setupsql']['delteAlreadyExistSql']
        self.db.excute(delteAlreadyExistSql)

        # 修改id=10的还款方式字段值到初始值
        resetStartSQL = readYaml(
            self.yamlfilepath)['data']['setupsql']['resetStartSQL']
        self.db.excute(resetStartSQL)
 def setup_class(cls):
     #初始化用例参数,将全局变量替换成配置文件中得变量
     # cls.rel = ini_rel
     with allure.step("初始化环境变量"):
         cls.log = Log.MyLog()
         cls.Assert = Assert.Assertions()
         cls.log.info("设置project_token_name为amdin")
         conf = Config()
         conf.set_conf("test_data", "project_token_name", "admin")
         cls.result = {"result": True}
         #更新配置文件中的token
         cls.token = Token.Token()
         cls.token.save_token()
예제 #8
0
 def test_0003_user(self):
     """
     :return:
     """
     config = Config()
     header = {
         'Authorization': 'bearer%s' % config.get_kv('token', 'token')
     }
     self.test_0001_get_jsession()
     url = 'https://apitest.chexinhui.com/hiserver/rest/org/user'
     res = self.re_model.get(url, headers=header)
     self.assertEqual('超级管理员',
                      json.loads(res.text)['user']['userFullName'],
                      '服务器通讯不正常,请修复')
     print(json.loads(res.text)['user']['userFullName'])
예제 #9
0
    def test_get_pro(self):
        """
           用例描述:获取商品列表
        :return:
        """
        token = Token.Token()
        conf = Config()
        data = Product()
        test = Assert.Assertions()

        host = conf.host_test
        req_url = 'http://' + host
        urls = req_url + data.url[0]
        headers = token.get_token("test")
        shop_id = data.data
        params = urls + "?" + "shop_id=" + str(shop_id[0])

        response = requests.get(params, headers=headers)
        print("------------------我是可爱的分界线----------------------------")
        r_data = response.json()

        # 断言
        allure.attach('实际结果', '{}'.format(r_data))
        assert test.assert_code(response.status_code, 200)
        assert test.assert_body_key(r_data, 'data')
        assert test.assert_body_key(r_data, 'page')
        assert test.assert_body_key(r_data, 'size')
        assert test.assert_body_key(r_data, 'total')

        Consts.RESULT_LIST.append('True')
예제 #10
0
 def __init__(self):
     self.config = Config()
     self.log = Log.MyLog()
     self.run_path = Config.path_dir
     self.USER_ID = str(get_value("xc手机号"))
     self.picture_verification_code = str(get_value("四位图片验证码"))
     self.login_verification_code = str(get_value("登录验证码"))
예제 #11
0
    def getproduct_01():
        """
            用例描述:测试get1
        """
        conf = Config()
        data = GetProduct()

        host = conf.host_debug
        req_url = 'http://' + host
        urls = data.url
        params = data.data
        header = data.header
        requestsql = data.requestsql
        #connection=SqlResult.connect_mysql()

        sqlresult = SqlResult(requestsql[0])
        print(sqlresult.get_sqlresult())
        for x in (sqlresult):
            for j in x:
                print(j, "=>", x[j])
                print(" ")
            print(x)
        print(sqlresult)
        print(params[0][0])
        api_url = req_url + urls[0]
예제 #12
0
    def test_response_data_format(self):
        """
        用例描述:图书馆标签详情接口状态码返回
        :return:
        """
        conf = Config()
        test = Assert.Assertions()

        host = conf.debug_gossapi_host
        api_url = host + "/library/tagDetail"
        params = Params().encrypt_data({
            "libraryId": 4512154,
            "page": 1,
            "pageSize": 10
        })
        headers = conf.debug_headers

        res = requests.post(api_url, params=params, headers=headers)
        schema = json.load(
            open(conf.json_schema_path + "/library_tag_detail_schema.json"))
        json_data = res.json()

        assert test.assert_code(res.status_code, 200)
        assert test.assert_code(json_data.get("code"), 200)
        assert test.assert_jsonschema(json_data, schema)
예제 #13
0
    def test_basic_01(self, action):
        """
            不在活动时间内
        """
        mysql = Mysql.Mysql()
        time = Tools.acttime()
        outtime = time[0]
        print(outtime)
        sql = "update 111 set `value` = '%s' where `key` = '111'" % outtime
        mysql.update(sql)  # 更改活动时间
        Tools.refresh()  # 刷新配置项

        print("hello")
        conf = Config()
        data = MyTest()
        test = Assert.Assertions()
        request = Request.Request(action)

        host = conf.host_test
        req_url = 'http://' + host
        print(req_url)
        urls = data.url
        params = data.data
        print(params)
        headers = data.header
        api_url = req_url + urls[0]

        response = request.get_request(api_url, params[0], headers[0])
        print(response)

        # assert test.assert_code(response['code'], 200)
        assert test.assert_body(response['body'], 'code', '600000')
        # assert test.assert_time(response['time_consuming'], 100)
        Consts.RESULT_LIST.append('True')
예제 #14
0
 def __init__(self):
     conf = Config()
     self.request = Request.Request()
     self.host = conf.host_debug
     self.test = Assert.Assertions()
     self.login = Login_interface()
     self.g = globals()
예제 #15
0
    def test_order_03(self):
        """
        用例描述:购买单个产品-匹配同一方案下多个计费项(计费项下的策略有按包计费也有按量计费)-支付订单
        """
        data = Order()
        urls = data.url
        params = data.data
        header = data.header
        request = Request.Request()
        Asserts = Assert.Assertions()
        conf = Config()
        host = conf.host
        req_url = 'http://' + host
        api_url = req_url + urls[0]
        sqlinfo = Mysql.Mysqlconnect()

        # 创建订单
        response = request.post_request(api_url, params[3], header[0])
        assert Asserts.assert_in_text(response, 'order_id')
        order_id = response['body']['order_id']

        # 支付订单
        url = req_url + urls[1].replace('{order_id}', order_id)
        request.post_request(url, params[1], header[0])

        #断言支付成功,数据库状态变为paid
        info = sqlinfo.info(
            'subscription',
            'select order_status from prd_order where order_id = "%s"' %
            order_id)
        assert Asserts.assert_exist(info[0], 'paid')
예제 #16
0
    def test_storeget_02(self, action):
        """
            用例描述01:get查询门店无效的字符(####)
        """
        conf = Config()
        data = Storeget()
        test = Assert.Assertions()
        request = Request.Request(action)

        host = conf.host_get
        req_url = 'http://' + host
        print(req_url)
        urls = data.url
        params = data.data
        headers = data.header

        api_url = req_url + urls[1]
        print(api_url)
        response = request.get_request(api_url, params[1], headers[1])
        # r = parse.unquote_plus(response["text"])
        print(response)
        # print(r)
        assert test.assert_code(response['code'], 200)
        # 这个需要url解码才能看出来,并且需要导入包from urllib import  parse,S代表更新成功的意思

        Consts.RESULT_LIST.append('True')
예제 #17
0
    def test_response_data_format(self):
        """
        用例描述:用户年级关系保存接口默认参数状态码返回
        :return:
        """
        conf = Config()
        test = Assert.Assertions()

        host = conf.debug_gossapi_host
        api_url = host + "/userEdu/saveUserGrade"
        params = Params().encrypt_data({
            "openid": "ff5d5663695b00f97015588033c196c7",
            "gradeId": 3,
            "phone": ""
        })
        headers = conf.debug_headers

        res = requests.post(api_url, params=params, headers=headers)
        schema = json.load(
            open(conf.json_schema_path + "/userEdu_saveUserGrade_schema.json"))
        json_data = res.json()

        assert test.assert_code(res.status_code, 200)
        assert test.assert_code(json_data.get("code"), 200)
        assert test.assert_jsonschema(json_data, schema)
예제 #18
0
    def test_response_data_format(self):
        """
        用例描述:VIP商品二维码接口状态码返回
        :return:
        """
        conf = Config()
        test = Assert.Assertions()

        host = conf.debug_gossapi_host
        api_url = host + "/vip/productQrCode"
        params = Params().encrypt_data({
            "openid": "kh54gh2j3g563gc673jh",
            "mobile": "15770843323",
            "product_id": "23",
            "service": "edu.pay",
            "from": "edu"
        })
        headers = conf.debug_headers

        res = requests.post(api_url, params=params, headers=headers)
        schema = json.load(
            open(conf.json_schema_path +
                 "/vip_product_pay_status_schema.json"))
        json_data = res.json()

        assert test.assert_code(res.status_code, 200)
        assert test.assert_code(json_data.get("code"), 200)
        assert test.assert_jsonschema(json_data, schema)
예제 #19
0
 def init_url_headers(self):
     '''
         初始化url和headers
     '''
     self.url = Config().get('url', 'api_url')
     self.headers = {'Content-Type': 'application/json'}
     self.re_list = []
예제 #20
0
    def test_response_data_format(self):
        """
        用例描述:【新版儿童模式】过滤器内容接口默认参数状态码返回
        :return:
        """
        conf = Config()
        test = Assert.Assertions()

        host = conf.debug_gossapi_host
        api_url = host + "/child/filter/content"
        params = Params().encrypt_data({
            "source": "iqiyi",
            "dockId": "1",
            "filters": [{
                "k": "1",
                "v": "1"
            }],
            "page": "1",
            "pageSize": "10",
            "gender": "1",
            "ageDuration": "1"
        })
        headers = conf.debug_headers

        res = requests.post(api_url, params=params, headers=headers)
        print(res.json())
        schema = json.load(
            open(conf.json_schema_path + "/child_filter_content_schema.json"))

        assert test.assert_code(res.status_code, 200)
        assert test.assert_jsonschema(res.json(), schema)
예제 #21
0
    def test_user_01(self):
        """
        用例描述:正常创建用户-正常创建角色-角色关联权限-用户关联角色
        :return:usreid

        """
        data = User()
        urls = data.url
        params = data.data
        request = Request.Request()
        Asserts = Assert.Assertions()
        conf = Config()
        host = conf.host
        session = Session.Session()
        token = session.get_session()[0]
        print(token)
        access_sys_id = session.get_session()[2]
        header = {
            'Authorization': "Bearer " + token,
            'Content-Type': 'application/json'
        }

        # 创建用户
        req_url_user = '******' + host + urls[0]
        response = request.post_request(req_url_user, params[0], header)
        assert Asserts.assert_in_text(response, 'user_id')

        # 创建角色
        req_url_roles = 'http://' + host + urls[1]
        prs = {
            "role_name": "角色名称",
            "access_sys_id": access_sys_id,
            "description": "角色描述"
        }
        response = request.post_request(req_url_roles, prs, header)
예제 #22
0
    def test_login_02(self, action):
        """
            用例描述:用户登录密码错误
        """
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        conf = Config()
        data = Login()
        test = Assert.Assertions()
        #        request = Request.Request(action)

        host = conf.host_release
        req_url = 'https://' + host
        urls = data.url
        params = data.data
        headers = data.header

        api_url = req_url + urls[0]
        datas = params[1][0]
        #        print("api_url==========", api_url)
        #        print("params==========", params[0][0])
        r = requests.post(api_url, data=datas, verify=False)
        re_time = r.elapsed.total_seconds()
        #        print("接口响应时间==========", r.elapsed.total_seconds())
        print("text==========", r.text)
        #        rep_code = r.status_code
        #        assert test.assert_code(rep_code, 200)
        assert test.assert_in_text(r.text, "access_token")
        Consts.STRESS_LIST.append(re_time)
예제 #23
0
    def test_update_product(self):
      token = Token.Token()
      conf = Config()
      data = Update()
      test = Assert.Assertions()

      host = conf.host_test
      req_url = 'http://' + host
      urls = req_url + data.url[0]
      products = data.data
      token = token.get_token("test")
      header = data.header
      header[0].update(token)

      response = requests.post(urls,data=json.dumps(products[0]), headers=header[0])
      print(response)
      print("------------------我是可爱的分界线----------------------------")
      r_data = response.json()

    # 断言
      allure.attach('实际结果', '{}'.format(r_data))
      assert test.assert_code(response.status_code, 200)
      assert test.assert_body(r_data,"message","update product success")

      Consts.RESULT_LIST.append('True')
예제 #24
0
    def test_login_02(self, action):
        """
            用例描述:密码错误数据
        """

        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已经开始执行')
            conf = Config()
            data = Login()

        request = Request.Request(action)

        #获取域名
        host = conf.host_debug
        req_url = 'http://' + host

        #获取请求参数
        urls = data.url
        params = data.data
        header = data.header
        requestsql = data.selectsql
        env = conf.environment
        responsecode = data.responsecode
        responsesql = data.responsesql
        casedescription = data.casedec

        #请求参数化
        with allure.step("获取输入参数值,{0}".format(requestsql[1])):
            try:
                sqlresult = SqlResult(requestsql[1], env).get_sqlresult()
                params[1][0]['auth'] = sqlresult['register_name']
            except:
                log.info("执行sql报错::" + requestsql[1])

        print(params[1][0])

        # 请求接口
        api_url = req_url + urls[1]
        with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(
                api_url, header[0], params[0][0])):
            response = request.post_request(api_url, json.dumps(params[1][0]),
                                            header[1])
            print(response)

        assertbody = Assertions()
        assertbody.assert_text(str(response['code']), str(responsecode[1]))
        with allure.step(
                "增加断言,ResponseCode:{0}=TestCode:{1},ResponseHeader:{2}".format(
                    response['code'], responsecode[1], response['header'])):
            if (response['code'] == responsecode[1]):
                #assertbody.assert_body(response['body'], 'message','密码错误')
                assertbody.assert_body(response['header'], 'X-Api-Error-Code',
                                       'ERR_LOGIN_FAILED')
            else:
                log.info("执行完成,Code不一致")
예제 #25
0
def action_env():
    # 定义环境
    env = Consts.UI_ENVIRONMENT_MOBILE_PHONE_MODEL
    # 定义报告中environment
    conf = Config()
    tester = conf.tester_release
    pytest.allure.environment(environment=env)
    pytest.allure.environment(tester=tester)
    return env
예제 #26
0
class MyDB:
    # 获取数据库的地址host(string类型)、端口port(number类型)、用户名user(string类型)、密码password(string类型)
    global host, port, user, password, database, con
    host = Config().get('mysql', 'host')
    port = int(Config().get('mysql', 'port'))
    user = Config().get('mysql', 'user')
    password = Config().get('mysql', 'password')
    database = Config().get('mysql', 'database')
    con = {
        'host': str(host),
        'port': int(port),
        'user': user,
        'password': password,
        'database': database
    }

    def __init__(self):
        self.db = self.connectDB()
        self.cursor = self.db.cursor()

    def connectDB(self):
        try:
            self.db = pymysql.connect(**con)
            log.info(f'成功连接到数据库')
            return self.db
        except ConnectionError as e:
            log.error(f'连接数据库发生异常:\n{e}')
            raise

    def executeSQL(self, sql):

        self.cursor.execute(sql)
        self.db.commit()
        return self.cursor

    def get_all(self, sql):
        return self.executeSQL(sql).fetchall()

    def get_one(self, sql):
        return self.executeSQL(sql).fetchone()

    def closeDB(self):
        self.db.close()
        log.info('数据库连接关闭!')
예제 #27
0
    def test_updatehierarchy_03(self):
        """
            用例描述:不变层级,名称重复
        """

        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已开始执行')
            conf = Config()
            data = UpdateHierarchy()

        # 获取请求域名
        host = conf.host_debug
        req_url = 'http://' + host

        # 获取请求参数
        urls = data.url[2]
        header = data.header[2]
        param = data.data[2]
        responsecode = data.responsecode[2]
        sql_name = data.sqlname[2]
        env = conf.environment
        selectsql = data.selectsql[2]
        errorcode = data.errorcode[2]
        parentid = SqlResult(selectsql, env).get_sqlresult()

        sqlname = str(sql_name).replace('@sqlresult', str(parentid['parent_id']))
        pname = SqlResult(sqlname, env).get_sqlresult()

        # 参数化请求参数
        with allure.step("获取输入参数值"):
            try:
                param[0]['id'] = parentid['id']
                param[0]['name'] = pname['name']
                param[0]['parent_id'] = parentid['parent_id']
            except:
                log.info("获取参数失败:{0}".format(param[0]))

        # 请求接口
        api_url = req_url + urls
        print(api_url)

        print(param[0])

        # post请求
        request = Request.Request()
        with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(api_url, header, param[0])):
            response = request.post_request(api_url, json.dumps(param[0]), header)
            print(response)

            # 增加断言
            with allure.step("接口返回结果:{0}".format(response)):
                if response['code'] == responsecode:
                    assertbody = Assertions()
                    assertbody.assert_text(response['body'], errorcode)
예제 #28
0
    def test_enablehierarchy_02(self):
        """
            用例描述:正常停用多个组织
        """

        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已开始执行')
            conf = Config()
            data = EnableHierarchy()

        # 获取请求域名
        host = conf.host_debug
        req_url = 'http://' + host

        # 获取请求参数
        urls = data.url[1]
        header = data.header[1]
        param = data.data[1]
        selectsql = data.selectsql[1]
        responsecode = data.responsecode[1]
        env = conf.environment

        ids = SqlResult(selectsql, env).get_sqlresult_list()

        myid = []
        for i in range(len(ids)):
            for k, v in ids[i].items():
                myid.append(ids[i][k])
        print(myid)

        # 参数化请求参数
        with allure.step("获取输入参数值"):
            try:
                param[0]['ids'].extend(myid)
            except:
                log.info("获取参数失败:{0}".format(param[0]))

        # 请求接口
        api_url = req_url + urls

        # post请求
        request = Request.Request()
        with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(
                api_url, header, param[0])):
            response = request.post_request(api_url, json.dumps(param[0]),
                                            header)
            print(response)

        # 增加断言
        with allure.step("接口返回结果:{0}".format(response)):
            if response['code'] == responsecode:
                assertbody = Assertions()
                assertbody.assert_text(response['body'], True)
예제 #29
0
 def test_0002_get_token(self):
     """
     获取token
     :return:
     """
     config = Config()
     data = {
         'username': '******',
         'password': '******',
         'client_id': 'cxh',
         'grant_type': 'password',
         'client_secret': 'password'
     }
     header = {
         'Accept':
         'application/json,text/plain,*/*',
         'Accept-Encoding':
         'gzip,deflate,br',
         'Accept-Language':
         'zh-CN,zh;q=0.9',
         'Connection':
         'keep-alive',
         'Content-Length':
         '86',
         'Content-Type':
         'application/x-www-form-urlencoded',
         'Host':
         'ssotest.chexinhui.com',
         'Origin':
         'https://dshitest.chexinhui.com',
         'Referer':
         'https://dshitest.chexinhui.com/cxh/dist/',
         'User-Agent':
         'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36',
     }
     try:
         res = self.re_model.post(self.rs_oauth, data=data, headers=header)
         config.set_item('token', 'token',
                         json.loads(res.text)['access_token'])
         return json.loads(res.text)['access_token']
     except Exception as e:
         print('连接失败,检查服务器:%s' % e)
예제 #30
0
def action():
    # 定义环境
    env = Consts.API_ENVIRONMENT_DEBUG
    # 定义报告中environment
    conf = Config()
    host = conf.host_debug
    tester = conf.tester_debug
    allure.environment(environment=env)
    allure.environment(hostname=host)
    allure.environment(tester=tester)
    return env