代码拉取完成,页面将自动刷新
同步操作将从 guozg/pytest_ui_api_fw 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 设置utf-8 显示中文
"""
@Create Time: 20年 11-14 21:27
@Author: guo
@File:conftest.py
"""
import json
from string import Template
import pytest
import requests
import sys
from common.util.get_file_path import GetFilePath
from common.util.handle_jsonfile import HandleJsonFile
from common.yml.get_yml_keys import GetYmlKeys
sys.path.append("../")
from common.cookie.get_web_cookie import GetWebCookie
from common.cookie.get_app_cookie_header import GetAppCookieHeader
from common.util.generate_device_key import GenerateDeviceKey
from config.get_conf_data import GetConfData
get_conf_data = GetConfData()
ymlkeys = GetYmlKeys()
fpath = GetFilePath()
hjson = HandleJsonFile()
web_login_data: dict = get_conf_data.get_web_login_request_data()
app_login_data: dict = get_conf_data.get_app_login_request_data()
logindata_key = ymlkeys.get_login_data_key()
res_filepath_key = ymlkeys.get_response_filepath_key()
token_key = ymlkeys.get_token_filepath_key()
@pytest.fixture(scope="class")
def web_login(request):
login_data = request.param[logindata_key]
res_filepath = request.param[res_filepath_key]
token_path = request.param[token_key]
global web_login_data
web_login_data = __replace(web_login_data,login_data)
res = requests.request(**web_login_data)
get_cookies = GetWebCookie(res)
# 当response_filepath 不为None时,则保存当前的登录响应结果
if res_filepath != None:
res_filepath = fpath.get_file_abspath_json(res_filepath)
hjson.write_dict_to_json_file(res_filepath, res.json())
# 当token_filepath 不为None时,则保存当前的cookie
if token_path != None:
token_path = fpath.get_file_abspath_json(token_path)
token = get_cookies.get_cookie()
hjson.write_dict_to_json_file(token_path, token)
# return get_cookies
@pytest.fixture(scope="class")
def app_login(request):
login_data = request.param[logindata_key]
res_filepath = request.param[res_filepath_key]
token_path = request.param[token_key]
loginid = login_data['loginId']
global app_login_data
app_login_data = __replace(app_login_data,login_data)
app_login_data['device'] = GenerateDeviceKey().generate_key_by_account(loginid)
res = requests.request(**app_login_data)
get_header = GetAppCookieHeader(res)
# 当response_filepath 不为None时,则保存当前的登录响应结果
if res_filepath != None:
res_filepath = fpath.get_file_abspath_json(res_filepath)
hjson.write_dict_to_json_file(res_filepath, res.json())
# 当token_filepath 不为None时,则保存当前的cookie
if token_path != None:
token_path = fpath.get_file_abspath_json(token_path)
token = get_header.get_header()
hjson.write_dict_to_json_file(token_path, token)
# return get_header
@pytest.fixture(scope="class")
def get_web_login_response(request):
login_data = request.param[logindata_key]
res_filepath = request.param[res_filepath_key]
token_path = request.param[token_key]
global web_login_data
web_login_data=__replace(web_login_data,login_data)
res = requests.request(**web_login_data)
# 当response_filepath 不为None时,则保存当前的登录响应结果
if res_filepath != None:
res_filepath = fpath.get_file_abspath_json(res_filepath)
hjson.write_dict_to_json_file(res_filepath, res.json())
# 当token_filepath 不为None时,则保存当前的cookie
if token_path != None:
token_path = fpath.get_file_abspath_json(token_path)
get_cookies = GetWebCookie(res)
token = get_cookies.get_cookie()
hjson.write_dict_to_json_file(token_path, token)
# return res
@pytest.fixture(scope="class")
def get_app_login_response(request):
login_data = request.param[logindata_key]
res_filepath = request.param[res_filepath_key]
token_path = request.param[token_key]
loginid = login_data['loginId']
global app_login_data
app_login_data = __replace(app_login_data,login_data)
app_login_data['data']['device'] = GenerateDeviceKey().generate_key_by_account(loginid)
res = requests.request(**app_login_data)
# 当response_filepath 不为None时,则保存当前的登录响应结果
if res_filepath != None:
res_filepath = fpath.get_file_abspath_json(res_filepath)
hjson.write_dict_to_json_file(res_filepath, res.json())
# 当token_filepath 不为None时,则保存当前的cookie
if token_path != None:
token_path = fpath.get_file_abspath_json(token_path)
get_header = GetAppCookieHeader(res)
token = get_header.get_header()
hjson.write_dict_to_json_file(token_path, token)
# return res
def __replace(templace,login_data:dict):
tem = Template(json.dumps(templace))
res = json.loads(tem.substitute(**login_data))
return res
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。