Esempio n. 1
0
    def __init__(self, name=None):
        # 1、创建Logger对象
        # 相当于日志记录工具
        if name is None:
            self.my_logger = logging.getLogger("testcase")
        else:
            self.my_logger = logging.getLogger(name)

        # 2、设置日志器的日志等级
        # self.my_logger.setLevel("DEBUG")
        self.my_logger.setLevel(do_yaml.get_data("log", "logger_level"))

        # 3、创建日志输出渠道(日志显示的地方)
        console_handler = logging.StreamHandler()
        console_handler.setLevel("WARNING")

        # file_handler = logging.FileHandler("testcase.log", encoding="utf-8")
        file_handler = logging.FileHandler(do_yaml.get_data("log", "log_filename"), encoding="utf-8")

        # 4、创建日志的显示样式(格式)并与渠道进行关联
        formater = logging.Formatter('%(asctime)s - [%(levelname)s] - [msg]: %(message)s - %(name)s - %(lineno)d')
        console_handler.setFormatter(formater)
        file_handler.setFormatter(formater)

        # 5、日志器对象与日志输出渠道(展示的地方)进行关联
        self.my_logger.addHandler(console_handler)
        self.my_logger.addHandler(file_handler)
Esempio n. 2
0
    def test_register(self, one_testcase):

        new_url = do_yaml.get_data("api", "base_url") + one_testcase.url
        res = self.do_request.send(one_testcase.method,
                                   new_url,
                                   json=one_testcase.data)

        real_code = res.json()["code"]
        # row = testcase_dict["id"] + 1
        # self.do_excel.write_data(row, 7, res.text)
        # name = testcase_dict["name"]
        try:
            self.assertEqual(one_testcase.expected_value, real_code,
                             one_testcase.name)
        except AssertionError as e:
            # print("此处需要使用日志器来记录日志!")
            # my_logger.error(f"{one_testcase.name}:具体异常为{e}")
            do_log.error(f"{one_testcase.name}:具体异常为{e}")
            # print(f"具体异常为:{e}")
            # self.do_excel.write_data(row, 8, "失败")
            self.do_excel.write_data(one_testcase, res.text, "失败")
            raise e
        else:
            # self.do_excel.write_data(row, 8, "成功")
            # do_log.debug(res.text)
            self.do_excel.write_data(one_testcase, res.text, "成功")
Esempio n. 3
0
    def setUpClass(cls):
        # 3、构造请求参数
        cls.do_request = HandleRequest()

        # headers_dict = {
        #     "X-Lemonban-Media-Type": "lemonban.v2"
        # }
        cls.do_request.add_headers(do_yaml.get_data("api", "api_version"))
        do_log.info("开始执行用例")
Esempio n. 4
0
 def test_register(self, testcase_dict):
     res = self.do_request.send(testcase_dict["method"],
                                testcase_dict["url"],
                                json=testcase_dict["data"])
     real_code = res.json()["code"]
     row = testcase_dict["id"] + 1
     self.do_excel.write_data(
         row, do_yaml.get_data("excel", "real_result_column"), res.text)
     type(res.text)
     try:
         self.assertEqual(testcase_dict["expected_value"], real_code,
                          testcase_dict["name"])
     except AssertionError as e:
         do_excel.write_data(row, do_yaml.get_data("excel",
                                                   "result_column"), "失败")
         raise e
     else:
         do_excel.write_data(row, do_yaml.get_data("excel",
                                                   "result_column"), "成功")
Esempio n. 5
0
 def test_register(self, one_testcase):
     res = self.do_request.send(one_testcase["method"],
                                one_testcase["url"],
                                json=one_testcase["data"])
     real_code = res.json()["code"]
     # row = one_testcase["id"] + 1
     # self.do_excel.write_data(row, do_yaml.get_data("excel", "real_result_column"), res.text)
     # type(res.text)
     try:
         self.assertEqual(one_testcase["expected_value"], real_code,
                          one_testcase["name"])
     except AssertionError as e:
         do_log.error(f"{one_testcase}:具体异常为{e}")
         do_excel.write_data(one_testcase,
                             do_yaml.get_data("excel", "result_column"),
                             "失败")
         raise e
     else:
         do_log.debug(res.text)
         do_excel.write_data(one_testcase,
                             do_yaml.get_data("excel", "result_column"),
                             "成功")
