Commit 9b681aa3 authored by 邓莹莹's avatar 邓莹莹

解决登录session问题

parent f2be5e82
......@@ -17,4 +17,5 @@ class account_request(BaseRequest):
if __name__ == '__main__':
print(account_request().login_vfc("beijing", "+8612345678912", 1234, "", ""))
\ No newline at end of file
# print(account_request().user_info())
print(account_request.loginvfc(""))
\ No newline at end of file
......@@ -9,3 +9,5 @@ login_vfc:
vfc_type: ${vfc_type}
face_token: ${face_token}
json: {}
......@@ -7,3 +7,4 @@ index_v9:
current_city_id: ${current_city_id}
data:
json: {}
isLogin: 1
develop_host:
url: http://backend.paas-develop.env
# url: http://doctor.paas-develop.env/
backend: http://backend.paas-develop.env
# doctor: http://doctor.paas-develop.env/
......@@ -4,6 +4,7 @@ import string
import requests
import yaml
from jsonpath import jsonpath
from login_session_function import LoginFunction
# from pymysql import OperationalError
import path_setting
......@@ -33,7 +34,7 @@ class BaseRequest:
if r is None:
r = self.r.json()
return jsonpath(r, path)
'''
def get_cookie(self, req: dict):
host = self.api_load(path_setting.HOSTYAML_CONFIG)
......@@ -50,15 +51,6 @@ class BaseRequest:
for i in r.cookies:
dict[i.name] = i.value
headers = '_gtid={};sessionid={}'.format(dict["_gtid"], dict["sessionid"])
# item = r.cookies.values()
# print("ppppppp",item)
# if len(item) == 1:
# headers = '_gtid={}'.format(item[0])
# print("cookie异常")
#
# else:
# headers = '_gtid={};sessionid={}'.format(item[0], item[1])
#
return headers
def read_header(self):
......@@ -66,28 +58,24 @@ class BaseRequest:
cookies = f.read()
headers = {"cookie": cookies}
return headers
'''
# 接口请求的封装
def api_send(self, req: dict):
host = self.api_load(path_setting.HOSTYAML_CONFIG)
raw = yaml.dump(req) # 将一个python对象生成为yaml文档
for key, value in self.params.items():
raw = raw.replace(f"${{{key}}}", repr(value))
req = yaml.safe_load(raw)
print('req:',req)
# print('------', req.get('headers'))
# hd = req.get('headers')
# if hd == None:
# user_headers = self.read_header()
# elif hd["Cookie"]:
# user_headers = req.get('headers')
# else:
# user_headers = self.read_header()
s = requests.session()
print('req:', req)
s = requests
if req.get('isLogin'):
s = LoginFunction().get_session()
# 调用具体case的url
r = s.request(
req['method'],
url=host['develop_host']['url'] + req['url'],
url=host['develop_host']['backend'] + req['url'],
params=req.get('params'),
# headers=user_headers,
data=req.get('data'),
......@@ -100,7 +88,7 @@ class BaseRequest:
return ''.join(random.sample(string.ascii_lowercase + string.digits, 32))
if __name__ == '__main__':
BaseRequest().api_load("../api/api.yaml")
# BaseRequest().api_load("../api/api.yaml")
# print(BaseApi().trace_id())
BaseRequest().read_header()
BaseRequest().a()
import path_setting
import requests
import yaml
"""
此文件是封装session的
"""
class LoginFunction:
def __init__(self):
self.host = self.login_yaml_load(path_setting.HOSTYAML_CONFIG)
self.params = self.login_yaml_load(path_setting.LOGIN_FUNCTION_DATA)
def login_yaml_load(self, path) -> list:
with open(path, encoding='utf-8') as f:
return yaml.safe_load(f)
def get_session(self):
hostList = self.host['develop_host']
for key in hostList:
if 'backend' == key:
return self.get_develop_session()
elif 'doctor' == key:
return self.get_doctor_session()
def get_develop_session(self):
url = self.host["develop_host"]["backend"] + self.params["backend_login"]["url"]
s = requests.session()
r = s.request(
self.params["backend_login"]["method"],
url=url,
params=self.params["backend_login"]["params"],
data=self.params["backend_login"]["data"],
headers={'Connection': 'close'}
)
return s
def get_doctor_session(self):
pass
if __name__ == '__main__':
LoginFunction().get_session()
\ No newline at end of file
backend_login:
method: POST
url: /api/account/login/login_vfc
params:
current_city_id: "beijing"
data:
phone_num: "+8612345678912"
vfc_code: 1234
vfc_type:
face_token:
#doctor_login:
# method: post
# url: /api
# params:
# a: "a"
# data:
# b: "b"
......@@ -4,6 +4,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.append(BASE_DIR)
HOSTYAML_CONFIG = os.path.join(BASE_DIR, "backend_auto", "host.yaml")
LOGIN_FUNCTION_DATA = os.path.join(BASE_DIR, "backend_auto", "login_session_function.yaml")
APYAML_CONFIG = os.path.join(BASE_DIR, "backend_auto/all_backend_api", "account_request.yaml")
LOGIN_VFC = os.path.join(BASE_DIR, "backend_auto/test_backend_data/account_data", "login_vfc.yaml")
......
import pytest
import path_setting
@pytest.fixture()
def login():
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment