Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
InterfaceAutoTest
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TestAuto
InterfaceAutoTest
Commits
1060280a
Commit
1060280a
authored
May 05, 2021
by
jiaqiying
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加通用请求方法,增加斑马信用的配置类
parent
269f589b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
common/tools.py
+32
-0
config.py
+9
-0
No files found.
common/tools.py
View file @
1060280a
#coding:utf-8
import
json
import
logging
import
requests
from
config
import
BaseConfig
def
request_main
(
url
,
headers
,
method
,
data
):
"""封装requests的通用请求方法"""
res
=
None
if
headers
==
None
or
headers
==
{}:
# 如果传的headers为空,使用通用headers
headers
=
BaseConfig
.
headers
header_content_type
=
headers
[
"Content-Type"
]
try
:
if
method
.
upper
()
==
"GET"
:
res
=
requests
.
get
(
url
=
url
,
headers
=
headers
,
params
=
data
)
elif
method
.
upper
()
==
"POST"
:
if
header_content_type
in
[
"application/x-www-form-urlencoded"
]:
#
res
=
requests
.
post
(
url
=
url
,
headers
=
headers
,
)
elif
header_content_type
==
"application/json"
:
res
=
requests
.
post
(
url
=
url
,
headers
=
headers
,
data
=
json
.
dumps
(
data
))
except
Exception
as
e
:
logging
.
log
(
str
(
e
))
raise
Exception
if
res
!=
None
:
return
res
.
json
()
return
res
\ No newline at end of file
config.py
View file @
1060280a
#coding:utf-8
class
BaseConfig
():
class
BaseConfig
():
"""基础配置类"""
"""基础配置类"""
# 请求头
# 请求头
headers
=
{
'Content-Type'
:
'application/json; charset=utf-8'
}
headers
=
{
'Content-Type'
:
'application/json; charset=utf-8'
}
# 当前运行的产品名
current_product
=
""
class
BMCConfig
(
BaseConfig
):
"""斑马信用app的配置类"""
pass
class
DingTalk
(
BaseConfig
):
class
DingTalk
(
BaseConfig
):
...
...
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