Esempio n. 6
0
    def __init__(self, name=None):
        if name is None:
            self.my_logger = logging.getLogger("testcase.log")
        else:
            self.my_logger = logging.getLogger(name)
        self.my_logger.setLevel(do_yaml.get_data("log",
                                                 "logger_level"))  # 创建日志等级
        console_handler = logging.StreamHandler()  # 创建控制台输入日志
        console_handler.setLevel("DEBUG")  # 创建控制台日志输出的等级

        if name is None:
            file_hander = logging.FileHandler(do_yaml.get_data(
                "log", "log_filename"),
                                              encoding="utf-8")
        else:
            file_hander = logging.FileHandler(
                name, encoding="utf-8")  # 创建在文本日志里面的日志文件
        farmter = logging.Formatter(
            '%(asctime)s - [%(levelname)s] - [msg]: %(message)s - %(name)s - %(lineno)d'
        )
        console_handler.setFormatter(farmter)  # 将样式与日志器关联,用setFormater
        file_hander.setFormatter(farmter)
        self.my_logger.addHandler(console_handler)  # 日志对象与输出渠道关联
        self.my_logger.addHandler(file_hander)
Esempio n. 7
0
    def test_login(self, one_testcase):

        new_url = do_yaml.get_data("api", "base_url") + one_testcase.url
        res = self.do_request.send(one_testcase.method,
                                   new_url,
                                   json=one_testcase.data)

        # real_code = res.json()["code"]
        try:
            self.assertIn(one_testcase.expected_value, res.text,
                          one_testcase.name)
        except AssertionError as e:
            # my_logger.error(f"{one_testcase.name}:具体异常为{e}")
            do_log.error(f"{one_testcase.name}:具体异常为{e}")
            self.do_excel.write_data(one_testcase, res.text, "失败")
            raise e
        else:
            self.do_excel.write_data(one_testcase, res.text, "成功")
Esempio n. 8
0
class TestLogin(unittest.TestCase):
    do_excel = HandleExcel(do_yaml.get_data("excel", "filename"), "login")
    testcases_data = do_excel.read_data()  # 嵌套字典的列表

    @classmethod
    def setUpClass(cls):
        # 3、构造请求参数
        cls.do_request = HandleRequest()

        cls.do_request.add_headers(do_yaml.get_data("api", "api_version"))
        do_log.info("开始执行用例")

    @classmethod
    def tearDownClass(cls):
        cls.do_request.close()
        do_log.info("用例执行结束")

    @ddt.data(*testcases_data)
    def test_login(self, one_testcase):

        new_url = do_yaml.get_data("api", "base_url") + one_testcase.url
        res = self.do_request.send(one_testcase.method,
                                   new_url,
                                   json=one_testcase.data)

        # real_code = res.json()["code"]
        try:
            self.assertIn(one_testcase.expected_value, res.text,
                          one_testcase.name)
        except AssertionError as e:
            # my_logger.error(f"{one_testcase.name}:具体异常为{e}")
            do_log.error(f"{one_testcase.name}:具体异常为{e}")
            self.do_excel.write_data(one_testcase, res.text, "失败")
            raise e
        else:
            self.do_excel.write_data(one_testcase, res.text, "成功")
Esempio n. 9
0
    def setUpClass(cls):
        # 3、构造请求参数
        cls.do_request = HandleRequest()

        cls.do_request.add_headers(do_yaml.get_data("api", "api_version"))
        do_log.info("开始执行用例")
Esempio n. 10
0
  @Company: 湖南省零檬信息技术有限公司
  @Copyright: 柠檬班
