def run(): host = '0.0.0.0' port = 24579 init_logging() http_server = WSGIServer((host, port), create_app()) logging.getLogger(__name__).info("Server start at %s:%s" % (host, port)) http_server.serve_forever()
def test01_login_success(self): app.init_logging() # 获取令牌 response = self.emp_api.login("13800000002", "123456") logging.info("员工模块登录结果为:{}".format(response.json())) token = "Bearer " + response.json().get("data") logging.info("取出令牌为{}".format(token)) headers = {"Content-Type": "application/json", "Authorization": token} app.HEADRES = headers logging.info("员工请求模块为:{}".format(app.HEADRES))
def read_query_emp(): app.init_logging() query_emp_data_path = app.BASEDIR + "/data/emp_data.json" query_emp_result_list = [] with open(query_emp_data_path, mode='r', encoding='utf-8') as f: jsonData = json.load(f) logging.info("读取的数据有:{}".format(jsonData)) query_emp_data = jsonData.get("query_emp") http_code = query_emp_data.get("http_code") success = query_emp_data.get("success") code = query_emp_data.get("code") message = query_emp_data.get("message") query_emp_result_list.append((http_code, success, code, message)) logging.info("添加员工数据列表为:{}".format(query_emp_result_list)) return query_emp_result_list
def read_add_emp(): app.init_logging() add_emp_data_path = app.BASEDIR + "/data/emp_data.json" add_emp_result_list = [] with open(add_emp_data_path, mode='r', encoding='utf-8') as f: jsonData = json.load(f) logging.info("读取的数据有:{}".format(jsonData)) add_emp_data = jsonData.get("add_emp") username = add_emp_data.get("username") mobile = add_emp_data.get("mobile") http_code = add_emp_data.get("http_code") success = add_emp_data.get("success") code = add_emp_data.get("code") message = add_emp_data.get("message") add_emp_result_list.append((username, mobile, http_code, success, code, message)) logging.info("添加员工数据列表为:{}".format(add_emp_result_list)) return add_emp_result_list
def read_login_data(): app.init_logging() login_data = app.BASEDIR + "/data/login.json" with open(login_data, mode='r', encoding='utf-8') as f: jsonData = json.load(f) logging.info("read_login_data: {}".format(jsonData)) result_list = [] for data in jsonData: mobile = data.get("mobile") password = data.get("password") http_code = data.get("http_code") success = data.get("success") code = data.get("code") message = data.get("message") result_list.append((mobile, password, http_code, success, code, message)) logging.info("result_list: {}".format(result_list)) return result_list
# 编写初始化日志的代码 import logging # 导入app.py模块 import app # 调用app.py中初始化日志的函数 app.init_logging() # 打印日志,调试结果 logging.info("测试日志是否会打印!")
import logging from gevent.pywsgi import WSGIServer from app import create_app, init_logging from gevent import monkey monkey.patch_all() def run(): host = '0.0.0.0' port = 24579 init_logging() http_server = WSGIServer((host, port), create_app()) logging.getLogger(__name__).info("Server start at %s:%s" % (host, port)) http_server.serve_forever() if __name__ == "__main__": debug = True if debug: init_logging() create_app().run(host='0.0.0.0', port=24579, debug=debug) else: run()
# 编写初始化日志的代码 import logging # 导入app.py模块 import app # 调用app.py中初始化日志的函数 app.init_logging() # 打印日志, 调试结果 logging.info("测试日志是否会打印!")