Commit 63e06c1c by taoke
parents 09c899b8 07b75db5
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
import json import json
import logging import logging
import requests import requests
from config import BaseConfig, BMCConfig, BmyConfig from config import *
def request_main(url, headers, method, data): def request_main(url, headers, method, data):
"""封装requests的通用请求方法""" """封装requests的通用请求方法"""
res = None res = None
if headers == None or headers == {}: if headers == None or headers == {} or headers == "":
# 如果传的headers为空,使用通用headers # 如果传的headers为空,使用各自产品的通用headers
headers = BaseConfig.headers headers = get_headers()
header_content_type = headers["Content-Type"] header_content_type = headers["Content-Type"]
try: try:
...@@ -31,6 +31,18 @@ def request_main(url, headers, method, data): ...@@ -31,6 +31,18 @@ def request_main(url, headers, method, data):
return res return res
def get_headers():
name = BaseConfig.current_name
headers = BaseConfig.headers
if name == BMCConfig.name:
headers = BMCConfig.headers
elif name == BmyConfig.name:
headers = BmyConfig.headers
# elif name == SsoConfig.name:
# headers = SsoConfig.headers
return headers
def get_case_dir(product_name): def get_case_dir(product_name):
"""根据传入的产品名来运行对应产品的测试用例目录""" """根据传入的产品名来运行对应产品的测试用例目录"""
test_case_dir = BaseConfig.name test_case_dir = BaseConfig.name
......
...@@ -6,7 +6,7 @@ class BaseConfig(): ...@@ -6,7 +6,7 @@ class BaseConfig():
# 请求头 # 请求头
headers = {'Content-Type': 'application/json'} headers = {'Content-Type': 'application/json'}
# 当前运行的产品名 # 当前运行的产品名
name = "auto" current_name = "auto"
test_case_dir = "test_case/" test_case_dir = "test_case/"
secs=0.1 # 测试用例间隔运行时间 secs=0.1 # 测试用例间隔运行时间
......
...@@ -5,6 +5,7 @@ from config import SSOConfig ...@@ -5,6 +5,7 @@ from config import SSOConfig
from common.utils.encryption import Encryption from common.utils.encryption import Encryption
from common.tools import request_main from common.tools import request_main
@pytest.fixture(scope='module', autouse=True) @pytest.fixture(scope='module', autouse=True)
def sso_login(): def sso_login():
"""SSO登录获取token""" """SSO登录获取token"""
...@@ -12,8 +13,3 @@ def sso_login(): ...@@ -12,8 +13,3 @@ def sso_login():
req_data = {"loginName": SSOConfig.sso_username, "password": encrypted_password} req_data = {"loginName": SSOConfig.sso_username, "password": encrypted_password}
res = request_main(SSOConfig.sso_url, headers=None, method='post', data=req_data) res = request_main(SSOConfig.sso_url, headers=None, method='post', data=req_data)
setattr(SSOConfig, 'sso_token', res['data']['token']) setattr(SSOConfig, 'sso_token', res['data']['token'])
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