-------------------------------------------------
"""
# python中的内置模块(框架)
# 0、导入unittest模块
import unittest

import ddt
from handle_request import HandleRequest
from handel_excel import HandelExcel
from handle_yaml import do_yaml
from handle_log import do_log

excel_name = "testcase.xlsx"
do_excel = HandelExcel(do_yaml.get_data("excel", "filename"), "register")
testcase_data = do_excel.read_data()  # 嵌套字典的列表


# 1、使用@ddt.ddt作为类的装饰器
@ddt.ddt
class TestRegister(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        # 3、构造请求参数
        cls.do_request = HandleRequest()
        cls.do_request.add_headers(do_yaml.get_data("api", "api_version"))
        do_log.info("开始执行用例")

    @classmethod
    def tearDownClass(cls):
Esempio n. 11
0
  @Motto: ABC(Always Be Coding)
  @Email: [email protected]
  @Company: 湖南省零檬信息技术有限公司
  @Copyright: 柠檬班
-------------------------------------------------
"""
import unittest

from HTMLTestRunnerNew import HTMLTestRunner
from handle_yaml import do_yaml

suite = unittest.defaultTestLoader.discover(".")
#
# with open("testcase1.html", "wb") as file:
#     runner = HTMLTestRunner(file,
#                             verbosity=1,
#                             title="py28期第一份测试报告",
#                             description="非常美的报告",
#                             tester="滔滔")
#     runner.run(suite)

html_filename = do_yaml.get_data("report", "filename")
with open(html_filename, "wb") as file:
    runner = HTMLTestRunner(file,
                            verbosity=do_yaml.get_data("report", "verbosity"),
                            title=do_yaml.get_data("report", "title"),
                            description=do_yaml.get_data(
                                "report", "description"),
                            tester=do_yaml.get_data("report", "tester"))
    runner.run(suite)
Esempio n. 12
0
class TestRegister(unittest.TestCase):
    # excel_filename = "testcase.xlsx"
    do_excel = HandleExcel(do_yaml.get_data("excel", "filename"), "register")
    testcases_data = do_excel.read_data()  # 嵌套字典的列表

    @classmethod
    def setUpClass(cls):
        # 3、构造请求参数
        cls.do_request = HandleRequest()

        # headers_dict = {
        #     "X-Lemonban-Media-Type": "lemonban.v2"
        # }
        cls.do_request.add_headers(do_yaml.get_data("api", "api_version"))
        do_log.info("开始执行用例")

    @classmethod
    def tearDownClass(cls):
        cls.do_request.close()
        do_log.info("用例执行结束")

    """
    @ddt.data(*testcases_data)
    def test_register(self, testcase_dict):
        # testcase_dict.method
        
        res = self.do_request.send(testcase_dict["method"],
                                   testcase_dict["url"],
                                   json=testcase_dict["data"])

        real_code = res.json()["code"]
        row = testcase_dict["id"] + 1
        self.do_excel.write_data(row, 7, res.text)
        name = testcase_dict["name"]
        try:
            self.assertEqual(testcase_dict["expected_value"],
                             real_code,
                             testcase_dict["name"])
        except AssertionError as e:
            # print("此处需要使用日志器来记录日志!")
            my_logger.error(f"{name}:具体异常为{e}")
            # print(f"具体异常为:{e}")
            self.do_excel.write_data(row, 8, "失败")
            raise e
        else:
            self.do_excel.write_data(row, 8, "成功")
    """

    @ddt.data(*testcases_data)
    def test_register(self, one_testcase):

        new_url = do_yaml.get_data("api", "base_url") + one_testcase.url
        res = self.do_request.send(one_testcase.method,
                                   new_url,
                                   json=one_testcase.data)

        real_code = res.json()["code"]
        # row = testcase_dict["id"] + 1
        # self.do_excel.write_data(row, 7, res.text)
        # name = testcase_dict["name"]
        try:
            self.assertEqual(one_testcase.expected_value, real_code,
                             one_testcase.name)
        except AssertionError as e:
            # print("此处需要使用日志器来记录日志!")
            # my_logger.error(f"{one_testcase.name}:具体异常为{e}")
            do_log.error(f"{one_testcase.name}:具体异常为{e}")
            # print(f"具体异常为:{e}")
            # self.do_excel.write_data(row, 8, "失败")
            self.do_excel.write_data(one_testcase, res.text, "失败")
            raise e
        else:
            # self.do_excel.write_data(row, 8, "成功")
            # do_log.debug(res.text)
            self.do_excel.write_data(one_testcase, res.text, "成功")