Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
backend_auto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
邓莹莹
backend_auto
Commits
9b681aa3
Commit
9b681aa3
authored
Apr 18, 2021
by
邓莹莹
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决登录session问题
parent
f2be5e82
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
87 additions
and
40 deletions
+87
-40
account_request.py
all_backend_api/account_request.py
+3
-2
account_request.yaml
all_backend_api/account_request.yaml
+2
-0
feed_request.yaml
all_backend_api/feed_request.yaml
+1
-0
host.yaml
host.yaml
+2
-2
base_request.py
in_common/base_request.py
+13
-25
get_cookies.txt
in_common/get_cookies.txt
+0
-0
login_session_function.py
login_session_function.py
+46
-0
login_session_function.yaml
login_session_function.yaml
+19
-0
path_setting.py
path_setting.py
+1
-0
conftest.py
test_backend_case/conftest.py
+0
-11
No files found.
all_backend_api/account_request.py
View file @
9b681aa3
...
...
@@ -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
all_backend_api/account_request.yaml
View file @
9b681aa3
...
...
@@ -9,3 +9,5 @@ login_vfc:
vfc_type
:
${vfc_type}
face_token
:
${face_token}
json
:
{}
all_backend_api/feed_request.yaml
View file @
9b681aa3
...
...
@@ -7,3 +7,4 @@ index_v9:
current_city_id
:
${current_city_id}
data
:
json
:
{}
isLogin
:
1
host.yaml
View file @
9b681aa3
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/
in_common/base_request.py
View file @
9b681aa3
...
...
@@ -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
()
in_common/get_cookies.txt
deleted
100644 → 0
View file @
f2be5e82
login_session_function.py
0 → 100644
View file @
9b681aa3
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
login_session_function.yaml
0 → 100644
View file @
9b681aa3
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"
path_setting.py
View file @
9b681aa3
...
...
@@ -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"
)
...
...
test_backend_case/conftest.py
deleted
100644 → 0
View file @
f2be5e82
import
pytest
import
path_setting
@pytest.fixture
()
def
login
():
pass
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment