示例#1
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]
示例#2
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)
    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不一致")
示例#4
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)
示例#5
0
    def test_deletehierarchy_01(self):
        """
            用例描述:正常删除一个层级
        """

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

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

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

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

        # 参数化请求参数
        with allure.step("获取输入参数值"):
            try:
                param[0]['id'].append(ids['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(my_param),
                                            header)
            print(response)

        # 增加断言
        with allure.step("接口返回结果:{0}".format(response)):
            if response['code'] == responsecode:
                assertbody = Assertions()
                assertbody.assert_text(response['body'], True)
    def test_hierarchy_01(self):
        """
            用例描述:获取目录
        """

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

        #获取请求域名
        host = conf.host_debug
        req_url = 'http://' + host
        env = conf.environment
        responsesql = data.responsesql
        responsecode = data.responsecode

        # 获取请求参数
        urls = data.url
        header = data.header

        #请求接口
        api_url = req_url + urls
        request = Request.Request()
        with allure.step("开始请求接口,RUL: {0},header:{1}".format(api_url, header)):
            response = request.get_request(api_url, None, header)
            print(response['body'])

        # 数据库查询结果
        try:
            # print(responsesql)
            responsesqlresult = SqlResult(responsesql, env).get_sqlresult_list()
            print(responsesqlresult)
            with allure.step("获取预期结果值成功"):
                log.info('查询结果数据库成功:' + responsesql)
        except:
            log.info('查询结果数据库失败:' + responsesql)

        print(responsecode)

        # 增加断言
        assertbody = Assertions()
        with allure.step("增加断言,接口返回结果:{0}".format(response)):
            assertbody.assert_text(str(response['code']), str(responsecode))
            if response['code'] == responsecode:
                for i in range(len(responsesqlresult)):
                    for k, v in responsesqlresult[i].items():
                        assertbody.assert_body(response['body'][i], k, responsesqlresult[i][k])
    def test_getproduct_01(self, action):
        """
            用例描述:测试get1
        """

        with allure.step("用例开始"):  # 步骤2,step的参数将会打印到测试报告中
            allure.attach('test2', '开始测试'),

        log = Log.MyLog()
        log.info('文件已经开始执行')
        conf = Config()
        data = AddToCart()
        request = Request.Request(action)

        host = conf.host_debug
        port = conf.portShopService_debug
        req_url = 'http://' + host + ':' + port
        print(req_url)
        urls = data.url
        params = data.data
        header = data.header
        requestsql = data.requestsql
        responsecode = data.responsecode
        #responsesql = data.responsesql
        #connection=SqlResult.connect_mysql()
        with allure.step('请求参数:'):  # 步骤2,step的参数将会打印到测试报告中
            allure.attach(str(urls[0]), '请求url')
            allure.attach(str(params[0][0]), '请求参数:')
            allure.attach(str(urls[0]), '请求heder:')

        sqlresult = SqlResult(requestsql[0], 'debug').get_sqlresult()

        print(sqlresult['id'])

        api_url = req_url + urls[0]
        #print(api_url)
        print(params[0][0])
        params[0][0]['memberId'] = 7
        print(params[0][0])
        #print(header[0])
        response = request.post_request(api_url, params[0][0], header[0])
        with allure.step('执行测试完成:'):  # 步骤2,step的参数将会打印到测试报告中
            allure.attach(str(response['code']), '请求结果')
            allure.attach(str(response['body']), '请求结果体')
        assert response['code'] == responsecode[0]
    def test_getproduct_01(self, action):
        """
            用例描述:测试get1
        """

        with allure.step("浏览商品"):  # 步骤2,step的参数将会打印到测试报告中
            allure.attach('笔记本', '商品1')

        log = Log.MyLog()
        log.info('文件已经开始执行')
        conf = Config()
        data = GetProduct()

        request = Request.Request(action)

        host = conf.host_debug
        port = conf.portShopService_debug
        req_url = 'http://' + host + ':' + port
        print(req_url)
        urls = data.url
        params = data.data
        header = data.header
        requestsql = data.requestsql
        responsecode = data.responsecode
        #responsesql = data.responsesql
        #connection=SqlResult.connect_mysql()
        sqlresult = SqlResult(requestsql[0], 'debug').get_sqlresult()

        print(sqlresult['id'])

        api_url = req_url + urls[0]
        #print(api_url)
        #print(params[0][0])
        #params[0][0]['categoryId']=7
        #print(header[0])
        response = request.get_request(api_url, params[0][0], header[0])
        assert response['code'] == responsecode[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
    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)
    def test_login_01(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[0], env).get_sqlresult()
                params[0][0]['auth'] = sqlresult['register_name']
            except:
                log.info("执行sql报错::" + requestsql[0])

        print(params[0][0])

        # 请求接口
        api_url = req_url + urls[0]
        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[0][0]),
                                            header[0])
            print(response)

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

        # 增加断言
        assertbody = Assertions()
        # if response['code'] == responsecode[0]:
        #     for k, v in responsesqlresult.items():
        #         assertbody.assert_body(response['body'], k,responsesqlresult[k])
        #         if not assertbody.assert_body(response['body'], k, responsesqlresult[k]):
        #             break
        #         allure.attach(k, params[0][0])

        with allure.step("接口返回结果:{0}".format(response)):
            assertbody.assert_text(str(response['code']), str(responsecode[0]))
示例#12
0
    def test_hierarchy_01(self, action):
        """
            用例描述:获取目录
        """

        allure.step("获取目录")

        # 写log
        log = Log.MyLog()
        log.info('文件已经开始执行')
        conf = Config()
        data = GetHierarchy()

        with allure.step("写入Log"):
            allure.attach('写入log', '文件已经开始执行')

        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

        #获取token
        token = Session().get_session('debug')
        print(token)
        dict_token = {'X-Api-Authorization': token}
        header = dict(header)
        header.update(dict_token)
        print(header)

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

        response = request.get_request(api_url, None, header)
        with allure.step("开始请求接口"):
            allure.attach('header', header)
            allure.attach('response', response)
        print(response)

        # 数据库查询结果
        try:
            responsesql = str(responsesql[0]).replace(
                '@sqlresult', str(response['body']['id']))
            responsesqlresult = SqlResult(responsesql, env).get_sqlresult()
            print(responsesqlresult)
            with allure.step("获取预期结果值成功"):
                allure.attach('获取SQL', responsesql)
        except:
            with allure.step("获取预期结果值失败"):
                allure.attach('获取SQL', responsesql)

        print(responsesqlresult['parent_id'])
        # 增加断言
        assertbody = Assertions()
        assertbody.assert_text(str(response['code']), str(responsecode[0]))
        if (response['code'] == responsecode[0]):
            assertbody.assert_body(response['body'], 'id',
                                   responsesqlresult['id'])
            assertbody.assert_text(responsesqlresult['name'],
                                   params[0][0]['name'])
            assertbody.assert_text(str(responsesqlresult['parent_id']), 'None')
            allure.step("断言完成")
        else:
            with allure.step("执行完成,Code不一致"):
                allure.attach('request', params[0][0])