Beispiel #1
0
def start_module(project_module_start):
    logger.info("==========开始执行测试用例集===========")
    headers = project_module_start[0]
    logger.info("开始执行 ------- {0} 用例".format(caseList['description']))
    ret = BaseRequest(url=caseList['url'], headers=project_module_start[0], method=caseList['method'],
                      data=eval(caseList['parm'])).get_json()
    # 将 token 加入到请求投中
    if ret['data'] != None and 'token' in ret['data']:
        headers['Authorization'] = ret['data']['token']
    yield (headers, project_module_start[1])
    logger.info("==========结束执行测试用例集===========")
Beispiel #2
0
    def test_P1_AddUser(self, start_module, item):
        logger.info("开始执行 ------- {0} 用例".format(item['description']))

        ret = BaseRequest(url=item['url'],
                          headers=start_module[0],
                          method=item['method'],
                          data=eval(item['parm'])).get_json()

        logger.info("请求发送后,开始进行 mysql 数据库检查")
        logger.info("sql:{0}".format(str(item['sql'])))
        try:
            logger.info("开始进行 返回值 断言")
            logger.info("返回值-期望值:{0}".format(str(item['excepted'])))
            logger.info("返回值-实际值:{0}".format(str(ret['meta']['status'])))
            assert str(item['excepted']) == str(ret['meta']['status'])
            logger.info("结束进行 返回值 断言,断言结果: PASS ")
            for sql in eval(item['sql']):
                after_ret = start_module[1].select(sql)
                logger.info("sql返回结果 {0}".format(str(after_ret)))
                logger.info("开始进行 数据库 断言")
                logger.info("数据库-期望值:{0}".format(
                    eval(item['parm'])['username']))
                if len(after_ret) == 0:
                    DE.write_data(item['sheetname'], item['id'] + 1, 10,
                                  'sql返回结果为空')
                    logger.info("数据库-实际值:{0}".format(str(after_ret)))
                    assert after_ret == eval(item['parm'])['username']
                else:
                    DE.write_data(item['sheetname'], item['id'] + 1, 10,
                                  str(after_ret))
                    logger.info("实际值:{0}".format(str(after_ret[0][1])))
                    assert after_ret[0][1] == eval(item['parm'])['username']
                    logger.info("结束进行 数据库 断言,断言结果: PASS ")
            TestResult = 'PASS'
            DE.write_data(item['sheetname'], item['id'] + 1, 11, str(ret))
            logger.info("接口测试结果:{0}".format(TestResult))
            DE.write_data(item['sheetname'], item['id'] + 1, 12, TestResult)
        except AssertionError as e:
            TestResult = 'Fail'
            DE.write_data(item['sheetname'], item['id'] + 1, 13, str(e))
            logger.error("断言失败:{0}".format(str(e)))
            DE.write_data(item['sheetname'], item['id'] + 1, 11, str(ret))
            logger.info("接口测试结果:{0}".format(TestResult))
            DE.write_data(item['sheetname'], item['id'] + 1, 12, TestResult)
            raise
    def test_P3_AddUser(self, start_module, item):
        logger.info("开始执行 ------- {0} 用例".format(item['description']))
        ret = BaseRequest(url=item['url'],
                          headers=start_module[0],
                          method=item['method'],
                          data=eval(item['parm'])).get_json()

        try:
            logger.info("期望值:{0}".format(str(item['excepted'])))
            logger.info("实际值:{0}".format(str(ret['meta']['status'])))
            assert str(item['excepted']) == str(ret['meta']['status'])
            TestResult = 'PASS'
            DE.write_data(item['sheetname'], item['id'] + 1, 11, str(ret))
            logger.info("接口测试结果:{0}".format(TestResult))
            DE.write_data(item['sheetname'], item['id'] + 1, 12, TestResult)
        except AssertionError as e:
            TestResult = 'Fail'
            DE.write_data(item['sheetname'], item['id'] + 1, 13, str(e))
            logger.error("断言失败:{0}".format(str(e)))
            DE.write_data(item['sheetname'], item['id'] + 1, 11, str(ret))
            logger.info("接口测试结果:{0}".format(TestResult))
            DE.write_data(item['sheetname'], item['id'] + 1, 12, TestResult)
            raise