コード例 #1
0
    def test_addhierarchy_07(self):
        """
            用例描述:name字段传空
        """
        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已经开始执行')
            conf = Config()
            data = AddHierarchy()

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

        # 获取请求参数
        urls = data.url[4]
        header = data.header[4]
        param = data.data[4]
        env = conf.environment
        responsecode = data.responsecode[4]
        responsesql = data.responsesql[4]
        selectsql = data.selectsql[4]
        errorcode = data.errorcode[4]
        print(param[0])

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

        # 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:
                assert response['body']
                assertbody = Assertions()
                assertbody.assert_text(response['header']['X-Api-Error-Code'],
                                       errorcode)
コード例 #2
0
    def test_addhierarchy_02(self):
        """
            用例描述:创建三级组织
        """

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

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

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

        parentid = SqlResult(selectsql, env).get_sqlresult()

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

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

        #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)

        # 数据库查询结果
        try:
            responsesql = str(responsesql).replace('@sqlresult',
                                                   str(parentid['id']))
            responsesqlresult = SqlResult(responsesql,
                                          env).get_sqlresult_list()
            with allure.step("获取预期结果值成功,查询Sql:{0},查询结果:{1}".format(
                    responsesql, responsesqlresult)):
                log.info('查询结果数据库成功:' + responsesql)
        except:
            log.info('查询结果数据库失败:' + responsesql)

        actual = []
        for i in range(len(responsesqlresult)):
            for k, v in responsesqlresult[i].items():
                actual.append(responsesqlresult[i][k])

        # 增加断言
        assertbody = Assertions()
        with allure.step("接口返回结果:{0}".format(response)):
            assertbody.assert_text(str(response['code']), str(responsecode))
            if response['code'] == responsecode:
                assert param[0]['name'] in actual
コード例 #3
0
    def test_addhierarchy_09(self):
        """
            用例描述:同一层级不同上级name重复
        """
        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已经开始执行')
            conf = Config()
            data = AddHierarchy()

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

        # 获取请求参数
        urls = data.url[6]
        header = data.header[6]
        param = data.data[6]
        env = conf.environment
        responsecode = data.responsecode[6]
        responsesql = data.responsesql[6]
        sqlparentid = data.sqlpid[6]
        sqlname = data.sqlname[6]
        selectsql = data.selectsql[6]

        parentid = SqlResult(selectsql, env).get_sqlresult()

        # 参数化请求参数
        with allure.step("获取输入参数值"):
            try:
                param[0]['parent_id'] = parentid['id']
                param[0]['name'] = '同层级不同上级' + str(int(time.time()))
            except:
                log.info("获取参数失败:{0}".format(param[0]))

        # 请求接口
        api_url = req_url + urls
        print(api_url)
        print(param[0])
        request = Request.Request()
        addname = request.post_request(api_url, json.dumps(param[0]), header)

        # dsqlname = str(sqlname).replace('@sqlresult', str(parentid['id']))
        sqlid = str(sqlparentid).replace('@sqlresult', str(parentid['id']))
        # param[0]['name'] = SqlResult(dsqlname, env).get_sqlresult()['name']
        param[0]['parent_id'] = SqlResult(sqlid, env).get_sqlresult()['id']

        ############################
        print(param[0])

        # post请求

        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)