Commit b9eecf0d by taoke

企业云HOST和密钥,配置化

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