def worker(message):
    logger = GeneralLogger().get_logger(True)
    print("Start")
    logger.info(message + ' info')
    logger.debug(message + ' 调试')
    logger.warning(message + ' 警告')
    logger.error(message + ' 错误')
    print("end")
    print("--------------\n", str(threading.current_thread().ident),
          HandlerFactory.get_stream_value(), "\n-----------------")
Exemplo n.º 2
0
    def test_Case2_Check_Home_Page_Top(self):
        request_API = 'Tournament_Recommend_Get'
        url = base_url + request_API

        querystring = {"limit": "50"}
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        print('请求API为: ' + str(response.url))
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')
Exemplo n.º 3
0
    def test_Case5_Check_Article_List_Get_News_page(self):
        request_API = 'Article_List_Get'
        url = base_url + request_API

        for i in range(10):

            querystring = {
                "channel": "1",
                "limit": "10",
                "page": "1",
                "type": i
            }
            html = requests.request("head", url,
                                    params=querystring)  # 获取封包header
            with self.subTest():
                self.assertEqual(html.status_code, 200,
                                 '回传HTTP状态码不正确')  # 检查HTTP状态码
            response = requests.request("GET",
                                        url,
                                        params=querystring,
                                        timeout=3)  # 发送get请求
            print('请求API为: ' + str(response.url))
            res_time = response.elapsed.total_seconds()
            with self.subTest():  # 检查res_time < 3秒
                self.assertLess(res_time, 3, '请求时间过长')
            print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
            retcode = response.json()  # 获取接口json格式资料
            with self.subTest():
                self.assertEqual(retcode["code"], 1,
                                 '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')
from HTMLReport import GeneralLogger
from HTMLReport.log.HandlerFactory import HandlerFactory


def worker(message):
    logger = GeneralLogger().get_logger(True)
    print("Start")
    logger.info(message + ' info')
    logger.debug(message + ' 调试')
    logger.warning(message + ' 警告')
    logger.error(message + ' 错误')
    print("end")
    print("--------------\n", str(threading.current_thread().ident),
          HandlerFactory.get_stream_value(), "\n-----------------")


GeneralLogger().set_log_path('report/test.log')
GeneralLogger().set_log_by_thread_log(True)
GeneralLogger().set_log_level(logging.DEBUG)
main_logger = GeneralLogger().get_logger()
main_logger.debug('debug')
main_logger.warning('warning')
main_logger.info('info')
main_logger.error('error')

with ThreadPoolExecutor(10) as pool:
    args = 'worker '
    for arg in range(2):
        pool.submit(worker, args + str(arg))
Exemplo n.º 5
0
    def test_Case1_Check_Today_SeriesList(self):
        request_API = 'Series_List_Get'
        url = base_url + request_API
        querystring = {"date": today, "game_id": "0", "limit": "200"}  # 登入使用參數
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')

        querystring = {
            "date": today,
            "game_id": "0",
            "limit": "200",
            "status": "2"
        }  # 登入使用參數
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200, '回传HTTP状态码不正确')
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        res_time = response.elapsed.total_seconds()
        retcode = response.json()  # 获取接口json格式资料
        GeneralLogger().get_logger().info(
            '============================================================数值开始============================================================'
        )
        GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
        GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
        GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
        GeneralLogger().get_logger().info(
            '============================================================数值结束============================================================'
        )
        GeneralLogger().get_logger().info('')
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        with self.subTest():
            self.assertEqual(retcode["code"], 1, '回传状态码不正确')
Exemplo n.º 6
0
    def test_Case3_Check_Article_List(self):
        request_API = 'Article_List_Get'
        url = base_url + request_API

        querystring = {"channel": "26"}
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        print('请求API为: ' + str(response.url))
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')

        querystring = {"channel": "18", "limit": "7"}
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        print('请求API为: ' + str(response.url))
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')

        querystring = {"channel": "27", "limit": "1"}
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        print('请求API为: ' + str(response.url))
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')

        # 抓取最新预测dota的文章
        querystring = {
            "type": "2",
            "limit": "5",
            "game_ids": "0",
            "order": "create_time desc"
        }
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        print('请求API为: ' + str(response.url))
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')

        # 抓取最新预测dota的文章
        querystring = {
            "type": "6",
            "limit": "5",
            "game_ids": "0",
            "order": "create_time desc"
        }
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        print('请求API为: ' + str(response.url))
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')

        querystring = {
            "type": "7",
            "limit": "5",
            "game_ids": "0",
            "order": "create_time desc"
        }
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        print('请求API为: ' + str(response.url))
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')

        # 抓取情报中心dota的文章
        querystring = {"limit": "10", "page": "1", "type": "0"}
        html = requests.request("head", url, params=querystring)  # 获取封包header
        with self.subTest():
            self.assertEqual(html.status_code, 200,
                             '回传HTTP状态码不正确')  # 检查HTTP状态码
        response = requests.request("GET", url, params=querystring,
                                    timeout=3)  # 发送get请求
        print('请求API为: ' + str(response.url))
        res_time = response.elapsed.total_seconds()
        with self.subTest():  # 检查res_time < 3秒
            self.assertLess(res_time, 3, '请求时间过长')
        print("请求时间长为 " + str(res_time))  # 获取请求时间, 单位s
        retcode = response.json()  # 获取接口json格式资料
        with self.subTest():
            self.assertEqual(retcode["code"], 1,
                             '回传状态码不正确')  # 检查return code, 透过dict的方式抓取回应
            GeneralLogger().get_logger().info(
                '============================================================数值开始============================================================'
            )
            GeneralLogger().get_logger().info('请求API为: ' + str(response.url))
            GeneralLogger().get_logger().info("请求时间长为 " + str(res_time))
            GeneralLogger().get_logger().info('请求结果为: ' + str(retcode))
            GeneralLogger().get_logger().info(
                '============================================================数值结束============================================================'
            )
            GeneralLogger().get_logger().info('')