Exemplo n.º 1
0
class ApiRequests:
    def __init__(self):
        self.log = MyLogs()

    def api_request(self, http_method, api_url, api_header, param, file=None):
        if http_method.upper() == "POST":
            try:
                self.log.info("正在进行post请求")
                res = requests.post(api_url,
                                    json=param,
                                    headers=api_header,
                                    files=file)
            except BaseException as e:
                self.log.error("post请求出现异常")
                raise e
        elif http_method.upper() == "GET":
            try:
                self.log.info("正在进行get请求")
                res = requests.get(api_url, json=param, headers=api_header)
            except BaseException as e:
                self.log.error("get请求出现异常")
                raise e
        else:
            self.log.error("请求方式不正确")
        return res
Exemplo n.º 2
0
 def read_config(self, filename, section, option):
     cf = configparser.ConfigParser()
     try:
         cf.read(filename)
     except Exception as e:
         MyLogs().error("打开配置文件异常:{0}".format(e))
     else:
         try:
             res = cf.get(section, option)
         except Exception as e:
             MyLogs().error("读取配置文件失败{0}".format(e))
     return res
Exemplo n.º 3
0
 def data_re(self, pattern, string, object):
     for i in range(20):
         if re.search(pattern, string):
             res = re.search(pattern, string)
             key = res.group(0)
             value = res.group(1)
             try:
                 MyLogs().info("正在获取动态参数:{0}获取的参数是:{1}".format(
                     key, str(getattr(object, value))))
                 string = string.replace(key, str(getattr(object, value)))
             except Exception as e:
                 MyLogs().error("参数替换失败{0}".format(e))
         else:
             string = string
     return string
Exemplo n.º 4
0
 def setUpClass(cls):
     cls.log = MyLogs()
     cls.read_data = ReadDatas(DataPaths.DatasPath)
     cls.re = DataRe()
     cls.api = ApiRequests()
Exemplo n.º 5
0
 def __init__(self):
     self.log = MyLogs()
Exemplo n.º 6
0
def output(title, url, header, param, expected):
    MyLogs().info("测试标题是:{0}".format(title))
    MyLogs().info("测试的地址是:{0}".format(url))
    MyLogs().info("测试的header是:{0}".format(header))
    MyLogs().info("测试的参数是:{0}".format(param))
    MyLogs().info("预期结果是:{0}".format(expected))
Exemplo n.º 7
0
Arquivo: run.py Projeto: yinhuajun/UBT
# @Author   :Tester_Liang
# @Email    :[email protected]
# @File     :run.py
# @software :PyCharm

from BusProject.Linebus_Platform_API import HTMLTestRunnerNew
from BusProject.Linebus_Platform_API.common import DataPaths
from BusProject.Linebus_Platform_API.common.suite_case import SuiteCase
from BusProject.Linebus_Platform_API.common.read_config import Read_Config
from BusProject.Linebus_Platform_API.common.MyLog import MyLogs

with open(DataPaths.ReportPath, 'wb+') as file:
    button = Read_Config().read_config(DataPaths.ConfigPath, 'CASE', 'switch')
    caselist = eval(Read_Config().read_config(DataPaths.ConfigPath, 'CASE',
                                              'caselist'))
    casedir = Read_Config().read_config(DataPaths.ConfigPath, 'DIR', 'switch')
    if casedir.upper() == "ALL":
        casepath = DataPaths.CasePath
    else:
        casepath = DataPaths.CasePath + '/{0}'.format(casedir)
    suite = SuiteCase().suitecase(casepath, button, caselist)
    runner = HTMLTestRunnerNew.HTMLTestRunner(file,
                                              verbosity=2,
                                              title="Linebus_Platform_API",
                                              description="2019/5/28",
                                              tester='Tester_yin')
    try:
        runner.run(suite)
    except Exception as e:
        MyLogs().error("执行用例失败:{0}".format(e))