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
b9eecf0d
Commit
b9eecf0d
authored
May 07, 2021
by
taoke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
企业云HOST和密钥,配置化
parent
07d405a3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
10 deletions
+19
-10
common/db.py
+3
-1
config.py
+6
-1
service/login.py
+6
-5
test_case/bmy/test_login.py
+4
-3
No files found.
common/db.py
View file @
b9eecf0d
import
redis
,
pymysql
from
config
import
BaseConfig
# redis类
class
RedisBase
:
def
__init__
(
self
,
inum
):
test_redis
=
BaseConfig
()
.
test_redis
"""每一个数据库实例管理一个连接池"""
self
.
num
=
inum
pool
=
redis
.
ConnectionPool
(
host
=
'10.197.236.197'
,
port
=
6379
,
db
=
self
.
num
,
password
=
'123456'
)
pool
=
redis
.
ConnectionPool
(
host
=
test_redis
[
'host'
],
port
=
test_redis
[
'port'
],
db
=
self
.
num
,
password
=
test_redis
[
'password'
]
)
self
.
r
=
redis
.
Redis
(
connection_pool
=
pool
)
class
RedisString
(
RedisBase
):
...
...
config.py
View file @
b9eecf0d
...
...
@@ -8,7 +8,8 @@ class BaseConfig():
name
=
"auto"
test_case_dir
=
"test_case/"
salt
=
'hikcreate_xj'
# SSO 登录的东西
secs
=
0.1
secs
=
0.1
# 测试用例间隔运行时间
test_redis
=
{
"host"
:
"10.197.236.197"
,
"port"
:
6379
,
"password"
:
"123456"
}
class
BMCConfig
(
BaseConfig
):
...
...
@@ -25,4 +26,8 @@ class BmyConfig(BaseConfig):
name
=
"bmy"
test_case_dir
=
"test_case/bmy/"
test_case_data_dir
=
"test_case_data/bmy/"
key
=
"Jv+h&c0A"
# 获取token和密码加密原始密钥
defaultToken
=
"Basic aHpjcF93ZWI6MTIzNDU2"
# 获取token 原始token
# 测试环境
test_host
=
"http://testyun.banmago.com/api"
service/login.py
View file @
b9eecf0d
...
...
@@ -6,6 +6,7 @@ from common.utils.encryption import Encryption
# from common.utils.getExcelData import get_excelData
from
common.tools
import
request_main
from
common.db
import
RedisString
from
config
import
BmyConfig
@pytest.fixture
(
scope
=
'session'
)
...
...
@@ -22,8 +23,8 @@ def sso_login(url, headers, method, data):
class
BMY
():
"""斑马云登录相关"""
# 获取当前时间的Authorization
def
get_authorization
(
self
,
defaultToken
=
"Basic aHpjcF93ZWI6MTIzNDU2"
):
key
=
"Jv+h&c0A"
# 原始密钥
def
get_authorization
(
self
,
defaultToken
=
BmyConfig
.
defaultToken
):
key
=
BmyConfig
.
key
# 原始密钥
m5dkey
=
Encryption
()
.
get_md5
(
key
)
# AES密钥
t
=
time
.
time
()
num
=
str
(
round
(
t
*
1000
))
...
...
@@ -35,7 +36,7 @@ class BMY():
③逆序
"""
def
pwd_encrypted
(
self
,
pwd
):
key
=
"Jv+h&c0A"
# 原始密钥
key
=
BmyConfig
.
key
# 原始密钥
m5dkey
=
Encryption
()
.
get_md5
(
key
)
encrypted_text_str
=
Encryption
()
.
aes_cipher
(
m5dkey
,
pwd
)
# ①
newpwd
=
Encryption
()
.
get_md5
(
encrypted_text_str
)
# ②
...
...
@@ -45,7 +46,7 @@ class BMY():
def
get_imageCode
(
self
,
username
,
pwd
):
payload
=
{
"username"
:
username
,
"password"
:
pwd
}
try
:
rep
=
requests
.
get
(
"http://testyun.banmago.com/api
/website/common/graph/login-captcha"
,
params
=
payload
)
rep
=
requests
.
get
(
f
"{BmyConfig().test_host}
/website/common/graph/login-captcha"
,
params
=
payload
)
imageId
=
rep
.
json
()[
'data'
][
'jtId'
]
result
=
RedisString
(
6
)
.
get
(
f
'bmc:captcha:{imageId}'
)
imageCode
=
str
(
result
)[
-
3
:
-
1
]
...
...
@@ -73,7 +74,7 @@ class BMY():
payload
[
'imageCode'
]
=
imageinfo
[
1
]
# print(payload)
resp
=
requests
.
post
(
"http://testyun.banmago.com/api
/auth/login"
,
data
=
payload
,
headers
=
header
)
resp
=
requests
.
post
(
f
"{BmyConfig().test_host}
/auth/login"
,
data
=
payload
,
headers
=
header
)
if
getToken
:
token
=
resp
.
json
()[
'data'
][
'token'
]
# 数据权限会藏在token中
return
BMY
()
.
get_authorization
(
defaultToken
=
token
)
...
...
test_case/bmy/test_login.py
View file @
b9eecf0d
...
...
@@ -7,6 +7,7 @@ import pytest,allure,xlrd,requests,os
from
common.utils.getExcelData
import
get_excelData
from
service.login
import
BMY
from
common.tools
import
request_main
from
config
import
BmyConfig
@allure.epic
(
"营运车企业端"
)
@allure.feature
(
"登录模块"
)
...
...
@@ -19,7 +20,7 @@ class TestLogin():
@allure.description
(
"url:/auth/login 。。。。"
)
@pytest.mark.parametrize
(
"inData"
,
get_excelData
(
workBook
,
'登录模块'
,
'Login'
))
def
test_login
(
self
,
inData
):
url
=
inData
[
'url'
]
url
=
f
"{BmyConfig().test_host}{inData['url']}"
method
=
inData
[
'method'
]
req_data
=
inData
[
'reqData'
]
expectData
=
inData
[
'expectData'
]
...
...
@@ -28,7 +29,7 @@ class TestLogin():
"""处理"""
req_data
[
'grant_type'
]
=
"passwordImageCode"
# 请求体中的固定值
authorization
=
BMY
()
.
get_authorization
()
# 获取当前时间戳的Authorization
headers
[
"Authorization"
]
=
authorization
headers
[
"Authorization"
]
=
authorization
password_Encrypted
=
BMY
()
.
pwd_encrypted
(
req_data
[
'password'
])
# 密码加密
req_data
[
'password'
]
=
password_Encrypted
imageinfo
=
BMY
()
.
get_imageCode
(
req_data
[
'username'
],
req_data
[
'password'
])
# 获取图片信息
...
...
@@ -36,7 +37,7 @@ class TestLogin():
req_data
[
'imageCode'
]
=
imageinfo
[
1
]
"""请求"""
res
=
request_main
(
f
"http://testyun.banmago.com/api{url}"
,
headers
,
method
,
req_data
)
res
=
request_main
(
url
,
headers
,
method
,
req_data
)
"""断言"""
assert
res
[
'code'
]
==
expectData
[
'code'
]
...
...
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