Exemplo n.º 1
0
 def __init__(self):
     self.conn = pymysql.connect(host=config_read_file.get_value("sql", "host"),
                                 user=config_read_file.get_value("sql", "user"),
                                 password=config_read_file.get_value("sql", "password"),
                                 db=config_read_file.get_value("sql", "db"),
                                 port=config_read_file.get_int("sql", "port"),
                                 charset='utf8',
                                 cursorclass=pymysql.cursors.DictCursor)
     self.cursor = self.conn.cursor()
Exemplo n.º 2
0
 def test_user_register(self, one_case):
     logger.info("正在执行第{0}条用例:{1}".format(one_case["case_id"],
                                          one_case["title"]))
     url_new = config_read_file.get_value("api", "url") + one_case["url"]
     new_data = HandleContext.reginster_paramization(one_case["data"])
     logger.info("\n请求url为{0}\ndata为{1}".format(url_new, new_data))
     register = self.resp.sendRequests(method=one_case["method"],
                                       url=url_new,
                                       data=eval(new_data))  # 返回注册响应对象
     try:
         self.assertEqual(one_case["expected"],
                          register.text,
                          msg=one_case["title"])
         result = "True"
         logger.info("\'{0}\'用例执行成功".format(one_case["title"]))
     except AssertionError as err:
         logger.error("{0}用例执行失败,错误信息为: {1}".format(one_case["title"], err))
         result = "False"
         raise err
     finally:
         logger.info("写入结果开始")
         do_excel.write_result(row=one_case["case_id"] + 1,
                               column=8,
                               result=result)
         do_excel.write_result(row=one_case["case_id"] + 1,
                               column=7,
                               result=register.text)
         logger.info("写入结果结束")
Exemplo n.º 3
0
def create_new_user(username, pwd="123456"):
    """
    创建用户信息
    :param renamne:
    :param passwd:
    :return:
    """
    handle_mysql = HandleSql()
    send_resquest = HandleRequest()
    url_new = config_read_file.get_value("api", "url") + "/member/register"
    sql = "select * from member where MobilePhone = %s"
    while True:
        mobile_phone = handle_mysql.create_not_exists_phone()
        data = {"mobilephone": mobile_phone, "pwd": pwd, "regname": username}
        send_resquest.sendRequests("post", url_new, data=data)
        result = handle_mysql.run_sql(sql, args=(mobile_phone, ))
        if result:
            user_id = result["Id"]
            break

    user_dict = {
        username: {
            "Id": user_id,
            "rename": username,
            "mobile_phone": mobile_phone,
            "pwd": pwd
        }
    }

    send_resquest.close()
    handle_mysql.close_mysql()
    return user_dict
Exemplo n.º 4
0
    def __init__(self):

        # 1、定义日志收集器
        self.logger = logging.getLogger(
            config_read_file.get_value("log", "log_name"))
        self.logger.setLevel(config_read_file.get_value("log", "log_level"))

        # 2、定义输出渠道
        # 定义日志输出到控制台
        ch = logging.StreamHandler()
        ch.setLevel(config_read_file.get_value("log", "console_level"))
        # 定义日志输出到文件
        fh = logging.FileHandler(os.path.join(
            LOG_DIR, config_read_file.get_value("log", "log_filename")),
                                 encoding="utf8")
        fh.setLevel(config_read_file.get_value("log", "file_level"))

        # 3、定义输出的 格式
        simple_formatter = logging.Formatter(
            config_read_file.get_value("log", "simple_formatter"))
        complex_formatter = logging.Formatter(
            config_read_file.get_value("log", "complex_formatter"))

        # 4、对接日志输出格式
        ch.setFormatter(simple_formatter)
        fh.setFormatter(complex_formatter)

        # 5、对接
        self.logger.addHandler(ch)
        self.logger.addHandler(fh)
Exemplo n.º 5
0
    def test_user_login(self, one_case):
        logger.info("正在执行第{0}条用例:{1}".format(one_case["case_id"],
                                             one_case["title"]))

        url_new = config_read_file.get_value("api", "url") + one_case["url"]
        new_data = HandleContext.invest_paramization(one_case["data"])
        logger.info("\n请求url为{0}\ndata为{1}".format(url_new, new_data))
        invest = self.resp.sendRequests(method=one_case["method"],
                                        url=url_new,
                                        data=eval(new_data))  # 返回投资的响应对象

        if "加标成功" in invest.text:
            check_sql = one_case["check_sql"]
            if check_sql:
                check_sql = HandleContext.invest_paramization(check_sql)
                mysql_result = self.sql.run_sql(check_sql)
                setattr(HandleContext, "loan_id", mysql_result.get("Id"))

        logger.info("\n响应数据为{1}".format(url_new, invest.text))
        try:
            self.assertEqual(one_case["expected"],
                             invest.text,
                             msg=one_case["title"])
            logger.info("\'{0}\'用例执行成功".format(one_case["title"]))
            result = "True"
        except AssertionError as err:
            logger.error("{0}用例执行失败,错误信息为: {1}".format(one_case["title"], err))
            result = "False"
            raise err
        finally:
            logger.info("写入结果开始")
            do_excel.write_result(row=one_case["case_id"] + 1,
                                  column=8,
                                  result=result)
            do_excel.write_result(row=one_case["case_id"] + 1,
                                  column=7,
                                  result=invest.text)
            logger.info("写入结果结束")
Exemplo n.º 6
0
import unittest
import os
from libs.ddt import ddt, data
from scripts.handle_excel import HandleExcel
from scripts.handle_config import config_read_file
from scripts.constant import DATA_DIR
from scripts.handle_requests import HandleRequest
from scripts.handle_log import logger
from scripts.handle_context import HandleContext

# 读取excel
do_excel = HandleExcel(
    os.path.join(DATA_DIR, config_read_file.get_value("excel", "case_excel")),
    "register")
all_cases = do_excel.get_cases()


@ddt
class TestRegister(unittest.TestCase):
    """
    定义一个测试注册的测试类
    """
    @classmethod
    def setUpClass(cls):
        cls.resp = HandleRequest()
        logger.info("******************************************************")
        logger.info("{0}".format("开始执行用例"))

    @classmethod
    def tearDownClass(cls):
        cls.resp.close()
Exemplo n.º 7
0
import unittest
import os
from libs.ddt import ddt, data
from scripts.handle_excel import HandleExcel
from scripts.handle_config import config_read_file
from scripts.constant import DATA_DIR
from scripts.handle_requests import HandleRequest
from scripts.handle_log import logger
from scripts.handle_context import HandleContext

# 读取excel
do_excel = HandleExcel(os.path.join(DATA_DIR, config_read_file.get_value("excel", "case_excel")), "add")
all_cases = do_excel.get_cases()


@ddt
class TestRecharge(unittest.TestCase):
    """
    定义一个测试加标的测试类
    """

    @classmethod
    def setUpClass(cls):
        cls.resp = HandleRequest()
        logger.info("******************************************************")
        logger.info("{0}".format("开始执行用例"))

    @classmethod
    def tearDownClass(cls):
        cls.resp.close()
        logger.info("{0}".format("执行用例完成"))